RFR: 8232765: NullPointerException at Types.eraseNotNeeded() when compiling a class

Maurizio Cimadamore mcimadamore at openjdk.java.net
Wed Apr 21 14:16:40 UTC 2021


On Fri, 15 Jan 2021 12:17:39 GMT, Guoxiong Li <gli at openjdk.org> wrote:

> Hi all,
> 
> The method `types::asSuper` may return `null` so that `types.erasure(types.asSuper(iterator.type.getReturnType(), syms.iteratorType.tsym))` throws `NPE`.
> 
> This patch sets the return type and outputs the corresponding error message if `types::asSuper` returns `null`.
> 
> Thank you for taking the time to review.
> 
> Best Regards.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java line 3501:

> 3499:                                            eType,
> 3500:                                            List.nil());
> 3501:             Type returnType = types.asSuper(iterator.type.getReturnType(), syms.iteratorType.tsym);

I know you closed this PR - just wanted to leave a comment: issuing this kind of type-checking errors in Lower is unusual. This kind of stuff should be caught in earlier (e.g. in Attr) - and, over the years we've been making efforts to move all error generation in the front-end; note than when using compiler through the compiler API, you might not run Lower (and all desugaring steps) so you might miss errors if these are generated too late.

That said, surely the check:


            Type returnType = types.asSuper(iterator.type.getReturnType(), syms.iteratorType.tsym);
 ```

Must be somewhere in Attr?

-------------

PR: https://git.openjdk.java.net/jdk/pull/2099


More information about the compiler-dev mailing list