RFR: 8269113: Javac throws when compiling switch (null)

Guoxiong Li gli at openjdk.java.net
Wed Jul 7 16:29:50 UTC 2021


On Wed, 7 Jul 2021 16:12:51 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> Hi all,
>> 
>> When we use `switch(null)` in the source code, the type of the selector is `BottomType`.
>> So the statement `Type seltype = selector.type;` of the method `TransPatterns::handleSwitch` will get a `BottomType`.
>> Then compiler mistakenly uses this `BottomType` to construct a new `VarSymbol`.
>> 
>> 
>>             VarSymbol temp = new VarSymbol(Flags.SYNTHETIC,
>>                     names.fromString("selector" + tree.pos + target.syntheticNameChar() + "temp"),
>>                     seltype,     // <--------here is a BottomType
>>                     currentMethodSym);
>> 
>> 
>> At last, when the compiler uses the new `VarSymbol temp` to construct a new `JCVariableDecl`(the code shown as below), it crashes at the method `TreeMaker::Type` because the method `TreeMaker::Type` can't handle the type `BottomType`.
>> 
>> 
>> statements.append(make.at(tree.pos).VarDef(temp, !hasNullCase ? attr.makeNullCheck(selector)
>>                                                                           : selector));
>> 
>> 
>> This patch changes the type from `BottomType` to `syms.objectType` and adds the corresponding test.
>> Thanks for taking the time to review.
>> 
>> Best Regards,
>> -- Guoxiong
>
> Looks good to me. Might make sense to submit against openjdk/jdk17 and integrate there?

@lahodaj thanks for your review. I will move this patch to JDK 17 later.

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

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


More information about the compiler-dev mailing list