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

implement jshell support #6

Open
rogerkeays opened this issue Jul 4, 2023 · 2 comments
Open

implement jshell support #6

rogerkeays opened this issue Jul 4, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@rogerkeays
Copy link
Owner

$ jshell -C-Xplugin:fluent
An exception has occurred in the compiler (17.0.2). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.NoClassDefFoundError: sun/misc/Unsafe
	at com.sun.tools.javac.comp.Fluent.init(Fluent.java:26)
	at jdk.compiler/com.sun.tools.javac.api.BasicJavacTask.initPlugin(BasicJavacTask.java:255)
	at jdk.compiler/com.sun.tools.javac.api.BasicJavacTask.initPlugins(BasicJavacTask.java:229)
        ...

We need to replace Unsafe to be future proof anyway.

Unsafe source: https://github.com/openjdk/jdk/blob/master/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java

@rogerkeays
Copy link
Owner Author

rogerkeays commented Jul 4, 2023

We can replace com.sun.misc with jdk.internals.misc, and use -J--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED to start the plugin, but still fails with jshell:

$ jshell -C-Xplugin:fluent -J--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED
Exception in thread "main" java.lang.InternalError: Exception during analyze - java.lang.NullPointerException: Cannot invoke "java.io.InputStream.available()" because "<local3>" is null
	...
Caused by: java.lang.NullPointerException: Cannot invoke "java.io.InputStream.available()" because "<local3>" is null
	at com.sun.tools.javac.comp.Fluent.reload(Fluent.java:57)
	at com.sun.tools.javac.comp.Fluent.init(Fluent.java:40)
	... 27 more

so, a classloading problem.

@rogerkeays
Copy link
Owner Author

  • jshell inits the plugin for every invocation: easily fixed with a null check

  • jshell uses it's own custom resolver: not so easy to fix:

    Exception in thread "main" java.lang.InternalError: Exception during analyze - java.lang.ClassCastException: class com.sun.tools.javac.comp.Fluent$FluentResolve cannot be cast to class jdk.jshell.TaskFactory$DisableAccessibilityResolve (com.sun.tools.javac.comp.Fluent$FluentResolve is in module jdk.compiler of loader 'app'; jdk.jshell.TaskFactory$DisableAccessibilityResolve is in module jdk.jshell of loader 'app')

@rogerkeays rogerkeays changed the title jshell can't load fluent: java.lang.NoClassDefFoundError: sun/misc/Unsafe implement jshell support Jul 5, 2023
@rogerkeays rogerkeays added the enhancement New feature or request label Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant