JDK-6906748 : Project Coin: Minor strings in switch cleanup
Type:Bug
Component:tools
Sub-Component:javac
Affected Version:7
Priority:P4
Status:Closed
Resolution:Fixed
OS:generic
CPU:generic
Submitted:2009-12-03
Updated:2021-03-03
Resolved:2011-07-25
The Version table provides details related to the release that this issue/RFE will be addressed.
Unresolved : Release in which this issue/RFE will be addressed. Resolved: Release in which this issue/RFE has been resolved. Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.
Neal made some suggestions for code cleanups and doc clarifications in the strings in switch implementation.
Comments
PUBLIC COMMENTS
See
http://hg.openjdk.java.net/jdk7/tl/langtools/rev/121e0ebf1658
03-12-2009
SUGGESTED FIX
# HG changeset patch
# User darcy
# Date 1259877833 28800
# Node ID 121e0ebf16587ff8a3ae30d36bdb41d2099bad8a
# Parent b1508b6affd8c44518320070169aea2bcdef2390
6906748: Project Coin: Minor strings in switch cleanup
Reviewed-by: jjg
--- a/src/share/classes/com/sun/tools/javac/code/Source.java Mon Nov 23 19:58:05 2009 -0800
+++ b/src/share/classes/com/sun/tools/javac/code/Source.java Thu Dec 03 14:03:53 2009 -0800
@@ -110,9 +110,6 @@ public enum Source {
}
/** Allow encoding errors, giving only warnings. */
- public boolean allowStringsInSwitch() {
- return compareTo(JDK1_7) >= 0;
- }
public boolean allowEncodingErrors() {
return compareTo(JDK1_6) < 0;
}
@@ -168,6 +165,9 @@ public enum Source {
public boolean allowUnderscoresInLiterals() {
return compareTo(JDK1_7) >= 0;
}
+ public boolean allowStringsInSwitch() {
+ return compareTo(JDK1_7) >= 0;
+ }
public static SourceVersion toSourceVersion(Source source) {
switch(source) {
case JDK1_2:
--- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Mon Nov 23 19:58:05 2009 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Dec 03 14:03:53 2009 -0800
@@ -3117,7 +3117,6 @@ public class Lower extends TreeTranslato
tree.cases = translateCases(tree.cases);
if (enumSwitch) {
result = visitEnumSwitch(tree);
- patchTargets(result, tree, result);
} else if (stringSwitch) {
result = visitStringSwitch(tree);
} else {
@@ -3146,7 +3145,9 @@ public class Lower extends TreeTranslato
cases.append(c);
}
}
- return make.Switch(selector, cases.toList());
+ JCSwitch enumSwitch = make.Switch(selector, cases.toList());
+ patchTargets(enumSwitch, tree, enumSwitch);
+ return enumSwitch;
}
public JCTree visitStringSwitch(JCSwitch tree) {
@@ -3187,7 +3188,14 @@ public class Lower extends TreeTranslato
* of String is the same in the compilation environment as
* in the environment the code will run in. The string
* hashing algorithm in the SE JDK has been unchanged
- * since at least JDK 1.2.
+ * since at least JDK 1.2. Since the algorithm has been
+ * specified since that release as well, it is very
+ * unlikely to be changed in the future.
+ *
+ * Different hashing algorithms, such as the length of the
+ * strings or a perfect hashing algorithm over the
+ * particular set of case labels, could potentially be
+ * used instead of String.hashCode.
*/
ListBuffer<JCStatement> stmtList = new ListBuffer<JCStatement>();