Classloaders hierarchy in Java 9

Here is the migration guide for Java 9, New Class Loader Implementations JDK 9 maintains the hierarchy of class loaders that existed since the 1.2 release. However, the following changes have been made to implement the module system: The application class loader is no longer an instance of URLClassLoader but, rather, of an internal class. … Read more

Java 9 + maven + junit: does test code need module-info.java of its own and where to put it?

The module system does not distinguish between production code and test code, so if you choose to modularize test code, the prod.module and the test.module cannot share the same package com.acme.project, as described in the specs: Non-interference — The Java compiler, virtual machine, and run-time system must ensure that modules that contain packages of the … Read more

How to hide warning “Illegal reflective access” in java 9 without JVM argument?

There are ways to disable illegal access warning, though I do not recommend doing this. 1. Simple approach Since the warning is printed to the default error stream, you can simply close this stream and redirect stderr to stdout. public static void disableWarning() { System.err.close(); System.setErr(System.out); } Notes: This approach merges error and output streams. … Read more

What is the difference between List.of and Arrays.asList?

Arrays.asList returns a mutable list while the list returned by List.of is immutable: List<Integer> list = Arrays.asList(1, 2, null); list.set(1, 10); // OK List<Integer> list = List.of(1, 2, 3); list.set(1, 10); // Fails with UnsupportedOperationException Arrays.asList allows null elements while List.of doesn’t: List<Integer> list = Arrays.asList(1, 2, null); // OK List<Integer> list = List.of(1, 2, … Read more

Why is the finalize() method deprecated in Java 9?

Although the question was asking about the Object.finalize method, the subject really is about the finalization mechanism as a whole. This mechanism includes not only the surface API Object.finalize, but it also includes specifications of the programming language about the life cycle of objects, and practical impact on garbage collector implementations in JVMs. Much has … Read more

Tomcat 7.0.73 doesn’t work with java 9

You’ll have to hack the script bin/catalina.sh to get this to work. There are a bunch of lines like this in bin/catalina.sh: exec “$_RUNJDB” “$LOGGING_CONFIG” $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -Djava.endorsed.dirs=”$JAVA_ENDORSED_DIRS” -classpath “$CLASSPATH” \ … Just remove the second of those lines (the one with -Djava.endorsed.dirs) in each case and you should be back in business. … Read more