@@ -341,7 +341,7 @@ public void setCache(IPath path, ZipFile zipFile) {
341
341
private final static int VALID_OPTION = 2 ;
342
342
HashSet <String > optionNames = new HashSet <>(20 );
343
343
Map <String , String []> deprecatedOptions = new HashMap <>();
344
- volatile Hashtable <String , String > optionsCache ;
344
+ private volatile Map <String , String > optionsCache ;
345
345
346
346
// Preferences
347
347
public final IEclipsePreferences [] preferencesLookup = new IEclipsePreferences [2 ];
@@ -1838,7 +1838,7 @@ private JavaModelManager() {
1838
1838
/**
1839
1839
* @deprecated
1840
1840
*/
1841
- private void addDeprecatedOptions (Hashtable <String , String > options ) {
1841
+ private void addDeprecatedOptions (Map <String , String > options ) {
1842
1842
options .put (JavaCore .COMPILER_PB_INVALID_IMPORT , JavaCore .ERROR );
1843
1843
options .put (JavaCore .COMPILER_PB_UNREACHABLE_CODE , JavaCore .ERROR );
1844
1844
}
@@ -2415,20 +2415,18 @@ public int getOptionLevel(String optionName) {
2415
2415
return UNKNOWN_OPTION ;
2416
2416
}
2417
2417
2418
- public Hashtable <String , String > getOptions () {
2419
-
2420
- // return cached options if already computed
2421
- Hashtable <String , String > cachedOptions ; // use a local variable to avoid race condition (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=256329 )
2422
- if ((cachedOptions = this .optionsCache ) != null ) {
2423
- return new Hashtable <>(cachedOptions );
2418
+ public Map <String , String > getOptions () {
2419
+ // use a local variable to avoid race condition (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=256329 )
2420
+ Map <String , String > cachedOptions = this .optionsCache ;
2421
+ if (cachedOptions != null ) {
2422
+ return cachedOptions ;
2424
2423
}
2424
+
2425
2425
if (!Platform .isRunning ()) {
2426
- Hashtable <String , String > defaults = getDefaultOptionsNoInitialization ();
2427
- this .optionsCache = defaults ;
2428
- return new Hashtable <>(defaults );
2426
+ return this .optionsCache = Map .copyOf (getDefaultOptionsNoInitialization ());
2429
2427
}
2430
2428
// init
2431
- Hashtable <String , String > options = new Hashtable <>(10 );
2429
+ Map <String , String > options = new HashMap <>(10 );
2432
2430
IPreferencesService service = Platform .getPreferencesService ();
2433
2431
2434
2432
for (String propertyName : this .optionNames ) {
@@ -2458,14 +2456,11 @@ public Hashtable<String, String> getOptions() {
2458
2456
addDeprecatedOptions (options );
2459
2457
2460
2458
Util .fixTaskTags (options );
2461
- // store built map in cache
2462
- this .optionsCache = new Hashtable <>(options );
2463
- // return built map
2464
- return options ;
2459
+ return this .optionsCache = Map .copyOf (options );
2465
2460
}
2466
2461
2467
2462
// Do not modify without modifying getDefaultOptions()
2468
- private Hashtable <String , String > getDefaultOptionsNoInitialization () {
2463
+ private Map <String , String > getDefaultOptionsNoInitialization () {
2469
2464
Map <String , String > defaultOptionsMap = new CompilerOptions ().getMap (); // compiler defaults
2470
2465
2471
2466
// Override some compiler defaults
@@ -2520,7 +2515,7 @@ private Hashtable<String, String> getDefaultOptionsNoInitialization() {
2520
2515
// Time out for parameter names
2521
2516
defaultOptionsMap .put (JavaCore .TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC , "50" ); //$NON-NLS-1$
2522
2517
2523
- return new Hashtable <>( defaultOptionsMap ) ;
2518
+ return defaultOptionsMap ;
2524
2519
}
2525
2520
2526
2521
/*
@@ -5321,30 +5316,30 @@ public boolean storePreference(String optionName, String optionValue, IEclipsePr
5321
5316
return true ;
5322
5317
}
5323
5318
5324
- public void setOptions (Hashtable <String , String > newOptions ) {
5319
+ public void setOptions (Map <String , String > newOptions ) {
5325
5320
Hashtable <String , String > cachedValue = newOptions == null ? null : new Hashtable <>(newOptions );
5326
5321
IEclipsePreferences defaultPreferences = getDefaultPreferences ();
5327
5322
IEclipsePreferences instancePreferences = getInstancePreferences ();
5328
5323
5329
- if (newOptions == null ){
5324
+ if (newOptions == null ) {
5330
5325
try {
5331
5326
instancePreferences .clear ();
5332
- } catch (BackingStoreException e ) {
5333
- // ignore
5327
+ } catch (BackingStoreException e ) {
5328
+ ILog . get (). log ( Status . warning ( "Error updating java options" , e )); //$NON-NLS-1$
5334
5329
}
5335
5330
} else {
5336
- Enumeration <String > keys = newOptions .keys ();
5337
- while (keys .hasMoreElements ()){
5338
- String key = keys .nextElement ();
5331
+ for (Entry <String , String > entry : newOptions .entrySet ()) {
5332
+ String key = entry .getKey ();
5339
5333
int optionLevel = getOptionLevel (key );
5340
- if (optionLevel == UNKNOWN_OPTION ) continue ; // unrecognized option
5334
+ if (optionLevel == UNKNOWN_OPTION )
5335
+ continue ; // unrecognized option
5341
5336
if (key .equals (JavaCore .CORE_ENCODING )) {
5342
5337
if (cachedValue != null ) {
5343
5338
cachedValue .put (key , JavaCore .getEncoding ());
5344
5339
}
5345
5340
continue ; // skipped, contributed by resource prefs
5346
5341
}
5347
- String value = newOptions . get ( key );
5342
+ String value = entry . getValue ( );
5348
5343
String defaultValue = defaultPreferences .get (key , null );
5349
5344
// Store value in preferences
5350
5345
if (defaultValue != null && defaultValue .equals (value )) {
@@ -5355,8 +5350,8 @@ public void setOptions(Hashtable<String, String> newOptions) {
5355
5350
try {
5356
5351
// persist options
5357
5352
instancePreferences .flush ();
5358
- } catch (BackingStoreException e ) {
5359
- // ignore
5353
+ } catch (BackingStoreException e ) {
5354
+ ILog . get (). log ( Status . warning ( "Error updating java options" , e )); //$NON-NLS-1$
5360
5355
}
5361
5356
}
5362
5357
if (cachedValue == null ) {
0 commit comments