JDK-6423181 : javax.lang.model.SourceVersion.is* methods should not be static
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.lang.model
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic,linux
  • CPU: generic,x86
  • Submitted: 2006-05-08
  • Updated: 2010-04-03
  • Resolved: 2006-08-10
Related Reports
Relates :  
Description
http://download.java.net/jdk6/docs/api/javax/lang/model/SourceVersion.html#isKeyword(java.lang.CharSequence)

says

"Returns whether or not s is a keyword or literal in the latest source version."

This method seems unreliable because it could change from release to release. E.g. in 1.3 this would return false for "assert" but true in 1.4+.

Comments
EVALUATION Having these particular methods be static is a reasonable design.
10-08-2006

EVALUATION Supporting per-version keywords would be simple, but identifiers would be problematic.
08-05-2006

SUGGESTED FIX Make the boolean is*(CharSequence) methods nonstatic. The current if (SourceVersion.isKeyword(n)) ... could simply be rewritten as if (SourceVersion.latest().isKeyword(n)) ... which is not much longer and is more explicit about its meaning. Code which knew it was dealing with older source code could use the correct instance. For example, consider a tool which knows it is working with -source 1.2 code and which can generate a new method with a suggested name: String n = ...; SourceVersion curr = SourceVersion.RELEASE_2; if (curr.isKeyword(n)) { error("cannot use name " + n + ", it is a keyword"); } else if (!curr.isName(n)) { error("not a valid name: " + n); } else { if (SourceVersion.latest().isKeyword(n)) { warn("name will be a keyword in a future release: " + n); // but continue... } makeMethod(n); } *** (#1 of 1): [ UNSAVED ] ###@###.###
08-05-2006