Skip to content

Commit 212f4c3

Browse files
authored
Merge pull request #7992 from apache/delivery
Sync delivery to release240 for 24-rc4
2 parents 0be8be2 + 0511bca commit 212f4c3

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

ide/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ public <T> void dumpErrors(final URL root, final Indexable i, final Iterable<? e
229229
}
230230
});
231231
} catch (IOException ex) {
232+
Exceptions.attachMessage(ex, "can't dump errors for: " + String.valueOf(i));
232233
Exceptions.printStackTrace(ex);
233234
}
234235
}

java/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,9 +1324,15 @@ public ErrorsCache.Range getRange(Diagnostic<?> t) {
13241324
if (lm == null) {
13251325
return new ErrorsCache.Range(new ErrorsCache.Position((int) t.getLineNumber(), (int) t.getColumnNumber()), null);
13261326
}
1327+
ErrorsCache.Position endPos;
1328+
if (t.getEndPosition() == (-1)) {
1329+
endPos = null;
1330+
} else {
1331+
endPos = new ErrorsCache.Position((int) lm.getLineNumber(t.getEndPosition()), (int) lm.getColumnNumber(t.getEndPosition()));
1332+
}
13271333
return new ErrorsCache.Range(
13281334
new ErrorsCache.Position((int) lm.getLineNumber(t.getStartPosition()), (int) lm.getColumnNumber(t.getStartPosition())),
1329-
new ErrorsCache.Position((int) lm.getLineNumber(t.getEndPosition()), (int) lm.getColumnNumber(t.getEndPosition()))
1335+
endPos
13301336
);
13311337
}
13321338
@Override

java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.EnumSet;
2828
import java.util.HashMap;
2929
import java.util.HashSet;
30+
import java.util.List;
3031
import java.util.Map;
3132
import java.util.Set;
3233
import java.util.concurrent.atomic.AtomicBoolean;
@@ -53,11 +54,16 @@
5354
import org.netbeans.modules.classfile.ClassFile;
5455
import org.netbeans.modules.java.source.indexing.CompileWorker.ParsingOutput;
5556
import org.netbeans.modules.java.source.indexing.JavaCustomIndexer.CompileTuple;
57+
import org.netbeans.modules.parsing.impl.indexing.errors.TaskCache;
5658
import org.netbeans.modules.parsing.spi.indexing.Context;
59+
import org.netbeans.modules.parsing.spi.indexing.ErrorsCache;
60+
import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.ErrorKind;
61+
import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Range;
5762
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
5863
import org.openide.filesystems.FileObject;
5964
import org.openide.filesystems.FileUtil;
6065
import org.openide.filesystems.URLMapper;
66+
import org.openide.util.Pair;
6167

6268
/**
6369
*
@@ -2431,6 +2437,54 @@ public void testRecord2() throws Exception {
24312437
assertEquals(expected, file2Fixed);
24322438
}
24332439

2440+
public void testBrokenWarningEndPos() throws Exception { //NETBEANS-7981
2441+
setCompilerOptions(Arrays.asList("-Xlint:deprecation"));
2442+
2443+
String code = """
2444+
package test;
2445+
public class Test {
2446+
void t() {
2447+
new D() {};
2448+
}
2449+
}
2450+
class D {
2451+
@Deprecated
2452+
D() {}
2453+
}
2454+
""";
2455+
ParsingOutput result = runIndexing(Arrays.asList(compileTuple("test/Test.java",
2456+
code)),
2457+
Arrays.asList());
2458+
2459+
assertFalse(result.lowMemory);
2460+
assertTrue(result.success);
2461+
2462+
Set<String> createdFiles = new HashSet<String>();
2463+
2464+
for (File created : result.createdFiles) {
2465+
createdFiles.add(getWorkDir().toURI().relativize(created.toURI()).getPath());
2466+
}
2467+
2468+
assertEquals(new HashSet<String>(Arrays.asList("cache/s1/java/15/classes/test/Test.sig",
2469+
"cache/s1/java/15/classes/test/Test$1.sig",
2470+
"cache/s1/java/15/classes/test/D.sig")),
2471+
createdFiles);
2472+
record Data(ErrorKind kind, Pair<Pair<Integer, Integer>, Pair<Integer, Integer>> range) {}
2473+
List<Data> errors = TaskCache.getDefault().getErrors(getRoot().getFileObject("test/Test.java"), new ErrorsCache.ReverseConvertor<Data>() {
2474+
@Override
2475+
public Data get(ErrorKind kind, Range range, String message) {
2476+
return new Data(kind, Pair.of(Pair.of(range.getStart().getLine(),
2477+
range.getStart().getColumn()),
2478+
range.getEnd() != null ? Pair.of(range.getEnd().getLine(),
2479+
range.getEnd().getColumn())
2480+
: null));
2481+
}
2482+
});
2483+
assertEquals(List.of(new Data(ErrorKind.WARNING, Pair.of(Pair.of(4, 9), Pair.of(4, 19))),
2484+
new Data(ErrorKind.WARNING, Pair.of(Pair.of(4, 17), null))),
2485+
errors);
2486+
}
2487+
24342488
public static void noop() {}
24352489

24362490
@Override

0 commit comments

Comments
 (0)