Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NETBEANS-7981] Handling Diagnostics with position -1 while writing error/warning index. #7983

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public <T> void dumpErrors(final URL root, final Indexable i, final Iterable<? e
}
});
} catch (IOException ex) {
Exceptions.attachMessage(ex, "can't dump errors for: " + String.valueOf(i));
Exceptions.printStackTrace(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1324,9 +1324,15 @@ public ErrorsCache.Range getRange(Diagnostic<?> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
*
Expand Down Expand Up @@ -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<String> createdFiles = new HashSet<String>();

for (File created : result.createdFiles) {
createdFiles.add(getWorkDir().toURI().relativize(created.toURI()).getPath());
}

assertEquals(new HashSet<String>(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<Integer, Integer>, Pair<Integer, Integer>> range) {}
List<Data> errors = TaskCache.getDefault().getErrors(getRoot().getFileObject("test/Test.java"), new ErrorsCache.ReverseConvertor<Data>() {
@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
Expand Down
Loading