cohorte / ipojo-nature

iPOJO Nature Eclipse plugin
Apache License 2.0
1 stars 0 forks source link

JEP 403 effects appear when running in Eclipse 2021-12 which embed a java 17 JVM #6

Open ogattaz opened 2 years ago

ogattaz commented 2 years ago

The message when building a class in a projet having the nature "iPOJO" :

Errors running builder 'Java Builder' on project 'tech.cohorte.ipojo.test.validation'.
Unable to make field private final java.util.Map java.util.jar.Manifest.entries accessible: module java.base does not "opens java.util.jar" to unnamed module @33fb7852

Look at explanations:

Java 17: What’s New, Removed and Preview in JDK 17 | by Vinicius Monteiro | Javarevisited | Medium https://medium.com/javarevisited/java-17-whats-new-removed-and-preview-in-jdk-17-62db367e62ee

A peek into Java 17: Encapsulating the Java runtime internals https://blogs.oracle.com/javamagazine/post/a-peek-into-java-17-continuing-the-drive-to-encapsulate-the-java-runtime-internals

ogattaz commented 2 years ago

The method "setAccessible() is used in two classes:

  1. org/ow2/chameleon/eclipse/ipojo/classpath/container/BundleClassFinder.java
  2. org/ow2/chameleon/eclipse/ipojo/core/Utilities.java

@see https://github.com/cohorte/ipojo-nature/search?q=setAccessible

The reasons:

  1. in the class BundleClassFinder => a trick for the Equinox framework in the method "getLocalURL()".
  2. in the class Utilities => to sort the attributes of a manifest in the method "makeSortedManifest()".
ogattaz commented 2 years ago

The stacktrace of the InaccessibleObjectException instance thrown when the "Utilities:makeSortedManifest()" method is running:

!ENTRY org.eclipse.core.resources 4 75 2021-12-27 09:43:16.485
!MESSAGE Errors occurred during the build.
!SUBENTRY 1 org.eclipse.jdt.core 4 75 2021-12-27 09:43:16.485
!MESSAGE Errors running builder 'Java Builder' on project 'tech.cohorte.ipojo.nature.test'.
!STACK 0
java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Map java.util.jar.Manifest.entries accessible: module java.base does not "opens java.util.jar" to unnamed module @51b4326b
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
    at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
    at org.ow2.chameleon.eclipse.ipojo.core.Utilities.makeSortedManifest(Utilities.java:460)
    at org.ow2.chameleon.eclipse.ipojo.core.EclipseResourceStore.open(EclipseResourceStore.java:185)
    at org.apache.felix.ipojo.manipulator.visitor.writer.ManipulatedResourcesWriter.visitEnd(ManipulatedResourcesWriter.java:70)
    at org.apache.felix.ipojo.manipulator.visitor.ManipulationAdapter.visitEnd(ManipulationAdapter.java:49)
    at org.apache.felix.ipojo.manipulator.Pojoization.pojoization(Pojoization.java:384)
    at org.ow2.chameleon.eclipse.ipojo.core.ManifestUpdater.updateManifest(ManifestUpdater.java:280)
    at org.ow2.chameleon.eclipse.ipojo.builder.IPojoCompilationParticipant.updateManifest(IPojoCompilationParticipant.java:212)
    at org.ow2.chameleon.eclipse.ipojo.builder.IPojoCompilationParticipant.buildFinished(IPojoCompilationParticipant.java:75)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:250)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:853)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:232)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:281)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:334)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:337)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:389)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:410)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:160)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:251)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
ogattaz commented 2 years ago

I found that post : Order of entries in MANIFEST.MF https://stackoverflow.com/questions/57361040/order-of-entries-in-manifest-mf

So, as the method "makeSortedManifest()" is always called just before the method "setManifestContent()", is the using of a class like "org.apache.juneau.utils.ManifestFile" could be the solution to have ordered attributes in the MANIFEST.MF file ?

eg. 1

        if (previousValue != null) {
            // Use a sorted manifest object first
            Utilities.INSTANCE.makeSortedManifest(aProject, manifestContent);

            // There was something before, so write the new manifest
            Utilities.INSTANCE.setManifestContent(aProject, manifestContent);
        }

eg. 2

        // Sort the manifest keys
        Utilities.INSTANCE.makeSortedManifest(pProject, updateManifest);

        // Write the file
        try {
            Utilities.INSTANCE.setManifestContent(pProject, updateManifest);

        } catch (final CoreException ex) {
            Activator.logError(pProject, "Error writing the manifest file", ex);
            throw new IOException("Can't write the manifest file", ex);
        }

JavaDoc: https://juneau.apache.org/site/apidocs-8.2.0/org/apache/juneau/utils/ManifestFile.html Source: https://github.com/apache/juneau/blob/106b1883b83dfca1cbdb40167223e0de9d700c17/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/utils/ManifestFile.java