Suspicious 'noOuterThisPath' variable in com.sun.tools.javac.comp.Attr#visitIdent

Andrey Turbanov turbanoff at gmail.com
Wed Aug 18 07:50:25 UTC 2021


Hello.

During investigation of results of IDEA inspections I found suspicious
code in a method 'com.sun.tools.javac.comp.Attr#visitIdent'
https://github.com/openjdk/jdk/blob/master/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java#L4194

Env<AttrContext> symEnv = env;
boolean noOuterThisPath = false;
if (env.enclClass.sym.owner.kind != PCK && // we are in an inner class
    sym.kind.matches(KindSelector.VAL_MTH) &&
    sym.owner.kind == TYP &&
    tree.name != names._this && tree.name != names._super) {

    // Find environment in which identifier is defined.
    while (symEnv.outer != null &&
           !sym.isMemberOf(symEnv.enclClass.sym, types)) {
        if ((symEnv.enclClass.sym.flags() & NOOUTERTHIS) != 0)
            noOuterThisPath = false;
        symEnv = symEnv.outer;
    }
}


Variable 'noOuterThisPath' has initially assigned a 'false' value.
And then in cycle it again can be set to 'false'.
There are only 2 places where noOuterThisPath is assigned.
It seems it should be set to 'true' in one of the places.


Andrey Turbanov


More information about the compiler-dev mailing list