CompilerToVM.lookupType() can throw a ClassNotFoundException but it doesn't document it. This prohibits catching the ClassNotFoundException outside for proper error handling as javac detects that the exception is never thrown from the try statement body. Catching all the exceptions outside, filtering out the ClassNotFoundException and rethrowing the others works with javac but it is problematic if using tools like findbugs.
Here is a trace where a ClassNotFoundException is thrown if the method for which the annotation is requested has a type which is not present on the classpath:
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at jdk.vm.ci.hotspot.CompilerToVM.lookupType(Native Method)
at jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.lookupType(HotSpotJVMCIRuntime.java:369)
at jdk.vm.ci.hotspot.HotSpotUnresolvedJavaType.resolve(HotSpotUnresolvedJavaType.java:89)
at jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.toJava(HotSpotResolvedJavaMethodImpl.java:577)
at jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.getAnnotation(HotSpotResolvedJavaMethodImpl.java:521)
Here is a trace where a ClassNotFoundException is thrown if the method for which the annotation is requested has a type which is not present on the classpath:
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at jdk.vm.ci.hotspot.CompilerToVM.lookupType(Native Method)
at jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.lookupType(HotSpotJVMCIRuntime.java:369)
at jdk.vm.ci.hotspot.HotSpotUnresolvedJavaType.resolve(HotSpotUnresolvedJavaType.java:89)
at jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.toJava(HotSpotResolvedJavaMethodImpl.java:577)
at jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.getAnnotation(HotSpotResolvedJavaMethodImpl.java:521)