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>