From ce18e4d9dc56d7e5049918d5a4f9853c479e84f1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Oct 2025 09:16:00 +0000 Subject: [PATCH 1/3] Initial plan From 700eed6fbdb460e6f56ac94048963206303f6638 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Oct 2025 09:22:49 +0000 Subject: [PATCH 2/3] Fix IllegalArgumentException with duplicate natures Changed ProjectDescription.hasPrivateChanges() to use HashSet instead of Set.of() to handle duplicate natures gracefully. Set.of() throws IllegalArgumentException on duplicates, but HashSet tolerates them and correctly compares nature sets. Also added test case testDuplicateNatures() to ensure this regression doesn't occur again. Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com> --- .../resources/ProjectDescription.java | 3 ++- .../core/tests/resources/NatureTest.java | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectDescription.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectDescription.java index 5a1b5d02f6c..69c5e408513 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectDescription.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ProjectDescription.java @@ -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; @@ -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? diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java index c5483cd4bc9..b3b84369a5d 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java @@ -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 (validation will catch it later) + IProjectDescription desc = project.getDescription(); + desc.setNatureIds(new String[] { NATURE_SIMPLE, NATURE_SIMPLE }); + // This should not throw IllegalArgumentException + project.setDescription(desc, IResource.KEEP_HISTORY, createTestMonitor()); + + // The duplicate nature should have been detected by validation and only one instance should remain + assertHasEnabledNature(NATURE_SIMPLE); + } + @Test public void testNatureLifecyle() throws Throwable { createInWorkspace(project); From 44c2b9eaeae7761049ac6097e1bdec71c7f058d0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Oct 2025 09:25:39 +0000 Subject: [PATCH 3/3] Refine test comment for duplicate natures test Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com> --- .../src/org/eclipse/core/tests/resources/NatureTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java index b3b84369a5d..d4c82a80eae 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/NatureTest.java @@ -181,13 +181,13 @@ public void testDuplicateNatures() throws Throwable { assertHasEnabledNature(NATURE_SIMPLE); // Try to set natures with a duplicate - this should not throw IllegalArgumentException - // The duplicate should be handled gracefully (validation will catch it later) + // 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 + // This should not throw IllegalArgumentException when hasPrivateChanges is called project.setDescription(desc, IResource.KEEP_HISTORY, createTestMonitor()); - // The duplicate nature should have been detected by validation and only one instance should remain + // After deduplication, only one instance of the nature should remain assertHasEnabledNature(NATURE_SIMPLE); }