Skip to content

Configure Guice classloading for Java 21+ compatibilit#3595

Open
rpx99 wants to merge 1 commit intoeclipse-jdtls:mainfrom
rpx99:claude/upgrade-guice-java21-compat-011CV4XJ6am7dFLovBMwRYuF
Open

Configure Guice classloading for Java 21+ compatibilit#3595
rpx99 wants to merge 1 commit intoeclipse-jdtls:mainfrom
rpx99:claude/upgrade-guice-java21-compat-011CV4XJ6am7dFLovBMwRYuF

Conversation

@rpx99
Copy link
Copy Markdown

@rpx99 rpx99 commented Nov 12, 2025

Summary

Configures Guice to use CHILD classloading mode via -Dguice_custom_class_loading=CHILD JVM argument to avoid sun.misc.Unsafe deprecation warnings on Java 21+.

Problem

Guice 5.1.0 (embedded via M2E 2.9.1 → Maven 3.9.11) uses the terminally deprecated sun.misc.Unsafe::staticFieldBase method, which triggers warnings on Java 21+ and will be removed in future Java versions.

Solution

This PR implements the same fix that Maven applied in apache/maven#10992:

  • Configures Guice to use CHILD classloader instead of the default BRIDGE mode
  • Avoids sun.misc.Unsafe calls while maintaining full functionality
  • No code changes required - configuration-only fix

Changes

Eclipse Launch Configurations:

  • launch/jdt.ls.socket-stream.launch
  • launch/jdt.ls.remote.server.launch
  • launch/jdt.ls.socket-stream.syntaxserver.launch

Test Configuration:

  • org.eclipse.jdt.ls.tests/pom.xml - Added flag to tycho-surefire argLine

Documentation:

  • README.md - Added Java 21+ compatibility section
  • GUICE_UPGRADE_ANALYSIS.md - Comprehensive analysis of upgrade options

Testing

  • ✅ All existing tests pass with the flag
  • ✅ No behavior changes - purely preventative configuration
  • ✅ Compatible with Java 21, 22, 23, 24, 25+

Why Not Upgrade Guice?

See GUICE_UPGRADE_ANALYSIS.md for detailed analysis:

  • Guice 6.0: Would require maintaining custom M2E maven.runtime bundle
  • Guice 7.0: Requires jakarta.inject migration, not compatible with Maven
  • This approach: Officially adopted by Maven, zero maintenance overhead

References

Impact

✅ No breaking changes
✅ Eliminates warnings on Java 21+
✅ Future-proofs for Java 26+

@eclipse-ls-bot
Copy link
Copy Markdown
Contributor

Can one of the admins verify this patch?

Copy link
Copy Markdown
Contributor

@fbricon fbricon left a comment

Choose a reason for hiding this comment

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

You should also add that flag to the org.eclipse.jdt.ls.product/*.product files:

<launcherArgs>
	<vmArgs>-Dguice_custom_class_loading=CHILD
	</vmArgs>
	<vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts
	</vmArgsMac>
</launcherArgs>

Also, you'll have to sign the Eclipse ECA before we can accept your contribution.

Comment thread README.md Outdated
Comment on lines +47 to +50
### Java 21+ Compatibility

When running on Java 21 or later, the JVM argument `-Dguice_custom_class_loading=CHILD` is configured to avoid deprecated `sun.misc.Unsafe` usage in the embedded Guice dependency injection framework. This prevents warning messages about terminally deprecated methods and ensures compatibility with future Java versions. This flag is automatically included in all launch configurations and test executions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is unnecessary

Comment thread GUICE_UPGRADE_ANALYSIS.md Outdated
@@ -0,0 +1,189 @@
# Guice Upgrade Analyse für eclipse.jdt.ls - Java 21+ Kompatibilität
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please remove this file

@rpx99 rpx99 force-pushed the claude/upgrade-guice-java21-compat-011CV4XJ6am7dFLovBMwRYuF branch 3 times, most recently from d4482a5 to 4a62b38 Compare November 14, 2025 15:26
Add -Dguice_custom_class_loading=CHILD to avoid sun.misc.Unsafe
warnings on Java 21+. This prevents "terminally deprecated method"
warnings from Guice 5.1.0's HiddenClassDefiner.

Changes:
- Add flag to Eclipse launch configurations (3 files)
- Add flag to product definitions (languageServer, syntaxServer)
- Add flag to tycho-surefire test configuration

Based on Maven fix: apache/maven#10992
Resolves sun.misc.Unsafe::staticFieldBase deprecation warnings
@rpx99 rpx99 force-pushed the claude/upgrade-guice-java21-compat-011CV4XJ6am7dFLovBMwRYuF branch from 4a62b38 to 2b4c6b0 Compare November 14, 2025 15:33
@rpx99
Copy link
Copy Markdown
Author

rpx99 commented Nov 14, 2025

@fbricon Hi Fred, many thanks for comments. Think i fixed that. But, i am Not willing to sign something. Either take it or leave it. Sorry.

@fbricon
Copy link
Copy Markdown
Contributor

fbricon commented Nov 19, 2025

Unfortunately, signing the ECA is a requirement to contribute to Eclipse projects.

Maybe taking a look at https://www.eclipse.org/legal/eca/faq/ will help you make an informed decision.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants