Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6410297

JSR 199: javax.tools.SimpleJavaFileObject.isNameCompatible doesn't work or has wrong spec

XMLWordPrintable

    • b81
    • generic
    • generic

      isNameCompatible doesn't work or has wrong spec.

      -------------------
      import javax.tools.*;
      import java.net.URI;

      public class Test {

          public static void main( String[] args ){

              URI uri = URI.create("file:///path/file.claSS");
              SimpleJavaFileObject fo =
                  new SimpleJavaFileObject( uri, JavaFileObject.Kind.CLASS) {};

              boolean rc;
              /* This implementation compares <!!the path of its URI!!> to the given simple name */
              String simpleName = uri.getPath();
              rc = fo.isNameCompatible( simpleName, JavaFileObject.Kind.CLASS );
              System.out.println( String.format( "SJFO('%s', %s).isNameCompatible('%s') = %s. Spec says it have to be true",
                                      fo.toUri(), fo.getKind(), simpleName, rc ) );

              simpleName = "file";
              rc = fo.isNameCompatible( simpleName, JavaFileObject.Kind.CLASS );
              System.out.println( String.format( "SJFO('%s', %s).isNameCompatible('%s') = %s. Spec says it have to be false",
                                      fo.toUri(), fo.getKind(), simpleName, rc ) );


              fo = new SimpleJavaFileObject( URI.create( "file:///file.class" ), JavaFileObject.Kind.CLASS) {};
              simpleName = "file";
              rc = fo.isNameCompatible( simpleName, JavaFileObject.Kind.CLASS );
              System.out.println( String.format( "SJFO('%s', %s).isNameCompatible('%s') = %s. Spec says it have to be false",
                                      fo.toUri(), fo.getKind(), simpleName, rc ) );
          }
      }
      -------------------
      output:
      SJFO('file:///path/file.claSS&#39;, CLASS).isNameCompatible('/path/file.claSS') = false. Spec says it have to be true
      SJFO('file:///path/file.claSS&#39;, CLASS).isNameCompatible('file') = false. Spec says it have to be false
      SJFO('file:///file.class&#39;, CLASS).isNameCompatible('file') = true. Spec says it have to be false

            ahe Peter Ahe
            itseytin Igor Tseytin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: