My main worker thread looks like this:
public final class Worker
implements Runnable {
@Override
public void run() {
try {
_run();
}
catch (RuntimeException e) {
// Cleanup carefully
}
}
private void _run() {
// do work here
}
}
Imagine my surprise when Thread.UncaughtExceptionHandler
reported an uncaught instance of java.lang.ClassNotFoundException
, a checked exception.
(The root cause is a different issue: We were overwriting a JAR file in a dev environment during runtime.)
In my book, this looks like a Sneaky Throw. Why is this exception not a RuntimeException?
Sample stacktrace (sanitised):
Caused by: java.lang.ClassNotFoundException: xyz
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 10 more
Caused by: java.util.zip.ZipException: error reading zip file
at java.util.zip.ZipFile.read(Native Method)
at java.util.zip.ZipFile.access$1400(ZipFile.java:61)
at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:717)
at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:420)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
at java.util.jar.Manifest$FastInputStream.fill(Manifest.java:441)
at java.util.jar.Manifest$FastInputStream.readLine(Manifest.java:375)
at java.util.jar.Manifest$FastInputStream.readLine(Manifest.java:409)
at java.util.jar.Attributes.read(Attributes.java:376)
at java.util.jar.Manifest.read(Manifest.java:199)
at java.util.jar.Manifest.<init>(Manifest.java:69)
at java.util.jar.JarFile.getManifestFromReference(JarFile.java:199)
at java.util.jar.JarFile.getManifest(JarFile.java:180)
at sun.misc.URLClassPath$JarLoader$2.getManifest(URLClassPath.java:780)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:422)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
... 16 more