8022161: javac Null Pointer Exception in Enter.visitTopLevel

Fri, 09 Aug 2013 15:01:33 -0700

author
ksrini
date
Fri, 09 Aug 2013 15:01:33 -0700
changeset 1941
d601238641e6
parent 1940
b8610a65fbf9
child 1942
0d9bc764cac7

8022161: javac Null Pointer Exception in Enter.visitTopLevel
Reviewed-by: jjg, vromero, jlahoda

src/share/classes/com/sun/tools/javac/comp/Enter.java file | annotate | diff | comparison | revisions
test/tools/javac/TestPkgInfo.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Enter.java	Thu Aug 08 11:49:16 2013 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java	Fri Aug 09 15:01:33 2013 -0700
     1.3 @@ -291,7 +291,7 @@
     1.4              if (tree.packageAnnotations.nonEmpty() || pkginfoOpt == PkgInfo.ALWAYS) {
     1.5                  if (isPkgInfo) {
     1.6                      addEnv = true;
     1.7 -                } else {
     1.8 +                } else if (tree.packageAnnotations.nonEmpty()){
     1.9                      log.error(tree.packageAnnotations.head.pos(),
    1.10                                "pkg.annotations.sb.in.package-info.java");
    1.11                  }
     2.1 --- a/test/tools/javac/TestPkgInfo.java	Thu Aug 08 11:49:16 2013 +0100
     2.2 +++ b/test/tools/javac/TestPkgInfo.java	Fri Aug 09 15:01:33 2013 -0700
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     2.6 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -23,8 +23,10 @@
    2.11  
    2.12  /*
    2.13   * @test
    2.14 - * @bug 6960424
    2.15 - * @summary new option -Xpkginfo for better control of when package-info.class is generated
    2.16 + * @bug 6960424 8022161
    2.17 + * @summary new option -Xpkginfo for better control of when package-info.class
    2.18 + *          is generated, also ensures no failures if package-info.java is
    2.19 + *          not available.
    2.20   */
    2.21  
    2.22  import java.io.*;
    2.23 @@ -43,8 +45,11 @@
    2.24      public static void main(String... args) throws Exception {
    2.25          new TestPkgInfo().run(args);
    2.26      }
    2.27 -
    2.28      public void run(String... args) throws Exception {
    2.29 +        testPositive();
    2.30 +        testNoExceptions();
    2.31 +    }
    2.32 +    public void testPositive(String... args) throws Exception {
    2.33          boolean[] booleanValues = { false, true };
    2.34          for (OptKind ok: OptKind.values()) {
    2.35              for (boolean sr: booleanValues) {
    2.36 @@ -65,6 +70,32 @@
    2.37              throw new Exception(errors + " errors occurred");
    2.38      }
    2.39  
    2.40 +    /** this should throw no exceptions **/
    2.41 +    void testNoExceptions() throws Exception {
    2.42 +        count++;
    2.43 +        System.err.println("Test " + count + ": ALWAYS nofile");
    2.44 +
    2.45 +        StringBuilder sb = new StringBuilder();
    2.46 +        sb.append("package test; class Hello{}");
    2.47 +
    2.48 +        // test specific tmp directory
    2.49 +        File tmpDir = new File("tmp.test" + count);
    2.50 +        File classesDir = new File(tmpDir, "classes");
    2.51 +        classesDir.mkdirs();
    2.52 +        File javafile = new File(new File(tmpDir, "src"), "Hello.java");
    2.53 +        writeFile(javafile, sb.toString());
    2.54 +        // build up list of options and files to be compiled
    2.55 +        List<String> opts = new ArrayList<>();
    2.56 +        List<File> files = new ArrayList<>();
    2.57 +
    2.58 +        opts.add("-d");
    2.59 +        opts.add(classesDir.getPath());
    2.60 +        opts.add("-Xpkginfo:always");
    2.61 +        files.add(javafile);
    2.62 +
    2.63 +        compile(opts, files);
    2.64 +    }
    2.65 +
    2.66      void test(OptKind ok, boolean sr, boolean cr, boolean rr) throws Exception {
    2.67          count++;
    2.68          System.err.println("Test " + count + ": ok:" + ok + " sr:" + sr + " cr:" + cr + " rr:" + rr);
    2.69 @@ -91,15 +122,15 @@
    2.70          writeFile(pkginfo_java, sb.toString());
    2.71  
    2.72          // build up list of options and files to be compiled
    2.73 -        List<String> opts = new ArrayList<String>();
    2.74 -        List<File> files = new ArrayList<File>();
    2.75 +        List<String> opts = new ArrayList<>();
    2.76 +        List<File> files = new ArrayList<>();
    2.77  
    2.78          opts.add("-d");
    2.79          opts.add(classesDir.getPath());
    2.80          if (ok.opt != null)
    2.81              opts.add(ok.opt);
    2.82          //opts.add("-verbose");
    2.83 -        files.add(pkginfo_java);
    2.84 +            files.add(pkginfo_java);
    2.85  
    2.86          compile(opts, files);
    2.87  
    2.88 @@ -134,7 +165,7 @@
    2.89      /** Compile files with options provided. */
    2.90      void compile(List<String> opts, List<File> files) throws Exception {
    2.91          System.err.println("javac: " + opts + " " + files);
    2.92 -        List<String> args = new ArrayList<String>();
    2.93 +        List<String> args = new ArrayList<>();
    2.94          args.addAll(opts);
    2.95          for (File f: files)
    2.96              args.add(f.getPath());

mercurial