Skip to content
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

ARROW-15755: [Java] Support Java 17 #12941

Closed
wants to merge 10 commits into from

Conversation

davisusanibar
Copy link
Contributor

Changes needed to support JDK17:

  • There are some errorprone suppress warnings needed to be able to continue using JSE17 with JSE1.8 source/target. This need to be migrated to new JSE X base on ML discussion.
  • JSE11+ is modular for that reason was needed to add --add-exports and --add-opens
  • The --add-exports option allows code in the target module to access types in the named package of the source module if the target module reads the source module.
  • If you have to allow code on the class path to do deep reflection to access nonpublic members, then use the --add-opens runtime option.
  • To be able to running unit test was needed to configure maven-surefire-plugin with <argLine>--add-opens=java.base/java.nio=ALL-UNNAMED</argLine>

@github-actions
Copy link

…g.apache.hadoop.shaded.com.ctc.wstx.io.InputBootstrapper
@davisusanibar davisusanibar changed the title ARROW-15755: [Java] WIP - Support Java 17 ARROW-15755: [Java] Support Java 17 Apr 21, 2022
@lidavidm lidavidm self-requested a review April 21, 2022 00:48
@lidavidm
Copy link
Member

You will want to rebase to get CI to run.

Can we add a CI job that tests JDK17?

Copy link
Member

@lidavidm lidavidm left a comment

Choose a reason for hiding this comment

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

Thanks for working this out. I think we just need to make sure to cover this in CI.

@@ -736,6 +738,7 @@
See https://github.com/jbosstools/m2e-apt/issues/62 for details
-->
<activation>
<jdk>1.8</jdk>
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, we already have a 1.8-specific profile below. What's the difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

<arg>-XDcompilePolicy=simple</arg>
<arg>
-Xplugin:ErrorProne \
-XepExcludedPaths:.*/(target/generated-sources)/.*
Copy link
Member

Choose a reason for hiding this comment

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

nit, but can these be two separate <arg> blocks or does it not work that way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does not work on that way.

Be aware that when running on JDK 8 the flags cannot be wrapped across multiple lines. JDK 9 and above do allow the flags to be separated by newlines. That is, the second element above can also be formatted as follows on JDK 9+, but not on JDK 8:

Copy link
Member

Choose a reason for hiding this comment

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

Ah, weird.

@@ -111,6 +111,7 @@ public void testNullPointersHashCode() {
}

@Test
@SuppressWarnings("ReturnValueIgnored")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe instead of suppresing we can check that the hash code changes/doesn't change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

Copy link
Member

Choose a reason for hiding this comment

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

We can remove the suppression now right?

@@ -77,6 +77,7 @@
/**
* Flight client with Flight SQL semantics.
*/
@SuppressWarnings({"ProtoBuilderReturnValueIgnored", "ReturnValueIgnored"})
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this is a very wide scope to suppress. Is it possible to refactor things?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

@@ -97,6 +97,7 @@ public void mixedProperties() {
testHeaders(headers);
}

@SuppressWarnings("ReturnValueIgnored")
Copy link
Member

Choose a reason for hiding this comment

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

Same here, maybe an assertTrue(....hasNext())?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

Comment on lines +62 to +63
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a brief comment about why we need to exclude these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the reason is [WARNING] Rule 0: org.apache.maven.plugins.enforcer.BannedDependencies failed with message: Found Banned Dependency: commons-logging:commons-logging:jar:1.1.3. Let me add some message on the exclude tag.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I didn't realize we had a bannedDependencies set. Ok, it's probably fine to leave this as is then.

Copy link
Member

Choose a reason for hiding this comment

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

Though uh wow, that's been there since the initial Arrow commit in 2016. Are we sure Hadoop functions without this dependency, incidentally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unit test is working without problems in JSE 8, JSE 11 but not in JSE 17, that is the reason because we added now.

@pitrou
Copy link
Member

pitrou commented Apr 21, 2022

@lwhite1 You might want to take a look at this.

@lwhite1
Copy link
Contributor

lwhite1 commented Apr 21, 2022

@pitrou will do

@davisusanibar
Copy link
Contributor Author

You will want to rebase to get CI to run.

Can we add a CI job that tests JDK17?

For CI jobs please take a look at https://issues.apache.org/jira/browse/ARROW-15177. Thank for your support @raulcd

@lidavidm
Copy link
Member

Well I don't think we should merge this without a CI job to actually validate it.

@lidavidm
Copy link
Member

Either that, or we should make sure to validate JDK17 during the 8.0.0 vote.

Copy link
Contributor

@lwhite1 lwhite1 left a comment

Choose a reason for hiding this comment

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

Other than my one nit on SuppressWarnings, this looks good to me.

@@ -246,9 +246,11 @@ public FlightClientMiddleware onCallStarted(CallInfo info) {
}

// Used to test that middleware can send and receive multi-valued text and binary headers.
@SuppressWarnings({"DoubleBraceInitialization"})
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just initialize these values (here and below) the old-fashioned way, rather than add the SuppressWarnings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, changed

Comment on lines 87 to 88
EXPECTED_BINARY_HEADERS.put("x-binary-bin", Arrays.asList(new byte[] {0}, new byte[]{1}));
EXPECTED_TEXT_HEADERS.put("x-text", Arrays.asList("foo", "bar"));
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, inline the declarations here too if they're only used in this test? Else put the initialization in a static block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

Comment on lines +793 to +802
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
Copy link

Choose a reason for hiding this comment

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

Does this change mean that consumers of this library will still need to pass add-opens to get Arrow to work with JDK 17? (I think so since you are just making the compilation work with these arguments, no code is changed to not use those modules?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are two part on this question:

  1. Changed for arrow side: Changes related to --add-exports" are needed to continue supporting erroProne base on JSE11+ installation doc. It mean you won't need this changes if you run arrow java building code without errorProne validation (mvn clean install -P-error-prone-jdk11+ ....)

  2. Changes as a user of arrow: If the user are planning to use Arrow with JSE17 is needed to pass modules needed. For example if I run cookbook for IO https://arrow.apache.org/cookbook/java/io.html it finished with an error mention Unable to make field long java.nio.Buffer.address accessible: module java.base does not "opens java.nio" to unnamed module for that reason as a user for JSE17 (not for arrow changes) is needed to add VM arguments as -ea --add-opens=java.base/java.nio=ALL-UNNAMED and it will finished without errors.

Please let me know if you have some additional doubts.

Copy link
Member

Choose a reason for hiding this comment

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

Can we add point (2) to the docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we add point (2) to the docs?

Hi Team, just send this PR to update Arrow JavaSE17/18 documentation. Please if you could review that, thanks.

Choose a reason for hiding this comment

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

@davisusanibar It looks like this is a half-finished solution because VM arguments should be considered a temporary solution. Is it possible to use ARROW with JDK 17 and not have VM arguments? Every time I see posts with VM arguments I feel a little worried. In JEP-261 there's a warning about the usage of --add-opens:

The --add-exports and --add-opens options must be used with great care. You can use them to gain access to an internal API of a library module, or even of the JDK itself, but you do so at your own risk: If that internal API is changed or removed then your library or application will fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @iamzafar as per the jar artifacts are exposed as a legacy mode (it means any jar are running in the classpath is consider as a unnamed module) and base on JEP 200 The Modular JDK: yes, this is needed:

--add-opens ${module}/${package}=${target_modules}
Let the ${target_modules} access all types and members, regardless of visibility, from ${module}'s ${package}

Yes, this is an intermediate step: (1) Legacy mode (already implemented, (2) single module and (3) multi-module will be the last steps.

This is a draft for implement JPMS and be more restrict about to not give ALL-UNNAMED access but there is a lot of discussion we need to close before to convert this draft into PR: #13072. This is the document that I am going to send for discussion to the ML.

lidavidm added a commit that referenced this pull request Apr 26, 2022
Related to #12941 (comment)

Closes #12990 from davisusanibar/java-ARROW-16292

Lead-authored-by: david dali susanibar arce <davi.sarces@gmail.com>
Co-authored-by: David Li <li.davidm96@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
@raulcd
Copy link
Member

raulcd commented Apr 28, 2022

Hi @davisusanibar I have created this draft PR to add Java 17 to CI (#13021). As you can see from the triggered jobs, there is a new Java job:
image
It is obviously failing (https://github.com/apache/arrow/runs/6208174355?check_suite_focus=true) because the fixes for Java 17 are on your PR but I have cherry-picked the commit locally on top of your branch and I have validated the build is working and tests are passing. Tested locally with:

$ JDK=17 MAVEN=3.8.5 JDK_NAME=openjdk docker-compose run --rm debian-java

I have validated java version was the correct when testing:

bash-4.4# java --version
openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)
bash-4.4# exit

I am not sure how we do this but probably you might want to cherrypick my commit and apply it on your PR.

@lidavidm
Copy link
Member

Thanks @raulcd! I think we can merge this, then rebase your PR and check that it passes in CI, and then merge that as well?

@@ -111,6 +111,7 @@ public void testNullPointersHashCode() {
}

@Test
@SuppressWarnings("ReturnValueIgnored")
Copy link
Member

Choose a reason for hiding this comment

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

We can remove the suppression now right?

java/pom.xml Outdated Show resolved Hide resolved
@raulcd
Copy link
Member

raulcd commented Apr 28, 2022

Thanks @raulcd! I think we can merge this, then rebase your PR and check that it passes in CI, and then merge that as well?

Thanks @lidavidm! that works for me, I'll be keeping an eye on this PR and will rebase mine once it is merged!

@davisusanibar
Copy link
Contributor Author

Hi @davisusanibar I have created this draft PR to add Java 17 to CI (#13021). As you can see from the triggered jobs, there is a new Java job: image It is obviously failing (https://github.com/apache/arrow/runs/6208174355?check_suite_focus=true) because the fixes for Java 17 are on your PR but I have cherry-picked the commit locally on top of your branch and I have validated the build is working and tests are passing. Tested locally with:

$ JDK=17 MAVEN=3.8.5 JDK_NAME=openjdk docker-compose run --rm debian-java

I have validated java version was the correct when testing:

bash-4.4# java --version
openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)
bash-4.4# exit

I am not sure how we do this but probably you might want to cherrypick my commit and apply it on your PR.

Thanks @raulcd. Let me solve pending comments. Consider: in my local test was needed to add this environment variable "--add-opens=java.base/java.nio=ALL-UNNAMED", but as suggested let merge this and test your changes them.

@lidavidm
Copy link
Member

@github-actions crossbow submit java

@github-actions
Copy link

Revision: 439403b

Submitted crossbow builds: ursacomputing/crossbow @ actions-1988

Task Status
java-jars Github Actions
verify-rc-source-java-linux-almalinux-8-amd64 Github Actions
verify-rc-source-java-linux-conda-latest-amd64 Github Actions
verify-rc-source-java-linux-ubuntu-18.04-amd64 Github Actions
verify-rc-source-java-linux-ubuntu-20.04-amd64 Github Actions
verify-rc-source-java-linux-ubuntu-22.04-amd64 Github Actions
verify-rc-source-java-macos-amd64 Github Actions

@toddfarmer
Copy link
Contributor

Just a note here as a reminder that https://arrow.apache.org/docs/dev/developers/java/building.html will need updates once support for additional JDK versions is added.

@lidavidm
Copy link
Member

Good point. @davisusanibar can we include the docs changes here?

@davisusanibar
Copy link
Contributor Author

Good point. @davisusanibar can we include the docs changes here?

Thanks @toddfarmer. Just updated.

Co-authored-by: David Li <li.davidm96@gmail.com>
@lidavidm lidavidm closed this in 760ad20 May 2, 2022
@pitrou
Copy link
Member

pitrou commented May 2, 2022

Great milestone, thanks a lot @davisusanibar !

kou pushed a commit that referenced this pull request May 5, 2022
This PR aims to add support for java 17 on CI as required on #12941
We probably should cherrypick the commit here on that PR.

Closes #13021 from raulcd/ARROW-16327

Authored-by: Raúl Cumplido <raulcumplido@gmail.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
@ursabot
Copy link

ursabot commented May 6, 2022

Benchmark runs are scheduled for baseline = 3f2c33f and contender = 760ad20. 760ad20 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Finished ⬇️0.43% ⬆️0.0%] test-mac-arm
[Failed ⬇️0.36% ⬆️0.0%] ursa-i9-9960x
[Finished ⬇️0.2% ⬆️0.0%] ursa-thinkcentre-m75q
Buildkite builds:
[Finished] 760ad200 ec2-t3-xlarge-us-east-2
[Finished] 760ad200 test-mac-arm
[Finished] 760ad200 ursa-i9-9960x
[Finished] 760ad200 ursa-thinkcentre-m75q
[Finished] 3f2c33f5 ec2-t3-xlarge-us-east-2
[Finished] 3f2c33f5 test-mac-arm
[Failed] 3f2c33f5 ursa-i9-9960x
[Finished] 3f2c33f5 ursa-thinkcentre-m75q
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants