4

I've been curious how can a java.lang.InternalError or a java.lang.UnknownError be thrown.

I don't mean simply

throw new InternalError();
throw new UnknownError();

but one thrown by the Java SE library or JVM itself (with recent usual Oracle implementation).

For example, specific codes or circumstances that make ArrayList.clone really throw an InternalError is an answer I want. The following is its source code.

public Object clone() {
    try {
        ArrayList<?> v = (ArrayList<?>) super.clone();
        v.elementData = Arrays.copyOf(elementData, size);
        v.modCount = 0;
        return v;
    } catch (CloneNotSupportedException e) {
        // this shouldn't happen, since we are Cloneable
        throw new InternalError(e);
    }
}

2 Answers 2

5

If you want to exercise your curiosity, go to the Java Bugs Database page, and search for bugs with InternalError and UnknownError as the keyword.

These reports will almost all be bugs where someone has managed to cause an InternalError or UnknownError to occur ... not just theoretical possibilities.

Note:

  • Most of these bugs are probably historical; i.e. fixed in earlier versions of Java. (But then you didn't clearly specify which version you were talking about. How recent? Usual for who?)

  • Many of the old bugs appear to have been hidden from public view. When you click on the link in the search results, it takes you back to the search from. (If you don't like it, complain to Oracle ... not me.)


In addition to the reported bugs, there probably lots of ways that you could cause these errors to occur if you were prepared to interfere with the Java installation (e.g. tweak the "rt.jar" file) or mess around in native code.

Sign up to request clarification or add additional context in comments.

1 Comment

There are also some on StackOverflow, such as this: stackoverflow.com/questions/8446243/…
2

I've seen this happen in production in a JVM embedded in C++ code. While this is an obscure case, I think it show the kind of stuff that causes InternalError to be thrown.

  • Link the C++ code statically with libz
  • Create the embedded JVM
  • Attempt to use org.apache.hadoop.io.compress.zlib.ZlibDecompressor in a Hadoop environment where hadoop.so is available.
  • Hadoop.so will attempt some native code loading, and eventually get to the stack trace

While we never nailed down exactly the nature of the incompatibility, removing the static link to libz from our C++ code (thereby letting it find libz.so.1 instead) solved the issue.

java.lang.InternalError
org.apache.hadoop.io.compress.zlib.ZlibDecompressor.init(Native Method)
org.apache.hadoop.io.compress.zlib.ZlibDecompressor.<init>(ZlibDecompressor.java:115)
...

I believe that you would hit the same kind of issue in the following scenario using a more normal Java program calling into native code:

System.load("library1");
// library1 statically links an incompatible libz version
System.load("libz");
// use libz via java native methods

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.