web-dev-qa-db-ja.com

jaxb-impl 2.3.0による不正なリフレクションアクセスについて不平を言っているJava 10の適切な修正

いくつかのレガシーコードをJava 10にアップグレードすることを検討しています。JAXBはデフォルトでは表示されないため(編集:および適切な長期ソリューションはnotです。フラグ、ただし適切に修正)このスニペットを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>

残念ながら、起動時にstderrに警告が出力されます。どうやらこれは正しい修正ではありません。

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

--illegal-access=debugからの完全な出力は次のとおりです。

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)

この問題を解決するためにここで使用する適切な依存関係は何ですか?

jaxb-riランタイムは、ClassLoader#defineClass / Unsafe#defineClassを使用して、ランタイムでバイトコードを変更し、パフォーマンスを最適化します。 ClassLoader#defineClassが最初に試行され、警告が発生します。

このレガシー最適化は、jaxb-riマスターで完全に削除されています(2.3.0以降、まだリリースされていません)。

2.3.0でこの最適化を無効にするには、システムプロパティcom.Sun.xml.bind.v2.bytecode.ClassTailor.noOptimizeを設定します。

次のjaxb-riリリースの後、最新バージョンに更新すると警告が削除されます。 jaxb-coreアーティファクトは、JPMSサポートのために廃止されます。正しいPOMは次のようになります。

<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>

早めに試してみたい場合は、最新の昇格ビルドを以下から選択できます。 https://maven.Java.net/content/groups/promoted/org/glassfish/jaxb/jaxb-runtime/

25

@Roman Grigoriadiに称賛、彼は正しかった、更新された2.4バージョンは警告の問題を修正します。以下の依存関係を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