diff --git a/ide/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java b/ide/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java index 08a415febd53..90442b05c2bc 100644 --- a/ide/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java +++ b/ide/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java @@ -229,6 +229,7 @@ public void dumpErrors(final URL root, final Indexable i, final Iterable t) { if (lm == null) { return new ErrorsCache.Range(new ErrorsCache.Position((int) t.getLineNumber(), (int) t.getColumnNumber()), null); } + ErrorsCache.Position endPos; + if (t.getEndPosition() == (-1)) { + endPos = null; + } else { + endPos = new ErrorsCache.Position((int) lm.getLineNumber(t.getEndPosition()), (int) lm.getColumnNumber(t.getEndPosition())); + } return new ErrorsCache.Range( new ErrorsCache.Position((int) lm.getLineNumber(t.getStartPosition()), (int) lm.getColumnNumber(t.getStartPosition())), - new ErrorsCache.Position((int) lm.getLineNumber(t.getEndPosition()), (int) lm.getColumnNumber(t.getEndPosition())) + endPos ); } @Override 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 bcd1c07c8701..482ddf14a061 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 @@ -27,6 +27,7 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; @@ -53,11 +54,16 @@ import org.netbeans.modules.classfile.ClassFile; import org.netbeans.modules.java.source.indexing.CompileWorker.ParsingOutput; import org.netbeans.modules.java.source.indexing.JavaCustomIndexer.CompileTuple; +import org.netbeans.modules.parsing.impl.indexing.errors.TaskCache; import org.netbeans.modules.parsing.spi.indexing.Context; +import org.netbeans.modules.parsing.spi.indexing.ErrorsCache; +import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.ErrorKind; +import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Range; import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; +import org.openide.util.Pair; /** * @@ -2431,6 +2437,54 @@ public void testRecord2() throws Exception { assertEquals(expected, file2Fixed); } + public void testBrokenWarningEndPos() throws Exception { //NETBEANS-7981 + setCompilerOptions(Arrays.asList("-Xlint:deprecation")); + + String code = """ + package test; + public class Test { + void t() { + new D() {}; + } + } + class D { + @Deprecated + D() {} + } + """; + ParsingOutput result = runIndexing(Arrays.asList(compileTuple("test/Test.java", + code)), + 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", + "cache/s1/java/15/classes/test/Test$1.sig", + "cache/s1/java/15/classes/test/D.sig")), + createdFiles); + record Data(ErrorKind kind, Pair, Pair> range) {} + List errors = TaskCache.getDefault().getErrors(getRoot().getFileObject("test/Test.java"), new ErrorsCache.ReverseConvertor() { + @Override + public Data get(ErrorKind kind, Range range, String message) { + return new Data(kind, Pair.of(Pair.of(range.getStart().getLine(), + range.getStart().getColumn()), + range.getEnd() != null ? Pair.of(range.getEnd().getLine(), + range.getEnd().getColumn()) + : null)); + } + }); + assertEquals(List.of(new Data(ErrorKind.WARNING, Pair.of(Pair.of(4, 9), Pair.of(4, 19))), + new Data(ErrorKind.WARNING, Pair.of(Pair.of(4, 17), null))), + errors); + } + public static void noop() {} @Override