Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Java 17 is far more strict in enforcement of class encapsulation.  For example, in previous Java releases, it was possible for a developer to set Java system properties as well as environment variables by using Java Reflection, as in the following code example:

    Code Block
    languagejava
            try{
                Map<String, String> env = System.getenv();
                Class<?> cl = env.getClass();
                Field field = cl.getDeclaredField("m");
                field.setAccessible(true);
                Map<String, String> writableEnv = (Map<String, String>) field.get(env);
                writableEnv.put(SDNC_CONFIG_DIR, "./src/test/resources");
            } catch (Exception e) {
                throw new IllegalStateException("Failed to set environment variable", e);
            }

    This is no longer permitted in Java 17 and will throw an IllegalAccessException.

    In our code, we were only using this within our jUnit tests.  Instead, we updated our design to set system properties and environment variables within the surefire-maven-plugin section of our project pom.xml, as in the following example:

    Code Block
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <environmentVariables>
                            <SDNC_CONFIG_DIR>src/test/resources</SDNC_CONFIG_DIR>
                        </environmentVariables>
                    </configuration>
                </plugin>


  2. Older versions of the maven lombok plugin use similar "tricks" that lead to IllegalAccessExceptions in Java 17.  If you are using lombok in Java 17, be sure to use at least version 1.18.24
  3. Users of JAX-B will need to add a dependency for the jax-b runtime library:

    Code Block
                        <dependency>
                            <groupId>org.glassfish.jaxb</groupId>
                            <artifactId>jaxb-runtime</artifactId>
                            <version>${jaxb-api.version}</version>
                        </dependency>


  4.  Users of the maven-bundle-plugin need to use  version 5.1.1 or greater with Java 17.
  5. The older maven gmaven-plugin throws an exception when used with the java 17 JVM.  Instead, the groovy-maven-plugin should be used.  This is the version we use in CCSDK London:

    Code Block
                   <groupId>org.codehaus.gmaven</groupId>
                    <artifactId>groovy-maven-plugin</artifactId>
                    <version>2.1.1</version>