-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Make dependency on java.sql optional #1707
Conversation
Don't worry, I don't pester easily. 😉 I'm happy to provide input, but keep in mind that I don't know GSON or the diff in detail (don't have the time to study them right now), so I may be off. Caveat emptor, I guess. Also, I wrote a blog post about optional dependencies that may help understand the feature. As I understand the situation, GSON only needs to work with java.sql types if the user already uses them, right? I.e. there's never a situation where a GSON user doesn't need the java.sql module, but GSON uses its types anyway. If that is so, Note that In case you're interested, the blog post shows a method I agree with your confusion about #1500. Turning |
Thanks for your clarification! Yes Gson does not need any Your
Regarding previously reported |
Heres another example of the same problem this time with CLosureCompiler, so+++ from me as well. [INFO] java.lang.SecurityException: Prohibited package name: java.sql
[INFO] at java.base/java.lang.ClassLoader.preDefineClass(ClassLoader.java:889)
[INFO] at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1005)
[INFO] at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
[INFO] at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:545)
[INFO] at java.base/java.net.URLClassLoader.access$100(URLClassLoader.java:83)
[INFO] at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:453)
[INFO] at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:447)
[INFO] at java.base/java.security.AccessController.doPrivileged(Native Method)
[INFO] at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:446)
[INFO] at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:425)
[INFO] at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
[INFO] at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
[INFO] at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
[INFO] at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
[INFO] at com.google.gson.Gson.<init>(Gson.java:265)
[INFO] at com.google.gson.Gson.<init>(Gson.java:186)
[INFO] at com.google.javascript.jscomp.AbstractCommandLineRunner.<init>(AbstractCommandLineRunner.java:224) |
This pull request worked great for me in a java agent (which cant use java.sql) When building it I got this test failure though :
I'm wondering if this is a timezone issue. TZ="Europe/Berlin" |
Thanks for your work on resolving this issue with this pull request, @Marcono1234. @inder123, Is it possible we could get a review on this PR? When using the The indirect/transitive module dependencies that end up being added are listed here: https://docs.oracle.com/javase/9/docs/api/java.sql-summary.html I would really appreciate seeing the |
I ran this against all of Google's internal tests that depend (directly or indirectly) on Gson, and didn't see any problems. I think this is good to go. |
Note: This is based on #1656
Fixes #1629
Makes the dependency on the
java.sql
module optional. If its classes are present at runtime, the respective type adapters will be used, otherwise Gson will not try to load the classes and will therefore not fail with aClassNotFoundException
anymore. The entry point for all SQL type adapters is nowSqlTypesSupport
.I am however, not that familiar with the module system so it would be good if others who are more familiar with it can check if this is a sane implementation.
Especially #1500 (@Degubi) is confusing me because from what I understood about the JPMS
requires transitive
is only so modules depending on Gson would also be "reading"java.sql
, which however makes no sense because Gson does not expose these types publicly anywhere, so it should not provide them transitively. To my understandingrequires
should have been enough to requirejava.sql
being present at runtime, however based on theClassNotFoundException
reports this was not the case?Or are they using tools (as it is the case here which break the module system)? Though that would be a rather common issue then, see the question "java.sql.Time exception".
Also pinging @nicolaiparlog, if you have any spare time, any hints regarding the JPMS would be appreciated :)
Sorry to pester you in case you don't have any time.