AdaptRecursive StackOverflowError

2019-08-01 12:34发布

问题:

While compiling my project I get:

The system is out of resources.
Consult the following stack trace for details.
java.lang.StackOverflowError
    at com.sun.tools.javac.code.Type$WildcardType.isSuperBound(Type.java:435)
    at com.sun.tools.javac.code.Types$1.visitWildcardType(Types.java:102)
    at com.sun.tools.javac.code.Types$1.visitWildcardType(Types.java:98)
    at com.sun.tools.javac.code.Type$WildcardType.accept(Type.java:416)
    at com.sun.tools.javac.code.Types$MapVisitor.visit(Types.java:3232)
    at com.sun.tools.javac.code.Types.upperBound(Types.java:95)
    at com.sun.tools.javac.code.Types.adaptRecursive(Types.java:2986)
    at com.sun.tools.javac.code.Types.adapt(Types.java:3016)
    at com.sun.tools.javac.code.Types.adaptRecursive(Types.java:2977)
    at com.sun.tools.javac.code.Types.adaptRecursive(Types.java:2986)
    at com.sun.tools.javac.code.Types.adapt(Types.java:3016)
    at com.sun.tools.javac.code.Types.adaptRecursive(Types.java:2977)
    at com.sun.tools.javac.code.Types.adaptRecursive(Types.java:2986)
    at com.sun.tools.javac.code.Types.adapt(Types.java:3016)
    at com.sun.tools.javac.code.Types.adaptRecursive(Types.java:2977)
    at com.sun.tools.javac.code.Types.adaptRecursive(Types.java:2986)
    at com.sun.tools.javac.code.Types.adapt(Types.java:3016)
    ...

How do you find the root of the problem?

I have found a bug report...

回答1:

The bug report you linked to indicates that the bug was fixed in JDK 6. Which version of the JDK are you using to build?

If you can't identify the part of your source that is causing the problem, perhaps you could try compiling with JDK 6 to see if it can identify the problem without crashing.

Otherwise, I would use the "divide and conquer" approach: Remove half your source code, compile, and see if it still crashes. Depending on whether it does or not, you will know which half the problem is in. Repeat.



回答2:

I would start by running javac with the -verbose option to see which .java file was causing the problem.



回答3:

What about trying a different compiler, like the one in Eclipse? It's error messages are at least different, in my experience often more to the point. Also I haven't seen compilation failures like this yet.