Skip to content

Commit

Permalink
Fix Issue 2393
Browse files Browse the repository at this point in the history
Fix for Issue #2393 (WrongOneof mishandles new style switch statement) based on PR #2371 and PR #2124.

Fixes #2470

COPYBARA_INTEGRATE_REVIEW=#2470 from openamiguel:master 148cf4d
PiperOrigin-RevId: 390456921
  • Loading branch information
openamiguel authored and Error Prone Team committed Aug 12, 2021
1 parent b1c4299 commit b894205
Showing 1 changed file with 6 additions and 2 deletions.
Expand Up @@ -44,11 +44,13 @@
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.tree.StatementTree;
import com.sun.source.tree.SwitchTree;
import com.sun.source.util.TreePath;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.VarSymbol;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

Expand Down Expand Up @@ -100,8 +102,10 @@ public Description matchSwitch(SwitchTree tree, VisitorState state) {

scanForInvalidGetters(getters, allowableGetters, caseTree, receiverSymbolChain.get(), state);

if (!caseTree.getStatements().isEmpty()
&& !canCompleteNormally(getLast(caseTree.getStatements()))) {
List<? extends StatementTree> statements = caseTree.getStatements();
if (statements != null
&& !statements.isEmpty()
&& !canCompleteNormally(getLast(statements))) {
allowableGetters.clear();
}
}
Expand Down

0 comments on commit b894205

Please sign in to comment.