-
Notifications
You must be signed in to change notification settings - Fork 32
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
Run snakeyaml without java.desktop module #12
Run snakeyaml without java.desktop module #12
Conversation
synced |
0ffd076
to
7726640
Compare
Can this refactoring be considered for integration? Right now I have to patch your library and it doesn't feel comfortable. |
src/main/java/org/yaml/snakeyaml/introspector/PropertyUtils.java
Outdated
Show resolved
Hide resolved
@@ -57,6 +52,13 @@ public PropertyUtils() { | |||
if (platformFeatureDetector.isRunningOnAndroid()) { | |||
beanAccess = BeanAccess.FIELD; | |||
} | |||
|
|||
/* when running with jlink restricted JDK without java.desktop package */ | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this detection into the PlatformFeatureDetector
maybe in something like isIntrospectorAvailable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 2ca1828. Is that OK?
Can you please expose instruction how to use it ? Is there a link to a wiki ? It will be delivered in version 2.3 |
Thank you for accepting my contribution! |
I am experimenting with
jlink
trying to create a small (headless) JDK while still usingsnakeyaml
. I created a small sample program inDemo.java
file:I compile it and run successfully with JDK21:
$ jdk21/bin/javac -d . -cp snakeyaml-1.28.jar Demo.java $ jdk21/bin/java -cp .:snakeyaml-1.28.jar Demo h: 25
however when I try to run it without
java.desktop
module, everything fails.To reproduce
First of all let's build a small JDK via
jlink
command. I use:this generates a small, restricted JDK in
smalljdk
directory. Running with regularsnakeyaml-1.28
then fails with a linkage error:the problem is that
PropertyUtils
class is referencingjava.beans
classes (part ofjava.desktop
JDK module) and those are not available. One of these classes is even in the signature of theisTransient
method and thus the JDK verifier refuses to load thePropertyUtils
class.This PR fixes that by restructuring the code, so only
MethodProperty
class references thejava.beans
package. As this class isn't used inBeanAccess.FIELD
mode, the following passes with the newsnakeyaml
JAR file:These changes are not only useful for our project, but for everyone trying to use snakeyaml on a headless JDK without
java.desktop
. Please consider accepting my refactoring.