Skip to content
Closed
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 @@ -24,6 +24,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -581,7 +582,7 @@ public boolean hasPrivateChanges(ProjectDescription description) {
return true;
}
// has natures changed?
if (!Set.of(natures).equals(Set.of(description.natures))) {
if (!new HashSet<>(Arrays.asList(natures)).equals(new HashSet<>(Arrays.asList(description.natures)))) {
return true;
}
// has buildspec changed?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,30 @@ public void testInvalidRemovals() throws Throwable {
assertHasEnabledNature(NATURE_SNOW);
}

/**
* Tests that duplicate natures in the project description don't cause
* IllegalArgumentException. This is a regression test for a bug where
* Set.of() was used which throws on duplicates.
*/
@Test
public void testDuplicateNatures() throws Throwable {
createInWorkspace(project);

// Set initial nature
setNatures(project, new String[] { NATURE_SIMPLE }, false);
assertHasEnabledNature(NATURE_SIMPLE);

// Try to set natures with a duplicate - this should not throw IllegalArgumentException
// The duplicate should be handled gracefully (deduplication happens automatically)
IProjectDescription desc = project.getDescription();
desc.setNatureIds(new String[] { NATURE_SIMPLE, NATURE_SIMPLE });
// This should not throw IllegalArgumentException when hasPrivateChanges is called
project.setDescription(desc, IResource.KEEP_HISTORY, createTestMonitor());

// After deduplication, only one instance of the nature should remain
assertHasEnabledNature(NATURE_SIMPLE);
}

@Test
public void testNatureLifecyle() throws Throwable {
createInWorkspace(project);
Expand Down
Loading