RFR: JDK-8234025 Elements.getPackageElement(ModuleElement,CharSequence) returns null for unnamed package

Jonathan Gibbons jonathan.gibbons at oracle.com
Tue Nov 12 22:51:05 UTC 2019


Please review a small fix and corresponding test so that
     Elements.getPackageElement(ModuleElement mdle, CharSequence name)
returns a non-null result, as intended, for an unnamed package.

The fault occurs in this code  in JavacElements.nameToSymbol:

try {
     if (sym ==null)
         sym =javaCompiler.resolveIdent(module, nameStr);

     if (clazz.isInstance(sym)) {
         sym.complete();
         if (sym.kind !=ERR &&
             sym.exists() &&
             name.equals(sym.getQualifiedName())) {
             return clazz.cast(sym);
         }
     }
     return null;
}catch (CompletionFailure cf) {
     cf.dcfh.handleAPICompletionFailure(cf);
     return null;
}

While a non-null value for sym is found early on, it fails the 
`.exists()` test and so `null` is returned.

The fix is to mark the symbol as existing.

-- Jon

JBS: https://bugs.openjdk.java.net/browse/JDK-8234025
Webrev: http://cr.openjdk.java.net/~jjg/8234025/webrev.00/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20191112/c675c652/attachment.html>


More information about the compiler-dev mailing list