Skip to content

Move Streams.copy into elasticsearch-core and make a multi-release jar #29322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 6, 2018

Conversation

dakrone
Copy link
Member

@dakrone dakrone commented Mar 30, 2018

This moves the method Streams.copy(InputStream in, OutputStream out) into the
elasticsearch-core project (inside the o.e.core.internal.io package). It
also makes this class into a multi-release class where the Java 9 equivalent
uses InputStream#transferTo.

This is a followup from
#29300 (comment)

This moves the method `Streams.copy(InputStream in, OutputStream out)` into the
`elasticsearch-core` project (inside the `o.e.core.internal.io` package). It
also makes this class into a multi-release class where the Java 9 equivalent
uses `InputStream#transferTo`.

This is a followup from
elastic#29300 (comment)
@dakrone dakrone added >non-issue :Core/Infra/Core Core issues without another label v7.0.0 v6.3.0 labels Mar 30, 2018
@dakrone dakrone requested a review from rjernst March 30, 2018 20:59
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@dakrone
Copy link
Member Author

dakrone commented Mar 30, 2018

I want to make sure here I'm not missing something with the multi-release jar, is there testing for this other than CI JDK randomization?

@nik9000
Copy link
Member

nik9000 commented Mar 31, 2018

I want to make sure here I'm not missing something with the multi-release jar, is there testing for this other than CI JDK randomization?

I don't believe we have any testing for this beyond the different JDK versions.

// we want to keep the JDKs in our IDEs set to JDK 8 until minimum JDK is bumped to 9 so we do not include this source set in our IDEs
if (!isEclipse && !isIdea) {
sourceSets {
java9 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this is java10 now, I think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that mean someone running with JDK 9 wouldn't use the 9-specific one? The code only uses Java 9 features so far so I figured that's where we should stick for now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't build Elasticsearch with Java 9 as of last week I believe. That is all I'm getting at. I dunno if we want to bump all the java9 directories to java10 because of that. I think probably, but for now we can keep it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even with java 10, we are still building this code with java 9 source level. It's really only about the standard features/libs that are allowed when compiling.

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a suggestion.

out.flush();
success = true;
return byteCount;
} finally {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you can simplify all of this gross exception handling with:

try (in; out) {
    final long byteCount = in.transferTo(out);
    out.flush();
    return byteCount;
}

Note that this also uses a Java 9 language-level feature (a resource reference in the try-with-resources statement).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See item 2 in JEP 213 for an explanation of this feature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also possible that

        try (in;
             out) {

        }

is clearer. I am not sure.

* @return the number of bytes copied
* @throws IOException in case of I/O errors
*/
public static long copy(InputStream in, OutputStream out) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While JEP 213 does not require these to be final, it would be clearer if they were declared as such.

@dakrone
Copy link
Member Author

dakrone commented Apr 4, 2018

@jasontedor okay, I've updated this PR with your comments as well as the discussion we reached regarding not suppressing exceptions

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

*
* @see #close(Closeable...)
*/
public static void close(Exception ex, final Iterable<? extends Closeable> objects) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you make ex final please?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly

@dakrone dakrone merged commit a07ba9e into elastic:master Apr 6, 2018
dakrone added a commit that referenced this pull request Apr 6, 2018
#29322)

* Move Streams.copy into elasticsearch-core and make a multi-release jar

This moves the method `Streams.copy(InputStream in, OutputStream out)` into the
`elasticsearch-core` project (inside the `o.e.core.internal.io` package). It
also makes this class into a multi-release class where the Java 9 equivalent
uses `InputStream#transferTo`.

This is a followup from
#29300 (comment)
@dakrone dakrone deleted the move-streams-into-core branch April 19, 2018 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants