Skip to content

Problem with Jackson reflection and (I think) Javax.activation #2318

Closed

Description

@fabionebbia

I've used dropwizard-core 1.3.0 targeting jdk 9. Don't know if it's something related to jdk 9.
I've run the simple program of the Getting Started guide on the website.

Here's the problem with Jackson reflection:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.fasterxml.jackson.module.afterburner.util.MyClassLoader (file:/Users/fabio/IdeaProjects/smartcity/build/libs/hello-1.0-SNAPSHOT.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.fasterxml.jackson.module.afterburner.util.MyClassLoader
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

And here's the one with javax (I think), which disappear if I use the VM parameter "--add-modules java.activation" (Why?)

WARN [2018-03-30 01:39:45,151] org.glassfish.jersey.internal.Errors: The following warnings have been detected: WARNING: HK2 service reification failed for [org.glassfish.jersey.message.internal.DataSourceProvider] with an exception:
MultiException stack 1 of 2
java.lang.NoClassDefFoundError: javax/activation/DataSource
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3110)
at java.base/java.lang.Class.getDeclaredConstructors(Class.java:2314)
at org.jvnet.hk2.internal.Utilities$3.run(Utilities.java:1308)
at org.jvnet.hk2.internal.Utilities$3.run(Utilities.java:1304)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.jvnet.hk2.internal.Utilities.getAllConstructors(Utilities.java:1304)
at org.jvnet.hk2.internal.Utilities.findProducerConstructor(Utilities.java:1247)
at org.jvnet.hk2.internal.DefaultClassAnalyzer.getConstructor(DefaultClassAnalyzer.java:83)
...

Activity

  1. changed the title [-]Possible jdk 9 problem with Jackson reflection running the getting started code.[/-] [+]Problem with Jackson reflection and (I think) Javax.activation[/+] on Mar 30, 2018
  2. nickbabcock commented on Mar 30, 2018

    @nickbabcock
    Contributor

    Is this the same issue reported in the Jackson repo? FasterXML/jackson-modules-base#37

  3. RohanNagar commented on Mar 30, 2018

    @RohanNagar
    Contributor

    I'm seeing the same issue with Jackson as well. I think its the same issue reported in the Jackson repo.

    I was also wondering, now that Dropwizard 1.3.0 supports JDK 9, I imagine more people will try to migrate their Dropwizard apps from 1.8 to 1.9 (or to 1.10). Is there a guide for this? Right now in order to run it I need to use --add-modules java.xml.bind both when compiling and when running the jar. I'm wondering if there's a cleaner way.

  4. arteam commented on Mar 30, 2018

    @arteam
    Member

    Yes, we run our tests on JDK10 with --add-modules java.xml.bind: https://github.com/dropwizard/dropwizard/blob/master/pom.xml#L381

    Unfortunately Jersey requires it for JAXB support if I'm not mistaken. We can't do much until a modularized version of Jersey come out.

  5. corcorb commented on Apr 10, 2018

    @corcorb

    FWIW, I was able to work around this by explicitly adding javax.xml.bind:jaxb-api as a dependency — would it make sense for this to be added as dependency for Jackson itself?

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
        </dependency>
  6. jmrodriguez commented on Apr 16, 2018

    @jmrodriguez

    I fixed the java.lang.NoClassDefFoundError: javax/activation/DataSource error by adding the next dependency in the POM

            <dependency>
                <groupId>javax.activation</groupId>
                <artifactId>activation</artifactId>
                <version>1.1.1</version>
            </dependency>
    

    and fixed the JAXB issues by adding these other dependencies

            <dependency>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
                <version>2.3.0</version>
            </dependency>
            <dependency>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-core</artifactId>
                <version>2.3.0</version>
            </dependency>
            <dependency>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-impl</artifactId>
                <version>2.3.0</version>
            </dependency>
    

    I also had to add these two properties to in the pom

            <maven.compiler.source>1.9</maven.compiler.source>
            <maven.compiler.target>1.9</maven.compiler.target>
    

    The application now runs, however the Jackson reflection warning still shows up

  7. added 3 commits that reference this issue on Jan 18, 2019
  8. mattc41190 commented on Apr 12, 2019

    @mattc41190

    @jmrodriguez Thank you very much! The only modifications I needed to make were the dependency based ones.

    My source and target were set to 1.6. and the dependency setting fixed me right up. I suppose it doesn't hurt to set it to 1.9 :)

    Does anyone have any idea why explicit references to those JAXB & JAVAX dependencies are needed for running the application if the application compiles fine without them?

  9. joschi commented on Apr 13, 2019

    @joschi
    Member

    Does anyone have any idea why explicit references to those JAXB & JAVAX dependencies are needed for running the application if the application compiles fine without them?

    JAXB was part of Java until Java 8 and was removed (or rather un-bundled) in Java 9.
    See also: https://jesperdj.com/2018/09/30/jaxb-on-java-9-10-11-and-beyond/

  10. joschi commented on Apr 22, 2019

    @joschi
    Member

    This should work out of the box with Dropwizard 2.0.0-rc1 and later.

    If you have problems with Dropwizard 2.0.0-rc1 (or later) and Java 11, please leave a comment.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions