changeset 2849:f5a1cb1309ae

8050021: Improper "duplicate case label" error Reviewed-by: jlahoda
author sadayapalam
date Thu, 12 Mar 2015 10:24:07 +0530
parents ea4930998b3a
children 32a2e7249884
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java test/tools/javac/enum/EnumSwitch2.java test/tools/javac/enum/EnumSwitch2.out
diffstat 3 files changed, 15 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Mar 11 23:53:38 2015 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Mar 12 10:24:07 2015 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1211,10 +1211,8 @@
                             if (pattype.constValue() == null) {
                                 log.error(c.pat.pos(),
                                           (stringSwitch ? "string.const.req" : "const.expr.req"));
-                            } else if (labels.contains(pattype.constValue())) {
+                            } else if (!labels.add(pattype.constValue())) {
                                 log.error(c.pos(), "duplicate.case.label");
-                            } else {
-                                labels.add(pattype.constValue());
                             }
                         }
                     }
@@ -1251,19 +1249,17 @@
     // where
     /** Return the selected enumeration constant symbol, or null. */
     private Symbol enumConstant(JCTree tree, Type enumType) {
-        if (!tree.hasTag(IDENT)) {
-            log.error(tree.pos(), "enum.label.must.be.unqualified.enum");
-            return syms.errSymbol;
-        }
-        JCIdent ident = (JCIdent)tree;
-        Name name = ident.name;
-        for (Symbol sym : enumType.tsym.members().getSymbolsByName(name)) {
-            if (sym.kind == VAR) {
-                Symbol s = ident.sym = sym;
-                ((VarSymbol)s).getConstValue(); // ensure initializer is evaluated
-                ident.type = s.type;
-                return ((s.flags_field & Flags.ENUM) == 0)
-                    ? null : s;
+        if (tree.hasTag(IDENT)) {
+            JCIdent ident = (JCIdent)tree;
+            Name name = ident.name;
+            for (Symbol sym : enumType.tsym.members().getSymbolsByName(name)) {
+                if (sym.kind == VAR) {
+                    Symbol s = ident.sym = sym;
+                    ((VarSymbol)s).getConstValue(); // ensure initializer is evaluated
+                    ident.type = s.type;
+                    return ((s.flags_field & Flags.ENUM) == 0)
+                        ? null : s;
+                }
             }
         }
         return null;
--- a/test/tools/javac/enum/EnumSwitch2.java	Wed Mar 11 23:53:38 2015 -0700
+++ b/test/tools/javac/enum/EnumSwitch2.java	Thu Mar 12 10:24:07 2015 +0530
@@ -1,6 +1,6 @@
 /*
  * @test /nodynamiccopyright/
- * @bug 4936393
+ * @bug 4936393 8050021
  * @summary enum switch case labels required to be unqualified.
  * @author gafter
  * @compile/fail/ref=EnumSwitch2.out -XDrawDiagnostics EnumSwitch2.java
--- a/test/tools/javac/enum/EnumSwitch2.out	Wed Mar 11 23:53:38 2015 -0700
+++ b/test/tools/javac/enum/EnumSwitch2.out	Thu Mar 12 10:24:07 2015 +0530
@@ -1,4 +1,3 @@
 EnumSwitch2.java:14:16: compiler.err.enum.label.must.be.unqualified.enum
 EnumSwitch2.java:15:16: compiler.err.enum.label.must.be.unqualified.enum
-EnumSwitch2.java:15:9: compiler.err.duplicate.case.label
-3 errors
+2 errors