update jdt.core to I20220509-1800
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java
index 5bd523a..dd3103f 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java
@@ -1979,9 +1979,11 @@
 		"public class X {\n"+
 		"  public X() {\n"+
 		"  }\n"+
-		"  void foo() {\n"+
-		"    <SelectOnType:Object> s;\n" +
-		"  }\n"+
+		"  void foo() {\n" +
+		"    if ((x instanceof <SelectOnType:Object> s))\n" +
+		"        {\n" +
+		"        }\n" +
+		"  }\n" +
 		"}\n";
 	String expectedReplacedSource = "Object";
 	String testName = "<select inside instanceof statement>";
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
index fecb59e..1a1f179 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
@@ -20,6 +20,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
+import java.net.URI;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -600,6 +601,11 @@
 		description.setNatureIds(new String[] {JavaCore.NATURE_ID});
 		project.setDescription(description, null);
 	}
+	protected IProjectDescription projectDescriptionForLocation(String projectName, URI location) throws CoreException {
+		IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
+		desc.setLocationURI(location);
+		return desc;
+	}
 	protected void assertSearchResults(String expected, Object collector) {
 		assertSearchResults("Unexpected search results", expected, collector);
 	}
@@ -1794,6 +1800,7 @@
 		return
 				this.createJavaProject(
 					projectName,
+					null,
 					sourceFolders,
 					libraries,
 					null/*no inclusion pattern*/,
@@ -1969,6 +1976,7 @@
 			final boolean simulateImport) throws CoreException {
 		return createJavaProject(
 				projectName,
+				null,
 				sourceFolders,
 				libraries,
 				librariesInclusionPatterns,
@@ -1988,6 +1996,7 @@
 	}
 	protected IJavaProject createJavaProject(
 			final String projectName,
+			URI locationURI,
 			final String[] sourceFolders,
 			final String[] libraries,
 			final String[][] librariesInclusionPatterns,
@@ -2008,7 +2017,10 @@
 		IWorkspaceRunnable create = new IWorkspaceRunnable() {
 			public void run(IProgressMonitor monitor) throws CoreException {
 				// create project
-				createProject(projectName);
+				if (locationURI != null)
+					createExternalProject(projectName, locationURI);
+				else
+					createProject(projectName);
 
 				// set java nature
 				addJavaNature(projectName);
@@ -2337,6 +2349,17 @@
 		getWorkspace().run(create, null);
 		return project;
 	}
+	protected IProject createExternalProject(final String projectName, URI location) throws CoreException {
+		final IProject project = getProject(projectName);
+		IWorkspaceRunnable create = new IWorkspaceRunnable() {
+			public void run(IProgressMonitor monitor) throws CoreException {
+				project.create(projectDescriptionForLocation(projectName, location), null);
+				project.open(null);
+			}
+		};
+		getWorkspace().run(create, null);
+		return project;
+	}
 	public void createSourceZip(String[] pathsAndContents, String zipPath) throws IOException {
 		org.eclipse.jdt.core.tests.util.Util.createSourceZip(pathsAndContents, zipPath);
 	}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java
index e8b906b..2940db3 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalAnnotations18Test.java
@@ -17,6 +17,7 @@
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.IOException;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -3057,6 +3058,14 @@
 	}
 
 	public void testAnnotationsInProjectReferencedViaContainer() throws CoreException, IOException {
+		internalTestAnnotationsInProjectReferencedViaContainer(null);
+	}
+	public void testAnnotationsInExternalProjectReferencedViaContainer() throws CoreException, IOException {
+		URI parentLocation = getWorkspaceRoot().getLocation().toFile().getParentFile().toURI();
+		URI location = parentLocation.resolve(URI.create("external-project"));
+		internalTestAnnotationsInProjectReferencedViaContainer(location);
+	}
+	void internalTestAnnotationsInProjectReferencedViaContainer(URI location) throws CoreException, IOException {
 		// undeployed version of testSeparateAnnotationJarInContainer:
 		// container "resolved" the eea-artifact to a workspace project
 		myCreateJavaProject("PrjTest");
@@ -3069,8 +3078,13 @@
 				'/'+eeaProjectName, null,
 				fullPathToPrj1, null));
 
+		IJavaProject eeaProject = null;
 		try {
-			createJavaProject(eeaProjectName);
+			final String projectName = eeaProjectName;
+			eeaProject = createJavaProject(projectName, location,
+					new String[] {""}, new String[] {"JCL_LIB"},
+					null, null, null, null, null, true, null,
+					"", null, null, null, "", false, false);
 			createFolder('/'+eeaProjectName+"/lib/pgen");
 			createFolder('/'+eeaProjectName+"/lib/pgen2");
 			createFile(eeaProjectName+"/lib/pgen/CGen.eea",   mixedArtifacts_CGen_eea_content);
@@ -3101,6 +3115,8 @@
 			internalTestMixedArtifactsTest();
 		} finally {
 			ContainerInitializer.setInitializer(prev);
+			if (eeaProject.exists())
+				eeaProject.getProject().delete(true, null);
 		}
 	}
 
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java
index 9296681..43960cf 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java
@@ -40,6 +40,7 @@
 import org.eclipse.jdt.internal.compiler.ast.ForeachStatement;
 import org.eclipse.jdt.internal.compiler.ast.ImportReference;
 import org.eclipse.jdt.internal.compiler.ast.Initializer;
+import org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression;
 import org.eclipse.jdt.internal.compiler.ast.LambdaExpression;
 import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.MessageSend;
@@ -52,7 +53,6 @@
 import org.eclipse.jdt.internal.compiler.ast.Statement;
 import org.eclipse.jdt.internal.compiler.ast.SuperReference;
 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.TypePattern;
 import org.eclipse.jdt.internal.compiler.ast.TypeReference;
 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
 import org.eclipse.jdt.internal.compiler.lookup.Binding;
@@ -386,8 +386,9 @@
 		}
 	}
 	// This is  copy of the code that processes astStack early in this method
-	for (int i = 0; i <= this.patternPtr; i++, lastNode = node) {
-		node = this.patternStack[i];
+	for (int i = 0; i <= this.expressionPtr; i++, lastNode = node) {
+		node = this.expressionStack[i];
+		if (node == null || !(node instanceof InstanceOfExpression)) continue;
 		/* check for intermediate block creation, so recovery can properly close them afterwards */
 		int nodeStart = node.sourceStart;
 		for (int j = blockIndex; j <= this.realBlockPtr; j++){
@@ -413,12 +414,11 @@
 			blockIndex = j+1; // shift the index to the new block
 		}
 
-		if (node instanceof TypePattern){
-			TypePattern pattern = (TypePattern) node;
-			LocalDeclaration local = pattern.getPatternVariableIntroduced();
+		InstanceOfExpression pattern = (InstanceOfExpression) node;
+		LocalDeclaration local = pattern.elementVariable;
+		if (local != null)
 			element = element.add(local, 0);
-			continue;
-		}
+		continue;
 	}
 	if (this.currentToken == TokenNameRBRACE) {
 		 if (isIndirectlyInsideLambdaExpression())
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java
index b6f8f41..c7f58e7 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java
@@ -838,25 +838,6 @@
 protected void consumeInstanceOfExpression() {
 	if (indexOfAssistIdentifier() < 0) {
 		super.consumeInstanceOfExpression();
-		int length = this.expressionLengthPtr >= 0 ?
-				this.expressionLengthStack[this.expressionLengthPtr] : 0;
-		if (length > 0) {
-			Expression exp = this.expressionStack[this.expressionPtr];
-			LocalDeclaration local = null;
-			if (exp instanceof InstanceOfExpression) {
-				local = ((InstanceOfExpression) exp).elementVariable;
-			} else if (exp instanceof AND_AND_Expression) {
-				InstanceOfExpression insExpr = (InstanceOfExpression) ((AND_AND_Expression) exp).left;
-				local = insExpr.elementVariable;
-			}
-			if (local != null) {
-				pushOnAstStack(local);
-				if (!this.diet) {
-					this.restartRecovery	= true;
-					this.lastIgnoredToken = -1;
-				}
-			}
-		}
 	} else {
 		getTypeReference(this.intStack[this.intPtr--]);
 		this.isOrphanCompletionNode = true;
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java
index 8d4cdb8..1e59824 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java
@@ -1394,7 +1394,7 @@
 								if (tgtJProject.exists()) {
 									if (resolve) {
 										// resolve the project's output location:
-										return wsRoot.getLocation().append(tgtJProject.getOutputLocation());
+										return wsRoot.findMember(tgtJProject.getOutputLocation()).getLocation();
 									}
 									// in non-resolving scenarii return the unresolved source folder path
 									for (IClasspathEntry classpathEntry : tgtJProject.getRawClasspath()) {
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java
index ba02f41..af9af7c 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java
@@ -1955,7 +1955,10 @@
 		if (!JavaProject.hasJavaNature(this.project)) return null;
 		// Get cached preferences if exist
 		JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfo(this.project, true);
-		if (perProjectInfo.preferences != null) return perProjectInfo.preferences;
+		IEclipsePreferences preferences = perProjectInfo.preferences;
+		if (checkPreferencesExist(preferences)) {
+			return preferences;
+		}
 		// Init project preferences
 		IScopeContext context = new ProjectScope(getProject());
 		final IEclipsePreferences eclipsePreferences = context.getNode(JavaCore.PLUGIN_ID);
@@ -2043,6 +2046,23 @@
 		return eclipsePreferences;
 	}
 
+	private boolean checkPreferencesExist(IEclipsePreferences preferences) {
+		if (preferences == null) {
+			return false;
+		}
+		try {
+			// check the root node ("")
+			if (preferences.nodeExists("")) { //$NON-NLS-1$
+				return true;
+			}
+		} catch (BackingStoreException e1) {
+			// shouldn't happen, but if happens, we continue below
+		}
+		JavaModelManager manager = JavaModelManager.getJavaModelManager();
+		manager.resetProjectPreferences(this);
+		return false;
+	}
+
 	@Override
 	public String getElementName() {
 		return this.project.getName();
@@ -2193,7 +2213,17 @@
 	 */
 	@Override
 	public String getOption(String optionName, boolean inheritJavaCoreOptions) {
-		return JavaModelManager.getJavaModelManager().getOption(optionName, inheritJavaCoreOptions, getEclipsePreferences());
+		IEclipsePreferences preferences = getEclipsePreferences();
+		JavaModelManager manager = JavaModelManager.getJavaModelManager();
+		String option;
+		try {
+			option = manager.getOption(optionName, inheritJavaCoreOptions, preferences);
+		} catch (IllegalStateException e) {
+			// preferences deleted right after the check? let's retry once
+			preferences = getEclipsePreferences();
+			option = manager.getOption(optionName, inheritJavaCoreOptions, preferences);
+		}
+		return option;
 	}
 
 	/**