Commit b24c0b07 authored by Philip S Doctor's avatar Philip S Doctor Committed by Wouter van Oortmerssen

When Java raises a CharacterCodingException, the catch block rethrows this…

When Java raises a CharacterCodingException, the catch block rethrows this exception as a java.lang.Error.  Per the docs https://docs.oracle.com/javase/8/docs/api/java/lang/Error.html an Error is a serious problem that applications should not attempt to catch such as ThreadDeath.  In this case, it is reasonable for a consumer to try to catch this error as it likely indicates a problem with the underlying data. (#4630)

As Error does not inherit from Exception, a generic `catch(Exception ex)` will not catch this error.

A simple change from `Error` to `Exception` is not sufficient as an `Exception` is checked by the compiler, so in order to keep this issue unchecked, I am proposing raising a `RuntimeException` which is not checked, but is still a subclass of `Exception`.

The only possible breaking change would be if a consumer was explicitly catching `Error` already for this library.

https://github.com/google/flatbuffers/issues/4629
parent 59e26017
......@@ -122,7 +122,7 @@ public class Table {
cr.throwException();
}
} catch (CharacterCodingException x) {
throw new Error(x);
throw new RuntimeException(x);
}
return dst.flip().toString();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment