[NEW BUG] jdk.internal.module.Checks seems to miss a check for 'var'
Christoph Dreis
christoph.dreis at freenet.de
Fri Mar 22 16:06:49 UTC 2019
For completeness reasons, here is the corrected version of the complete patch I'm proposing.
============= PATCH =============
diff -r 96c45aa61056 src/java.base/share/classes/jdk/internal/module/Checks.java
--- a/src/java.base/share/classes/jdk/internal/module/Checks.java Fri Mar 22 13:42:45 2019 +0530
+++ b/src/java.base/share/classes/jdk/internal/module/Checks.java Fri Mar 22 17:04:38 2019 +0100
@@ -111,6 +111,11 @@
if (name.indexOf('.') == -1)
throw new IllegalArgumentException(name + ": is not a qualified name of"
+ " a Java class in a named package");
+ String unqualifiedName = getUnqualifiedClassName(name);
+ if ("var".equals(unqualifiedName)) {
+ throw new IllegalArgumentException(name + ": Invalid " + what
+ + ": 'var' is not a valid Java class name");
+ }
return name;
}
@@ -118,7 +123,19 @@
* Returns {@code true} if the given name is a legal class name.
*/
public static boolean isClassName(String name) {
- return isTypeName(name);
+ if (!isTypeName(name)) {
+ return false;
+ }
+ String unqualifiedName = getUnqualifiedClassName(name);
+ return !"var".equals(unqualifiedName);
+ }
+
+ /**
+ * Returns the unqualified name of the given class name.
+ */
+ private static String getUnqualifiedClassName(String name) {
+ int index = name.lastIndexOf('.');
+ return index != -1 ? name.substring(index + 1) : name;
}
> I'm sorry. Another correction.
>
> >
> > I wonder if this should do the trick.
> >
> > What do you think, Alan?
> >
> > ============ PATCH ============
> > diff -r 96c45aa61056
> > src/java.base/share/classes/jdk/internal/module/Checks.java
> > --- a/src/java.base/share/classes/jdk/internal/module/Checks.java Fri
> > Mar 22 13:42:45 2019 +0530
> > +++ b/src/java.base/share/classes/jdk/internal/module/Checks.java Fri
> > Mar 22 14:30:03 2019 +0100
> > @@ -111,6 +111,11 @@
> > if (name.indexOf('.') == -1)
> > throw new IllegalArgumentException(name + ": is not a
> > qualified name of"
> > + " a Java class in a
> > named package");
> > + String unqualifiedName = getUnqualifiedClassName(name);
> > + if (!"var".equals(unqualifiedName)) {
> > + throw new IllegalArgumentException(name + ": Invalid " + what
> > + + ": 'var' is not a valid Java class name");
> > + }
> > return name;
> > }
> >
>
> Today is not my day. This needs to be of course if
> ("var".equals(unqualifiedName)).
>
> Cheers,
> Christoph
More information about the core-libs-dev
mailing list