Skip to content

Commit 192a97a

Browse files
Copilotlaeubi
andcommitted
Address code review feedback: improve null handling and test assertions
Co-authored-by: laeubi <[email protected]>
1 parent 40b599d commit 192a97a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectNestingCache.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ private List<IProject> computeAncestorProjects(IProject project, Workspace works
7979
}
8080

8181
IPath ancestorLocation = potentialAncestor.getLocation();
82-
if (ancestorLocation != null && ancestorLocation.isPrefixOf(projectLocation)) {
82+
// Skip projects with null locations - they cannot be ancestors
83+
if (ancestorLocation == null) {
84+
continue;
85+
}
86+
87+
if (ancestorLocation.isPrefixOf(projectLocation)) {
8388
ancestors.add(potentialAncestor);
8489
}
8590
}
@@ -88,9 +93,16 @@ private List<IProject> computeAncestorProjects(IProject project, Workspace works
8893
ancestors.sort((p1, p2) -> {
8994
IPath loc1 = p1.getLocation();
9095
IPath loc2 = p2.getLocation();
91-
if (loc1 == null || loc2 == null) {
96+
// At this point, locations should not be null (filtered above), but be defensive
97+
if (loc1 == null && loc2 == null) {
9298
return 0;
9399
}
100+
if (loc1 == null) {
101+
return 1; // null locations go to end
102+
}
103+
if (loc2 == null) {
104+
return -1; // null locations go to end
105+
}
94106
// Reverse order: longer paths (closer ancestors) come first
95107
return Integer.compare(loc2.segmentCount(), loc1.segmentCount());
96108
});

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/HierarchicalProjectPreferencesTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ public void testInheritanceDoesNotModifyFiles() throws Exception {
278278
assertEquals("Child should inherit from parent", valueParent, inheritedValue);
279279

280280
// Verify child preference file does not exist (not created by inheritance)
281-
assertEquals("Child should not have a preference file",
282-
false,
281+
assertFalse("Child should not have a preference file",
283282
projectChild.getFile(".settings/" + qualifier + ".prefs").exists());
284283
}
285284

0 commit comments

Comments
 (0)