web-dev-qa-db-fra.com

Correctif pour Java 10 se plaindre d'un accès illégal à la réflexion par jaxb-impl 2.3.0?

Nous envisageons de mettre à niveau certains codes hérités vers Java 10. JAXB n’est pas visible par défaut (EDIT: et la solution à long terme appropriée est not pour contourner le symptôme en utilisant divers indicateurs JVM, mais corrigez-le correctement) J'ai ajouté cet extrait à mon pom.xml:

    <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
    <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>

Malheureusement, il y a toujours un avertissement imprimé au démarrage sur stderr. Apparemment, ce n'est pas la solution correcte.

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.Sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/home/tra/.m2/repository/com/Sun/xml/bind/jaxb-impl/2.3.0/jaxb-impl-2.3.0.jar) to method Java.lang.ClassLoader.defineClass(Java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.Sun.xml.bind.v2.runtime.reflect.opt.Injector
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

La sortie complète de --illegal-access=debug est:

WARNING: Illegal reflective access by com.Sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/home/tra/.m2/repository/com/Sun/xml/bind/jaxb-impl/2.3.0/jaxb-impl-2.3.0.jar) to method Java.lang.ClassLoader.defineClass(Java.lang.String,byte[],int,int)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector.getMethod(Injector.Java:222)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector.access$000(Injector.Java:74)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector$1.run(Injector.Java:175)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector$1.run(Injector.Java:172)
    at Java.base/Java.security.AccessController.doPrivileged(Native Method)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector.<clinit>(Injector.Java:171)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector.prepare(AccessorInjector.Java:81)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.Java:179)
    at com.Sun.xml.bind.v2.runtime.reflect.Accessor$FieldReflection.optimize(Accessor.Java:285)
    at com.Sun.xml.bind.v2.runtime.property.ArrayProperty.<init>(ArrayProperty.Java:68)
    at com.Sun.xml.bind.v2.runtime.property.ArrayERProperty.<init>(ArrayERProperty.Java:88)
    at com.Sun.xml.bind.v2.runtime.property.ArrayElementProperty.<init>(ArrayElementProperty.Java:100)
    at com.Sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.<init>(ArrayElementNodeProperty.Java:62)
    at com.Sun.xml.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.Java:128)
    at com.Sun.xml.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.Java:181)
    at com.Sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.Java:514)
    at com.Sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.Java:331)
    at com.Sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.Java:139)
    at com.Sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.Java:1156)
    at com.Sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.Java:165)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.Java:297)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.Java:286)
    at javax.xml.bind.ContextFinder.find(ContextFinder.Java:409)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.Java:721)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.Java:662)
    at dk.statsbiblioteket.medieplatform.autonomous.PremisManipulatorFactory.<init>(PremisManipulatorFactory.Java:28)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule.providePremisManipulatorFactory(DomsModule.Java:182)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule_ProvidePremisManipulatorFactoryFactory.get(DomsModule_ProvidePremisManipulatorFactoryFactory.Java:32)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule_ProvidePremisManipulatorFactoryFactory.get(DomsModule_ProvidePremisManipulatorFactoryFactory.Java:11)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule_ProvideSBOIEventIndexFactory.get(DomsModule_ProvideSBOIEventIndexFactory.Java:56)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule_ProvideSBOIEventIndexFactory.get(DomsModule_ProvideSBOIEventIndexFactory.Java:12)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.doms.DomsRepository_Factory.get(DomsRepository_Factory.Java:53)
WARNING: Illegal reflective access by com.Sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/home/tra/.m2/repository/com/Sun/xml/bind/jaxb-impl/2.3.0/jaxb-impl-2.3.0.jar) to method Java.lang.ClassLoader.resolveClass(Java.lang.Class)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector.getMethod(Injector.Java:222)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector.access$000(Injector.Java:74)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector$1.run(Injector.Java:175)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector$1.run(Injector.Java:172)
    at Java.base/Java.security.AccessController.doPrivileged(Native Method)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector.<clinit>(Injector.Java:171)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector.prepare(AccessorInjector.Java:81)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.Java:179)
    at com.Sun.xml.bind.v2.runtime.reflect.Accessor$FieldReflection.optimize(Accessor.Java:285)
    at com.Sun.xml.bind.v2.runtime.property.ArrayProperty.<init>(ArrayProperty.Java:68)
    at com.Sun.xml.bind.v2.runtime.property.ArrayERProperty.<init>(ArrayERProperty.Java:88)
    at com.Sun.xml.bind.v2.runtime.property.ArrayElementProperty.<init>(ArrayElementProperty.Java:100)
    at com.Sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.<init>(ArrayElementNodeProperty.Java:62)
    at com.Sun.xml.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.Java:128)
    at com.Sun.xml.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.Java:181)
    at com.Sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.Java:514)
    at com.Sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.Java:331)
    at com.Sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.Java:139)
    at com.Sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.Java:1156)
    at com.Sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.Java:165)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.Java:297)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.Java:286)
    at javax.xml.bind.ContextFinder.find(ContextFinder.Java:409)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.Java:721)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.Java:662)
    at dk.statsbiblioteket.medieplatform.autonomous.PremisManipulatorFactory.<init>(PremisManipulatorFactory.Java:28)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule.providePremisManipulatorFactory(DomsModule.Java:182)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule_ProvidePremisManipulatorFactoryFactory.get(DomsModule_ProvidePremisManipulatorFactoryFactory.Java:32)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule_ProvidePremisManipulatorFactoryFactory.get(DomsModule_ProvidePremisManipulatorFactoryFactory.Java:11)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule_ProvideSBOIEventIndexFactory.get(DomsModule_ProvideSBOIEventIndexFactory.Java:56)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule_ProvideSBOIEventIndexFactory.get(DomsModule_ProvideSBOIEventIndexFactory.Java:12)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.doms.DomsRepository_Factory.get(DomsRepository_Factory.Java:53)
WARNING: Illegal reflective access by com.Sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/home/tra/.m2/repository/com/Sun/xml/bind/jaxb-impl/2.3.0/jaxb-impl-2.3.0.jar) to method Java.lang.ClassLoader.findLoadedClass(Java.lang.String)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector.getMethod(Injector.Java:222)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector.access$000(Injector.Java:74)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector$1.run(Injector.Java:175)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector$1.run(Injector.Java:172)
    at Java.base/Java.security.AccessController.doPrivileged(Native Method)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.Injector.<clinit>(Injector.Java:171)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector.prepare(AccessorInjector.Java:81)
    at com.Sun.xml.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.Java:179)
    at com.Sun.xml.bind.v2.runtime.reflect.Accessor$FieldReflection.optimize(Accessor.Java:285)
    at com.Sun.xml.bind.v2.runtime.property.ArrayProperty.<init>(ArrayProperty.Java:68)
    at com.Sun.xml.bind.v2.runtime.property.ArrayERProperty.<init>(ArrayERProperty.Java:88)
    at com.Sun.xml.bind.v2.runtime.property.ArrayElementProperty.<init>(ArrayElementProperty.Java:100)
    at com.Sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.<init>(ArrayElementNodeProperty.Java:62)
    at com.Sun.xml.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.Java:128)
    at com.Sun.xml.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.Java:181)
    at com.Sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.Java:514)
    at com.Sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.Java:331)
    at com.Sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.Java:139)
    at com.Sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.Java:1156)
    at com.Sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.Java:165)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.Java:297)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.Java:286)
    at javax.xml.bind.ContextFinder.find(ContextFinder.Java:409)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.Java:721)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.Java:662)
    at dk.statsbiblioteket.medieplatform.autonomous.PremisManipulatorFactory.<init>(PremisManipulatorFactory.Java:28)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule.providePremisManipulatorFactory(DomsModule.Java:182)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule_ProvidePremisManipulatorFactoryFactory.get(DomsModule_ProvidePremisManipulatorFactoryFactory.Java:32)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule_ProvidePremisManipulatorFactoryFactory.get(DomsModule_ProvidePremisManipulatorFactoryFactory.Java:11)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule_ProvideSBOIEventIndexFactory.get(DomsModule_ProvideSBOIEventIndexFactory.Java:56)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.tools.modules.DomsModule_ProvideSBOIEventIndexFactory.get(DomsModule_ProvideSBOIEventIndexFactory.Java:12)
    at dk.statsbiblioteket.digital_pligtaflevering_aviser.doms.DomsRepository_Factory.get(DomsRepository_Factory.Java:53)

Quelles sont les dépendances appropriées à utiliser ici pour résoudre ce problème?

le runtime jaxb-ri utilise ClassLoader#defineClass / Unsafe#defineClass pour effectuer des modifications de code intermédiaire au moment de l'exécution afin d'optimiser les performances. ClassLoader#defineClass est essayé en premier, ce qui provoque l'avertissement.

Cette optimisation héritée est supprimée complètement dans le maître jaxb-ri (après la version 2.3.0, pas encore publiée).

Pour désactiver cette optimisation pour la version 2.3.0, définissez la propriété système com.Sun.xml.bind.v2.bytecode.ClassTailor.noOptimize.

Après la prochaine version de jaxb-ri, la mise à jour vers la version la plus récente supprimera l’avertissement. l'artefact jaxb-core sera abandonné en faveur du support JPMS. Pom correct va ressembler à:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.4.0</version> <!-- not released yet -->
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.4.0</version> <!-- not released yet -->
</dependency>

Si vous souhaitez essayer plus tôt, vous pouvez choisir la dernière version promue parmi: https://maven.Java.net/content/groups/promoted/org/glassfish/jaxb/jaxb-runtime/

25

bravo à @Roman Grigoriadi, il avait raison, la version 2.4 mise à jour corrige les problèmes d’avertissement. Ajoutez simplement les dépendances ci-dessous au fichier pom

<dependency>
  <groupId>javax.xml.bind</groupId>
  <artifactId>jaxb-api</artifactId>
  <version>2.4.0-b180830.0359</version>
</dependency>
<dependency>
  <groupId>org.glassfish.jaxb</groupId>
  <artifactId>jaxb-runtime</artifactId>
  <version>2.4.0-b180830.0438</version>
</dependency>
4
Evan