6891079: Compiler allows invalid binary literals 0b and oBL
authorjjg
Tue, 13 Oct 2009 15:26:30 -0700
changeset 4072 70eaf9773f81
parent 4071 10c876d2de66
child 4073 9788f4549740
6891079: Compiler allows invalid binary literals 0b and oBL Reviewed-by: darcy
langtools/src/share/classes/com/sun/tools/javac/parser/Scanner.java
langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties
langtools/test/tools/javac/literals/T6891079.java
langtools/test/tools/javac/literals/T6891079.out
--- a/langtools/src/share/classes/com/sun/tools/javac/parser/Scanner.java	Tue Oct 13 14:02:53 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/Scanner.java	Tue Oct 13 15:26:30 2009 -0700
@@ -876,7 +876,11 @@
                         }
                         scanChar();
                         skipIllegalUnderscores();
-                        scanNumber(2);
+                        if (digit(2) < 0) {
+                            lexError("invalid.binary.number");
+                        } else {
+                            scanNumber(2);
+                        }
                     } else {
                         putChar('0');
                         if (ch == '_') {
--- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Oct 13 14:02:53 2009 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Oct 13 15:26:30 2009 -0700
@@ -252,6 +252,8 @@
     interface methods cannot have body
 compiler.err.invalid.annotation.member.type=\
     invalid type for annotation member
+compiler.err.invalid.binary.number=\
+    binary numbers must contain at least one binary digit
 compiler.err.invalid.hex.number=\
     hexadecimal numbers must contain at least one hexadecimal digit
 compiler.err.invalid.meth.decl.ret.type.req=\
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/literals/T6891079.java	Tue Oct 13 15:26:30 2009 -0700
@@ -0,0 +1,12 @@
+/* @test /nodynamiccopyright/
+ * @bug 6891079
+ * @summary Compiler allows invalid binary literals 0b and oBL
+ * @compile/fail/ref=T6891079.out -XDrawDiagnostics T6891079.java
+ */
+
+class Test {
+    int bi = 0B;
+    long bl = 0BL;
+    int xi = 0X;
+    long xl = 0XL;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/literals/T6891079.out	Tue Oct 13 15:26:30 2009 -0700
@@ -0,0 +1,7 @@
+T6891079.java:8:14: compiler.err.invalid.binary.number
+T6891079.java:9:15: compiler.err.invalid.binary.number
+T6891079.java:9:18: compiler.err.expected: token.identifier
+T6891079.java:10:14: compiler.err.invalid.hex.number
+T6891079.java:11:15: compiler.err.invalid.hex.number
+T6891079.java:11:18: compiler.err.expected: token.identifier
+6 errors