<s> package org . eclipse . jdt . internal . core ; import org . eclipse . core . runtime . preferences . IEclipsePreferences ; import org . eclipse . core . runtime . preferences . InstanceScope ; import org . eclipse . core . runtime . preferences . PreferenceModifyListener ; import org . eclipse . jdt . core . * ; import org . osgi . service . prefs . BackingStoreException ; import org . osgi . service . prefs . Preferences ; public class JavaCorePreferenceModifyListener extends PreferenceModifyListener { static int PREFIX_LENGTH = JavaModelManager . CP_CONTAINER_PREFERENCES_PREFIX . length ( ) ; JavaModel javaModel = JavaModelManager . getJavaModelManager ( ) . getJavaModel ( ) ; public IEclipsePreferences preApply ( IEclipsePreferences node ) { Preferences instance = node . node ( InstanceScope . SCOPE ) ; cleanJavaCore ( instance . node ( JavaCore . PLUGIN_ID ) ) ; return super . preApply ( node ) ; } void cleanJavaCore ( Preferences preferences ) { try { String [ ] keys = preferences . keys ( ) ; for ( int k = 0 , kl = keys . length ; k < kl ; k ++ ) { String key = keys [ k ] ; if ( key . startsWith ( JavaModelManager . CP_CONTAINER_PREFERENCES_PREFIX ) && ! isJavaProjectAccessible ( key ) ) { preferences . remove ( key ) ; } } } catch ( BackingStoreException e ) { } } boolean isJavaProjectAccessible ( String propertyName ) { int index = propertyName . indexOf ( '|' , PREFIX_LENGTH ) ; if ( index > 0 ) { final String projectName = propertyName . substring ( PREFIX_LENGTH , index ) . trim ( ) ; JavaProject project = ( JavaProject ) this . javaModel . getJavaProject ( projectName ) ; if ( project . getProject ( ) . isAccessible ( ) ) { return true ; } } return false ; } } </s>