Behavior change in exceptions when calling the Class.getAnnotation() method

The method java.lang.Class.getAnnotation() previously threw the incorrect java.lang.ArrayStoreException when the annotation had an array value that references a missing class. In Java 11 this call results in a java.lang.TypeNotPresentException when the annotation has an array value that references a missing class. Evaluate the logic in your catch block to see if you need to also handle TypeNotPresentException or a more general runtime exception type.

This rule flags calls to the java.lang.Class.getAnnotation() method when the method call is surrounded by a try statement with a catch clause for ArrayStoreException.

This rule has an automated fix to replace ArrayStoreException with TypeNotPresentException in try/catch using Class.getAnnotation(). Copy the custom configuration to your application build file to enable the fix automation.

For Class Javadoc, see Class. For more information on Java SE 11 changes, see Removed Features and Options in JDK 11.