--- old/test/langtools/tools/javac/processing/filer/TestPackageInfo.java 2018-07-17 07:25:42.222001000 -0700 +++ new/test/langtools/tools/javac/processing/filer/TestPackageInfo.java 2018-07-17 07:25:42.066001000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* * @test - * @bug 6380018 6392177 6993311 + * @bug 6380018 6392177 6993311 8193462 * @summary Test the ability to create and process package-info.java files * @author Joseph D. Darcy * @library /tools/javac/lib @@ -35,7 +35,6 @@ */ import java.util.Set; -import java.util.HashSet; import java.util.Map; import javax.annotation.processing.*; import javax.lang.model.SourceVersion; @@ -61,8 +60,8 @@ round++; // Verify annotations are as expected - Set expectedAnnotations = new HashSet(); - expectedAnnotations.add(eltUtils.getTypeElement("java.lang.Deprecated")); + Set expectedAnnotations = + Set.of(eltUtils.getTypeElement("java.lang.Deprecated")); if (!roundEnv.processingOver()) { System.out.println("\nRound " + round); @@ -91,11 +90,15 @@ throw new RuntimeException("Created class file for \"package-info\"."); } catch(FilerException fe) {} - PrintWriter pw = new PrintWriter(filer.createSourceFile("foo.package-info").openWriter()); - pw.println("@Deprecated"); - pw.println("package foo;"); - pw.close(); - + try(PrintWriter pw = + new PrintWriter(filer.createSourceFile("foo.package-info").openWriter())) { + pw.println("@Deprecated"); + pw.println("package foo;"); + } + + attemptReopening("foo.package-info"); + attemptReopening("TestPackageInfo"); // Initial input + attemptReopening("foo.bar.package-info"); // Initial input } catch(IOException ioe) { throw new RuntimeException(ioe); } @@ -103,9 +106,7 @@ case 2: // Expect foo.package-info - - Set expectedElement = new HashSet(); - expectedElement.add(eltUtils.getPackageElement("foo")); + Set expectedElement = Set.of(eltUtils.getPackageElement("foo")); if (!expectedElement.equals(roundEnv.getRootElements())) throw new RuntimeException("Unexpected root element set " + roundEnv.getRootElements()); @@ -113,6 +114,8 @@ throw new RuntimeException("Unexpected annotations: " + annotations); } + attemptReopening("foo.package-info"); + break; default: @@ -121,4 +124,26 @@ } return false; } + + private void attemptReopening(String name) { + final String SHOULD_NOT_REACH = "Should not reach: created "; + try { + try { + filer.createSourceFile(name); + throw new AssertionError(SHOULD_NOT_REACH + name + ".java"); + } catch (FilerException fe) { + ; // Expected + } + + try { + filer.createClassFile(name); + throw new AssertionError(SHOULD_NOT_REACH + name + ".class"); + } catch (FilerException fe) { + ; // Expected + } + } catch (IOException ioe) { + throw new RuntimeException(ioe); + } + + } }