NullPointerException in method type inference

Issue #172 resolved
Jesper Öqvist created an issue

ExtendJ 8.0.1-121-gc55b02b Java SE 8

The following simple test case causes a NullPointerException:

public class Test {
    private static final int i = 0;

    public <T extends Test> T a() {
        return b();

    <T extends Test> T b() {
        return null;


Here is part of the stack trace:

        at org.extendj.ast.BodyDecl.hostType(
        at org.extendj.ast.FieldDecl.isPublic(
        at org.extendj.ast.TypeVariable.toInterface_compute(
        at org.extendj.ast.TypeVariable.toInterface(
        at org.extendj.ast.GLBTypeFactory.addInterfaces(
        at org.extendj.ast.GLBTypeFactory.glb(
        at org.extendj.ast.Constraints.resolveSubtypeConstraints(
        at org.extendj.ast.Expr.computeConstraints(
        at org.extendj.ast.Expr.inferTypeArguments_compute(
        at org.extendj.ast.Expr.inferTypeArguments(
        at org.extendj.ast.MethodAccess.potentiallyApplicable(
        at org.extendj.ast.MethodAccess.potentiallyApplicable(
        at org.extendj.ast.MethodAccess.maxSpecific(
        at org.extendj.ast.MethodAccess.decls_compute(
        at org.extendj.ast.MethodAccess.decls(

Comments (3)

  1. Jesper Öqvist reporter

    Added the above test to the regression test suite as test case generics/inference_06p.

  2. Jesper Öqvist reporter

    This bug is caused by first copying some BodyDecl nodes and then evaluating isPublic() on the copies in GLBTypeFactory.jadd. The fix is to simply evaluate isPublic() before the copy.

  3. Jesper Öqvist reporter

    Avoid attribute evaluation in unrooted subtrees

    The isPublic() attribute was evaluated on fresh copies of BodyDecl nodes leading to NullPointerExceptions in some cases.

    fixes #172 (bitbucket)

    → <<cset 06a46a558d57>>

  4. Log in to comment