8028415: TreeMaker.Literal(Object) creates invalid JCLiterals when passed a Character.
authorjlahoda
Tue, 17 Dec 2013 10:58:21 +0100
changeset 22154 3c8d86bf756b
parent 22153 f9f06fcca59d
child 22155 2f0a83a98593
8028415: TreeMaker.Literal(Object) creates invalid JCLiterals when passed a Character. Summary: JCLiteral for char must contain an Integer, not the provided Character. Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java
langtools/test/tools/javac/tree/MakeLiteralTest.java
--- a/langtools/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Tue Dec 17 10:55:59 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Tue Dec 17 10:58:21 2013 +0100
@@ -757,7 +757,7 @@
                 setType(syms.byteType.constType(value));
         } else if (value instanceof Character) {
             int v = (int) (((Character) value).toString().charAt(0));
-            result = Literal(CHAR, value).
+            result = Literal(CHAR, v).
                 setType(syms.charType.constType(v));
         } else if (value instanceof Double) {
             result = Literal(DOUBLE, value).
--- a/langtools/test/tools/javac/tree/MakeLiteralTest.java	Tue Dec 17 10:55:59 2013 +0100
+++ b/langtools/test/tools/javac/tree/MakeLiteralTest.java	Tue Dec 17 10:58:21 2013 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, 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
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 6504896
+ * @bug 6504896 8028415
  * @summary TreeMaker.Literal(Object) does not support Booleans
  */
 
@@ -76,6 +76,12 @@
                     + l.type.constValue().getClass() + " " + l.type.constValue()
                     + ": expected:" + constValue.getClass() + " " + constValue);
         }
+        if (l.getValue().getClass() != value.getClass()
+                || !value.equals(l.getValue()))  {
+            error("unexpected const value: "
+                    + l.getValue().getClass() + " " + l.type.constValue()
+                    + ": expected:" + value.getClass() + " " + value);
+        }
     }
 
     void error(String msg) {