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

com.sun.source.util.Trees.isAccessible incorrect

XMLWordPrintable

    • b120
    • x86
    • linux
    • Verified

      If c.s.s.u.Trees.isAccessible is called on a public innerclass, which is inside an inaccessible type, it returns true, although it should return false, in my opinion.

      I have revision 248 checked-out from https://openjdk.dev.java.net/svn/openjdk/jdk/trunk, but I have some problems with the checkout, so it is possible that I run tests against an older 1.7 build.
      I was not able to attach a test case, so placing it here:
      /*
       * @test @(#)T9999999.java 1.7 07/05/05
       * @bug 9999999
       * @summary Trees.isAccessible should return false for public innerclasses of non-accessible outer-classes
       */

      import com.sun.source.tree.CompilationUnitTree;
      import com.sun.source.tree.Scope;
      import com.sun.source.util.JavacTask;
      import com.sun.source.util.TreePath;
      import com.sun.source.util.Trees;
      import java.net.URI;
      import java.util.Arrays;
      import javax.lang.model.element.TypeElement;
      import javax.tools.JavaCompiler;
      import javax.tools.JavaFileObject;
      import javax.tools.SimpleJavaFileObject;
      import javax.tools.ToolProvider;

      public class T9999999 {
          public static void main(String[] args) throws Exception {
              final String bootPath = System.getProperty("sun.boot.class.path"); //NOI18N
              final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
              assert tool != null;
              final JavacTask ct = (JavacTask)tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath), null, Arrays.asList(new MyFileObject()));
              
              CompilationUnitTree cut = ct.parse().iterator().next();
              TreePath tp = new TreePath(new TreePath(cut), cut.getTypeDecls().get(0));
              Scope s = Trees.instance(ct).getScope(tp);
              TypeElement type = ct.getElements().getTypeElement("com.sun.java.util.jar.pack.Package.File");
              
              if (Trees.instance(ct).isAccessible(s, type)) {
                  //com.sun.java.util.jar.pack.Package.File is a public innerclass inside a non-accessible class, so
                  //"false" would be expected here.
                  throw new IllegalStateException("");
              }
          }

          static class MyFileObject extends SimpleJavaFileObject {
              public MyFileObject() {
                  super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
              }
              public CharSequence getCharContent(boolean ignoreEncodingErrors) {
                  return "public class Test<TTT> { public void test() {TTT ttt;}}";
              }
          }
      }

            mcimadamore Maurizio Cimadamore
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: