View | Details | Raw Unified | Return to bug 302850 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (-20 lines)
Lines 2922-2934 Link Here
2922
		return org.eclipse.jdt.core.tests.util.Util.toString(strings, false/*don't add extra new line*/);
2922
		return org.eclipse.jdt.core.tests.util.Util.toString(strings, false/*don't add extra new line*/);
2923
	}
2923
	}
2924
	protected void tearDown() throws Exception {
2924
	protected void tearDown() throws Exception {
2925
		if (JavaModelManager.DEBUG_302850) {
2926
			System.out.println("	- Options before tear down:");
2927
			System.out.println("		+ Task tags:           " + JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
2928
			System.out.println("		+ Task priorities:     " + JavaCore.getOption(JavaCore.COMPILER_TASK_PRIORITIES));
2929
			System.out.println("		+ Forbidden reference: " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
2930
			System.out.println(org.eclipse.jdt.core.tests.util.Util.indentString(new CompilerOptions(JavaCore.getOptions()).toString(), 2));
2931
		}
2932
2925
2933
		super.tearDown();
2926
		super.tearDown();
2934
		if (this.workingCopies != null) {
2927
		if (this.workingCopies != null) {
Lines 2937-2953 Link Here
2937
		}
2930
		}
2938
		this.wcOwner = null;
2931
		this.wcOwner = null;
2939
2932
2940
		if (JavaModelManager.DEBUG_302850) {
2941
			System.out.println("	- Options before comparison with defaults:");
2942
			System.out.println("		+ Task tags:           " + JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
2943
			System.out.println("		+ Task priorities:     " + JavaCore.getOption(JavaCore.COMPILER_TASK_PRIORITIES));
2944
			System.out.println("		+ Forbidden reference: " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
2945
			System.out.println(org.eclipse.jdt.core.tests.util.Util.indentString(new CompilerOptions(JavaCore.getOptions()).toString(), 2));
2946
			System.out.println("	- Default Options before comparison:");
2947
			System.out.println(org.eclipse.jdt.core.tests.util.Util.indentString(new CompilerOptions(JavaCore.getDefaultOptions()).toString(), 2));
2948
			System.out.println("================================================================================");
2949
		}
2950
2951
		// ensure workspace options have been restored to their default
2933
		// ensure workspace options have been restored to their default
2952
		Hashtable options = JavaCore.getOptions();
2934
		Hashtable options = JavaCore.getOptions();
2953
		Hashtable defaultOptions = JavaCore.getDefaultOptions();
2935
		Hashtable defaultOptions = JavaCore.getDefaultOptions();
Lines 2955-2962 Link Here
2955
			"Workspace options should be back to their default",
2937
			"Workspace options should be back to their default",
2956
			new CompilerOptions(defaultOptions).toString(),
2938
			new CompilerOptions(defaultOptions).toString(),
2957
			new CompilerOptions(options).toString());
2939
			new CompilerOptions(options).toString());
2958
		
2959
		JavaModelManager.DEBUG_302850 = false;
2960
	}
2940
	}
2961
2941
2962
	/**
2942
	/**
(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (-52 / +16 lines)
Lines 69-75 Link Here
69
import org.eclipse.jdt.core.search.TypeReferenceMatch;
69
import org.eclipse.jdt.core.search.TypeReferenceMatch;
70
import org.eclipse.jdt.core.tests.util.Util;
70
import org.eclipse.jdt.core.tests.util.Util;
71
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
71
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
72
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
73
import org.eclipse.jdt.internal.core.ClassFile;
72
import org.eclipse.jdt.internal.core.ClassFile;
74
import org.eclipse.jdt.internal.core.JavaModelManager;
73
import org.eclipse.jdt.internal.core.JavaModelManager;
75
import org.eclipse.jdt.internal.core.SourceMethod;
74
import org.eclipse.jdt.internal.core.SourceMethod;
Lines 11581-11589 Link Here
11581
 */
11580
 */
11582
public void testBug286379c() throws CoreException {
11581
public void testBug286379c() throws CoreException {
11583
	class TestResourceChangeListener implements IResourceChangeListener {
11582
	class TestResourceChangeListener implements IResourceChangeListener {
11584
		boolean valid = false;
11583
		boolean toRemPresent = false;
11585
		public void resourceChanged(IResourceChangeEvent event) {
11584
		public void resourceChanged(IResourceChangeEvent event) {
11586
			this.valid = validate(event.getDelta());
11585
			this.toRemPresent = validate(event.getDelta());
11587
		}
11586
		}
11588
		/*
11587
		/*
11589
		 * Ensure that the listener receives a delta concerning the resource
11588
		 * Ensure that the listener receives a delta concerning the resource
Lines 11606-11622 Link Here
11606
	        return false;
11605
	        return false;
11607
        }
11606
        }
11608
	}
11607
	}
11609
	// print statement to debug random failures of this test
11610
	JavaModelManager.DEBUG_302850 = true;
11611
	System.out.println("================================================================================");
11612
	System.out.println("Starting test JavaSearchBugTests.testBug286379c()...");
11613
	System.out.println("	- Default Options at test start:");
11614
	System.out.println(Util.indentString(new CompilerOptions(JavaCore.getDefaultOptions()).toString(), 1));
11615
	System.out.println("	- Options at test start:");
11616
	System.out.println("		+ Task tags:           " + JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
11617
	System.out.println("		+ Task priorities:     " + JavaCore.getOption(JavaCore.COMPILER_TASK_PRIORITIES));
11618
	System.out.println("		+ Forbidden reference: " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
11619
	System.out.println(Util.indentString(new CompilerOptions(JavaCore.getOptions()).toString(), 2));
11620
	
11608
	
11621
	IContentType javaContentType = Platform.getContentTypeManager().getContentType(JavaCore.JAVA_SOURCE_CONTENT_TYPE);
11609
	IContentType javaContentType = Platform.getContentTypeManager().getContentType(JavaCore.JAVA_SOURCE_CONTENT_TYPE);
11622
	TestResourceChangeListener changeListener = new TestResourceChangeListener();
11610
	TestResourceChangeListener changeListener = new TestResourceChangeListener();
Lines 11646-11652 Link Here
11646
		// fail as we don't get any specific event from the platform to refresh the indexes.
11634
		// fail as we don't get any specific event from the platform to refresh the indexes.
11647
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=118619
11635
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=118619
11648
		int counter = 0;
11636
		int counter = 0;
11649
		while (!changeListener.valid) {
11637
		while (!changeListener.toRemPresent) {
11650
			try {
11638
			try {
11651
				Thread.sleep(100);
11639
				Thread.sleep(100);
11652
			}
11640
			}
Lines 11659-11679 Link Here
11659
		// Wait to be sure that indexes are ready after the new resource was added
11647
		// Wait to be sure that indexes are ready after the new resource was added
11660
		waitUntilIndexesReady();
11648
		waitUntilIndexesReady();
11661
11649
11662
		// print statement to debug random failures of this test
11663
		System.out.println("	- Options before first exit:");
11664
		System.out.println("		+ Task tags:           " + JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
11665
		System.out.println("		+ Task priorities:     " + JavaCore.getOption(JavaCore.COMPILER_TASK_PRIORITIES));
11666
		System.out.println("		+ Forbidden reference: " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
11667
		System.out.println(Util.indentString(new CompilerOptions(JavaCore.getOptions()).toString(), 2));
11668
		// Restart to let the indexes to be refreshed
11650
		// Restart to let the indexes to be refreshed
11669
		simulateExit();
11651
		simulateExit();
11670
		simulateRestart();
11652
		simulateRestart();
11671
		// print statement to debug random failures of this test
11672
		System.out.println("	- Options after first restart:");
11673
		System.out.println("		+ Task tags:           " + JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
11674
		System.out.println("		+ Task priorities:     " + JavaCore.getOption(JavaCore.COMPILER_TASK_PRIORITIES));
11675
		System.out.println("		+ Forbidden reference: " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
11676
		System.out.println(Util.indentString(new CompilerOptions(JavaCore.getOptions()).toString(), 2));
11677
		waitUntilIndexesReady();
11653
		waitUntilIndexesReady();
11678
11654
11679
		// Search for the new type with new extension
11655
		// Search for the new type with new extension
Lines 11691-11712 Link Here
11691
				false /*only assume*/);
11667
				false /*only assume*/);
11692
		
11668
		
11693
		// Delete the file specification
11669
		// Delete the file specification
11670
		changeListener.toRemPresent = true;
11694
		javaContentType.removeFileSpec("torem", IContentType.FILE_EXTENSION_SPEC);
11671
		javaContentType.removeFileSpec("torem", IContentType.FILE_EXTENSION_SPEC);
11672
		counter = 0;
11673
		while (changeListener.toRemPresent) {
11674
			try {
11675
				Thread.sleep(100);
11676
			}
11677
			catch (InterruptedException ie) {
11678
				// skip
11679
			}
11680
			assertTrue("We should have got a resource event within a 10s delay!", counter++ < 100);
11681
		}
11682
		waitUntilIndexesReady();
11695
		
11683
		
11696
		// print statement to debug random failures of this test
11697
		System.out.println("	- Options before second exit:");
11698
		System.out.println("		+ Task tags:           " + JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
11699
		System.out.println("		+ Task priorities:     " + JavaCore.getOption(JavaCore.COMPILER_TASK_PRIORITIES));
11700
		System.out.println("		+ Forbidden reference: " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
11701
		System.out.println(Util.indentString(new CompilerOptions(JavaCore.getOptions()).toString(), 2));
11702
		// Restarting should update the index file to remove the references of any .torem files
11684
		// Restarting should update the index file to remove the references of any .torem files
11703
		simulateExit();
11685
		simulateExit();
11704
		simulateRestart();	
11686
		simulateRestart();
11705
		// print statement to debug random failures of this test
11706
		System.out.println("	- Options after second restart:");
11707
		System.out.println("		+ Task tags:           " + JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
11708
		System.out.println("		+ Task priorities:     " + JavaCore.getOption(JavaCore.COMPILER_TASK_PRIORITIES));
11709
		System.out.println("		+ Forbidden reference: " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
11710
		waitUntilIndexesReady();
11687
		waitUntilIndexesReady();
11711
11688
11712
		// Search for the new type with new extension
11689
		// Search for the new type with new extension
Lines 11719-11742 Link Here
11719
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
11696
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
11720
				null);
11697
				null);
11721
		assertSearchResults("No search results expected", "", collector);
11698
		assertSearchResults("No search results expected", "", collector);
11722
		System.out.println("	- Options after search:");
11723
		System.out.println("		+ Task tags:           " + JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
11724
		System.out.println("		+ Task priorities:     " + JavaCore.getOption(JavaCore.COMPILER_TASK_PRIORITIES));
11725
		System.out.println("		+ Forbidden reference: " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
11726
		System.out.println(Util.indentString(new CompilerOptions(JavaCore.getOptions()).toString(), 2));
11727
	} finally {
11699
	} finally {
11728
		getWorkspace().removeResourceChangeListener(changeListener);
11700
		getWorkspace().removeResourceChangeListener(changeListener);
11729
		if (javaContentType != null)
11701
		if (javaContentType != null)
11730
			javaContentType.removeFileSpec("torem", IContentType.FILE_EXTENSION_SPEC);
11702
			javaContentType.removeFileSpec("torem", IContentType.FILE_EXTENSION_SPEC);
11731
		deleteProject("P");
11703
		deleteProject("P");
11732
		System.out.println("	- Options at test end:");
11733
		System.out.println("		+ Task tags:           " + JavaCore.getOption(JavaCore.COMPILER_TASK_TAGS));
11734
		System.out.println("		+ Task priorities:     " + JavaCore.getOption(JavaCore.COMPILER_TASK_PRIORITIES));
11735
		System.out.println("		+ Forbidden reference: " + JavaCore.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE));
11736
		System.out.println(Util.indentString(new CompilerOptions(JavaCore.getOptions()).toString(), 2));
11737
		System.out.println("	- Default Options at test end:");
11738
		System.out.println(Util.indentString(new CompilerOptions(JavaCore.getDefaultOptions()).toString(), 2));
11739
		JavaModelManager.DEBUG_302850 = false;
11740
	}
11704
	}
11741
}
11705
}
11742
11706
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java (-74 / +39 lines)
Lines 1413-1421 Link Here
1413
	public static boolean CP_RESOLVE_VERBOSE_ADVANCED = false;
1413
	public static boolean CP_RESOLVE_VERBOSE_ADVANCED = false;
1414
	public static boolean CP_RESOLVE_VERBOSE_FAILURE = false;
1414
	public static boolean CP_RESOLVE_VERBOSE_FAILURE = false;
1415
	public static boolean ZIP_ACCESS_VERBOSE = false;
1415
	public static boolean ZIP_ACCESS_VERBOSE = false;
1416
	// temporary debug flag to track failures of bug 302850
1416
	
1417
	public static boolean DEBUG_302850 = false;
1418
1419
	/**
1417
	/**
1420
	 * A cache of opened zip files per thread.
1418
	 * A cache of opened zip files per thread.
1421
	 * (for a given thread, the object value is a HashMap from IPath to java.io.ZipFile)
1419
	 * (for a given thread, the object value is a HashMap from IPath to java.io.ZipFile)
Lines 2155-2167 Link Here
2155
		// return cached options if already computed
2153
		// return cached options if already computed
2156
		Hashtable cachedOptions; // use a local variable to avoid race condition (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=256329 )
2154
		Hashtable cachedOptions; // use a local variable to avoid race condition (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=256329 )
2157
		if ((cachedOptions = this.optionsCache) != null) {
2155
		if ((cachedOptions = this.optionsCache) != null) {
2158
			if (DEBUG_302850) checkTaskTags("Retrieving options from optionsCache", this.optionsCache); //$NON-NLS-1$
2159
			return new Hashtable(cachedOptions);
2156
			return new Hashtable(cachedOptions);
2160
		}
2157
		}
2161
		if (DEBUG_302850) System.out.println("optionsCache was null"); //$NON-NLS-1$
2162
		if (!Platform.isRunning()) {
2158
		if (!Platform.isRunning()) {
2163
			this.optionsCache = getDefaultOptionsNoInitialization();
2159
			this.optionsCache = getDefaultOptionsNoInitialization();
2164
			if (DEBUG_302850) checkTaskTags("Platform is not running", this.optionsCache); //$NON-NLS-1$
2165
			return new Hashtable(this.optionsCache);
2160
			return new Hashtable(this.optionsCache);
2166
		}
2161
		}
2167
		// init
2162
		// init
Lines 2177-2183 Link Here
2177
				options.put(propertyName, propertyValue);
2172
				options.put(propertyName, propertyValue);
2178
			}
2173
			}
2179
		}
2174
		}
2180
		if (DEBUG_302850) checkTaskTags("Options initialized from preferences", options); //$NON-NLS-1$
2181
2175
2182
		// set deprecated options using preferences service lookup
2176
		// set deprecated options using preferences service lookup
2183
		Iterator deprecatedEntries = this.deprecatedOptions.entrySet().iterator();
2177
		Iterator deprecatedEntries = this.deprecatedOptions.entrySet().iterator();
Lines 2203-2230 Link Here
2203
		addDeprecatedOptions(options);
2197
		addDeprecatedOptions(options);
2204
2198
2205
		Util.fixTaskTags(options);
2199
		Util.fixTaskTags(options);
2206
		if (DEBUG_302850) checkTaskTags("Retrieved options from preferences", options); //$NON-NLS-1$
2207
		// store built map in cache
2200
		// store built map in cache
2208
		this.optionsCache = new Hashtable(options);
2201
		this.optionsCache = new Hashtable(options);
2209
		if (DEBUG_302850) checkTaskTags("Stored optionsCache", this.optionsCache); //$NON-NLS-1$
2210
2211
		// return built map
2202
		// return built map
2212
		return options;
2203
		return options;
2213
	}
2214
2215
	// debugging bug 302850:
2216
	private void checkTaskTags(String msg, Hashtable someOptions) {
2217
		System.out.println(msg);
2218
		Object taskTags = someOptions.get(JavaCore.COMPILER_TASK_TAGS);
2219
		System.out.println("	+ Task tags:           " + taskTags); //$NON-NLS-1$
2220
		if (taskTags == null || "".equals(taskTags)) { //$NON-NLS-1$
2221
			System.out.println("	- option names: "+this.optionNames); //$NON-NLS-1$
2222
			System.out.println("	- Call stack:"); //$NON-NLS-1$
2223
			StackTraceElement[] elements = new Exception().getStackTrace();
2224
			for (int i=0,n=elements.length; i<n; i++) {
2225
				System.out.println("		+ "+elements[i]); //$NON-NLS-1$
2226
			}
2227
		}
2228
	}
2204
	}
2229
2205
2230
	// Do not modify without modifying getDefaultOptions()
2206
	// Do not modify without modifying getDefaultOptions()
Lines 4836-4892 Link Here
4836
	}
4812
	}
4837
4813
4838
	public void setOptions(Hashtable newOptions) {
4814
	public void setOptions(Hashtable newOptions) {
4839
		
4815
		Hashtable cachedValue = newOptions == null ? null : new Hashtable(newOptions);
4840
		if (DEBUG_302850) {
4816
		IEclipsePreferences defaultPreferences = getDefaultPreferences();
4841
			System.out.println("Entering in JavaModelManager.setOptions():"); //$NON-NLS-1$
4817
		IEclipsePreferences instancePreferences = getInstancePreferences();
4842
			System.out.println(new CompilerOptions(newOptions).toString());
4818
4843
			System.out.println("	- Call stack:"); //$NON-NLS-1$
4819
		if (newOptions == null){
4844
			StackTraceElement[] elements = new Exception().getStackTrace();
4820
			try {
4845
			for (int i=0,n=elements.length; i<n; i++) {
4821
				instancePreferences.clear();
4846
				System.out.println("		+ "+elements[i]); //$NON-NLS-1$
4822
			} catch(BackingStoreException e) {
4823
				// ignore
4824
			}
4825
		} else {
4826
			Enumeration keys = newOptions.keys();
4827
			while (keys.hasMoreElements()){
4828
				String key = (String)keys.nextElement();
4829
				int optionLevel = getOptionLevel(key);
4830
				if (optionLevel == UNKNOWN_OPTION) continue; // unrecognized option
4831
				if (key.equals(JavaCore.CORE_ENCODING)) {
4832
					if (cachedValue != null) {
4833
						cachedValue.put(key, JavaCore.getEncoding());
4834
					}
4835
					continue; // skipped, contributed by resource prefs
4836
				}
4837
				String value = (String) newOptions.get(key);
4838
				String defaultValue = defaultPreferences.get(key, null);
4839
				// Store value in preferences
4840
				if (defaultValue != null && defaultValue.equals(value)) {
4841
					value = null;
4842
				}
4843
				storePreference(key, value, instancePreferences, newOptions);
4844
			}
4845
			try {
4846
				// persist options
4847
				instancePreferences.flush();
4848
			} catch(BackingStoreException e) {
4849
				// ignore
4847
			}
4850
			}
4848
		}
4851
		}
4849
4852
		// update cache
4850
			Hashtable cachedValue = newOptions == null ? null : new Hashtable(newOptions);
4853
		Util.fixTaskTags(cachedValue);
4851
			IEclipsePreferences defaultPreferences = getDefaultPreferences();
4854
		this.optionsCache = cachedValue;
4852
			IEclipsePreferences instancePreferences = getInstancePreferences();
4853
4854
			if (newOptions == null){
4855
				try {
4856
					instancePreferences.clear();
4857
				} catch(BackingStoreException e) {
4858
					// ignore
4859
				}
4860
			} else {
4861
				Enumeration keys = newOptions.keys();
4862
				while (keys.hasMoreElements()){
4863
					String key = (String)keys.nextElement();
4864
					int optionLevel = getOptionLevel(key);
4865
					if (optionLevel == UNKNOWN_OPTION) continue; // unrecognized option
4866
					if (key.equals(JavaCore.CORE_ENCODING)) {
4867
						if (cachedValue != null) {
4868
							cachedValue.put(key, JavaCore.getEncoding());
4869
						}
4870
						continue; // skipped, contributed by resource prefs
4871
					}
4872
					String value = (String) newOptions.get(key);
4873
					String defaultValue = defaultPreferences.get(key, null);
4874
					// Store value in preferences
4875
					if (defaultValue != null && defaultValue.equals(value)) {
4876
						value = null;
4877
					}
4878
					storePreference(key, value, instancePreferences, newOptions);
4879
				}
4880
				try {
4881
					// persist options
4882
					instancePreferences.flush();
4883
				} catch(BackingStoreException e) {
4884
					// ignore
4885
				}
4886
			}
4887
			// update cache
4888
			Util.fixTaskTags(cachedValue);
4889
			this.optionsCache = cachedValue;
4890
	}
4855
	}
4891
4856
4892
	public void startup() throws CoreException {
4857
	public void startup() throws CoreException {

Return to bug 302850