jglick commented on code in PR #5739:
URL: https://github.com/apache/netbeans/pull/5739#discussion_r1152133487
##########
java/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java:
##########
@@ -628,7 +630,9 @@ private static FileObject findSourceForBinary(FileObject
binaryRoot, FileObject
private static FileObject findMatchingChild(String sourceFileName,
Collection<FileObject> folders, boolean caseSensitive) {
final Match matchSet = caseSensitive ? new
CaseSensitiveMatch(sourceFileName) : new CaseInsensitiveMatch(sourceFileName);
for (FileObject folder : folders) {
- for (FileObject child : folder.getChildren()) {
+ FileObject[] children = folder.getChildren();
+ Arrays.sort(children,
Comparator.comparing(FileObject::getNameExt)); // for determinism
Review Comment:
Otherwise test may randomly pass or fail depending on filesystem iteration
order. Would not affect production use since a `*-sources.jar` would return
elements in ZIP order (typically folders first).
##########
java/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java:
##########
@@ -684,6 +688,9 @@ private abstract static class Match {
}
final boolean apply(final FileObject fo) {
+ if (fo.isFolder()) {
+ return false;
Review Comment:
The key fix.
##########
java/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java:
##########
@@ -1127,9 +1134,8 @@ private static boolean isCaseSensitive () {
}
/**
- * Returns candidate filenames given a classname. The return value is
either
- * a String (top-level class, no $) or List<String> as the JLS permits
$ in
- * class names.
+ * Returns candidate filenames given a classname.
+ * @return a single name (top-level class, no $) or multiple as the JLS
permits $ in class names.
Review Comment:
#5152 made this method type-safe but neglected to adjust the Javadoc
accordingly.
##########
java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTest.java:
##########
@@ -337,16 +338,16 @@ public void testGetFile () throws Exception {
ElementHandle<? extends Element> handle =
ElementHandle.createTypeElementHandle(ElementKind.CLASS, "org.me.Test");
assertNotNull (handle);
FileObject result = SourceUtils.getFile(handle, cpInfo);
- assertNotNull(result);
+ assertEquals(sourceFile, result);
Review Comment:
Existing test was too weakâtolerated any result, even completely wrong.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists