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

Guoxiong Li gli at openjdk.java.net
Sun Jul 4 18:21:11 UTC 2021


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

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

Commit messages:
 - 8269113: Javac throws when compiling switch (null)

Changes: https://git.openjdk.java.net/jdk/pull/4679/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=4679&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8269113
  Stats: 17 lines in 2 files changed: 15 ins; 0 del; 2 mod
  Patch: https://git.openjdk.java.net/jdk/pull/4679.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/4679/head:pull/4679

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


More information about the compiler-dev mailing list