diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java index b5e7aec3dbf3..75375bd0c045 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java @@ -712,7 +712,7 @@ public Void visitClass(ClassTree node, Void p) { csym.members_field.remove(member); } } - if (errorClass || def.hasTag(JCTree.Tag.ERRONEOUS) || def.hasTag(JCTree.Tag.BLOCK)) { + if (errorClass || def.hasTag(JCTree.Tag.ERRONEOUS)) { clazz.defs = com.sun.tools.javac.util.List.filter(clazz.defs, def); } } diff --git a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java index 276c07fe4bc1..e3dfc1701d5e 100644 --- a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java +++ b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java @@ -1876,6 +1876,51 @@ public void testSuperCall() throws Exception { assertEquals(expected, file2Fixed); } + public void testStaticInit() throws Exception { + Map file2Fixed = new HashMap<>(); + VanillaCompileWorker.fixedListener = (file, cut) -> { + try { + FileObject source = URLMapper.findFileObject(file.toUri().toURL()); + file2Fixed.put(FileUtil.getRelativePath(getRoot(), source), cut.toString()); + } catch (MalformedURLException ex) { + throw new IllegalStateException(ex); + } + }; + ParsingOutput result = runIndexing(Arrays.asList(compileTuple("test/Test.java", + "package test;\n" + + "public class Test {\n" + + " static {\n" + + " System.err.println();\n" + + " }\n" + + "}\n")), + Arrays.asList()); + + assertFalse(result.lowMemory); + assertTrue(result.success); + + Set createdFiles = new HashSet(); + + for (File created : result.createdFiles) { + createdFiles.add(getWorkDir().toURI().relativize(created.toURI()).getPath()); + } + + assertEquals(new HashSet(Arrays.asList("cache/s1/java/15/classes/test/Test.sig")), + createdFiles); + Map expected = Collections.singletonMap("test/Test.java", + "package test;\n" + + "\n" + + "public class Test {\n" + + " \n" + + " public Test() {\n" + + " super();\n" + + " }\n" + + " static {\n" + + " System.err.println();\n" + + " }\n" + + "}"); + assertEquals(expected, file2Fixed); + } + public static void noop() {} @Override