### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v retrieving revision 1.468 diff -u -r1.468 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 28 Jul 2011 17:07:05 -0000 1.468 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 23 Aug 2011 16:07:30 -0000 @@ -10,6 +10,7 @@ * Theodora Yeung (tyeung@bea.com) - ensure that JarPackageFragmentRoot make it into cache * before its contents * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=102422) + * Stephan Herrmann - Contribution for Bug 346010 - [model] strange initialization dependency in OptionTests *******************************************************************************/ package org.eclipse.jdt.internal.core; @@ -4788,10 +4789,11 @@ * @param optionValue The value of the option. If null, then * the option will be removed from the preferences instead. * @param eclipsePreferences The eclipse preferences to be updated + * @param otherOptions more options being stored, used to avoid conflict between deprecated option and its compatible * @return true if the preferences have been changed, * false otherwise. */ - public boolean storePreference(String optionName, String optionValue, IEclipsePreferences eclipsePreferences) { + public boolean storePreference(String optionName, String optionValue, IEclipsePreferences eclipsePreferences, Map otherOptions) { int optionLevel = this.getOptionLevel(optionName); if (optionLevel == UNKNOWN_OPTION) return false; // unrecognized option @@ -4809,6 +4811,8 @@ eclipsePreferences.remove(optionName); // get rid off old preference String[] compatibleOptions = (String[]) this.deprecatedOptions.get(optionName); for (int co=0, length=compatibleOptions.length; co < length; co++) { + if (otherOptions != null && otherOptions.containsKey(compatibleOptions[co])) + continue; // don't overwrite explicit value of otherOptions at compatibleOptions[co] if (optionValue == null) { eclipsePreferences.remove(compatibleOptions[co]); } else { @@ -4862,7 +4866,7 @@ if (defaultValue != null && defaultValue.equals(value)) { value = null; } - storePreference(key, value, instancePreferences); + storePreference(key, value, instancePreferences, newOptions); } try { // persist options Index: model/org/eclipse/jdt/internal/core/JavaProject.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v retrieving revision 1.447 diff -u -r1.447 JavaProject.java --- model/org/eclipse/jdt/internal/core/JavaProject.java 10 May 2011 19:29:43 -0000 1.447 +++ model/org/eclipse/jdt/internal/core/JavaProject.java 23 Aug 2011 16:07:34 -0000 @@ -7,7 +7,9 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Stephan Herrmann - inconsistent initialization of classpath container backed by external class folder, see https://bugs.eclipse.org/320618 + * Stephan Herrmann - Contributions for + * Bug 320618 - inconsistent initialization of classpath container backed by external class folder + * Bug 346010 - [model] strange initialization dependency in OptionTests *******************************************************************************/ package org.eclipse.jdt.internal.core; @@ -2928,7 +2930,7 @@ public void setOption(String optionName, String optionValue) { // Store option value IEclipsePreferences projectPreferences = getEclipsePreferences(); - boolean modified = JavaModelManager.getJavaModelManager().storePreference(optionName, optionValue, projectPreferences); + boolean modified = JavaModelManager.getJavaModelManager().storePreference(optionName, optionValue, projectPreferences, null); // Write changes if (modified) { @@ -2957,7 +2959,7 @@ Map.Entry entry = (Map.Entry) entries.next(); String key = (String) entry.getKey(); String value = (String) entry.getValue(); - javaModelManager.storePreference(key, value, projectPreferences); + javaModelManager.storePreference(key, value, projectPreferences, newOptions); } // reset to default all options not in new map #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/OptionTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/OptionTests.java,v retrieving revision 1.32 diff -u -r1.32 OptionTests.java --- src/org/eclipse/jdt/core/tests/model/OptionTests.java 10 May 2011 19:30:30 -0000 1.32 +++ src/org/eclipse/jdt/core/tests/model/OptionTests.java 23 Aug 2011 16:07:37 -0000 @@ -7,11 +7,17 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for Bug 346010 - [model] strange initialization dependency in OptionTests *******************************************************************************/ package org.eclipse.jdt.core.tests.model; +import java.util.ArrayList; +import java.util.HashSet; import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.Set; import junit.framework.Test; @@ -43,6 +49,7 @@ super(name); } static { +// TESTS_NAMES = new String[] { "testBug346010" }; // TESTS_NUMBERS = new int[] { 125360 }; // TESTS_RANGE = new int[] { 4, -1 }; } @@ -758,6 +765,61 @@ } } /** + * @bug 346010 - [model] strange initialization dependency in OptionTests + * @test Verify that unfortunate order of map entries doesn't spoil intended semantics. + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=346010" + * @deprecated As using deprecated constants + */ +public void testBug346010() throws CoreException { + class ForcedOrderMap extends Hashtable { + private static final long serialVersionUID = 8012963985718522218L; + Map original; + Map.Entry additionalEntry; + /* Force (additionalKey,additionalValue) to be served after all entries of original. */ + public ForcedOrderMap(Map original, String additionalKey, String additionalValue) { + this.original = original; + // convert additionalKey->additionalValue to a Map.Entry without inserting into original: + Hashtable tmp = new Hashtable(); + tmp.put(additionalKey, additionalValue); + this.additionalEntry = (Map.Entry) tmp.entrySet().iterator().next(); + } + public Set entrySet() { + return new HashSet() { + private static final long serialVersionUID = 1L; + public Iterator iterator() { + List orderedEntries; + orderedEntries = new ArrayList(ForcedOrderMap.this.original.entrySet()); + orderedEntries.add(ForcedOrderMap.this.additionalEntry); + return orderedEntries.iterator(); + } + }; + } + public synchronized boolean containsKey(Object key) { + return this.original.containsKey(key) || key.equals(this.additionalEntry.getKey()); + } + } + try { + // Set the obsolete option using the IJavaProject API + JavaProject project = (JavaProject) createJavaProject("P"); + final String obsoleteOption = DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER; + Map testOptions = project.getOptions(true); + Map orderedOptions = new ForcedOrderMap(testOptions, obsoleteOption, JavaCore.DO_NOT_INSERT); + project.setOptions(orderedOptions); + // Verify that obsolete preference is not stored + assertNull( + "Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", + project.getEclipsePreferences().get(obsoleteOption, null)); + // Verify that project obsolete option is well retrieved + assertEquals( + "Unexpected value for formatter deprecated option 'org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member'", + JavaCore.INSERT, + project.getOption(obsoleteOption, true)); + } finally { + deleteProject("P"); + } +} + +/** * @bug 324987: [formatter] API compatibility problem with Annotation Newline options * @test Verify that a deprecated option is well preserved when read through * the IEclipsePreferences (i.e. simulate reading project preferences of a project