Bug 317216 - NPE in ParameterizedTypeBinding.readableName

Adding regression test
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
index 821e180..0246907 100644
--- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
index 177bbda..2c4c285 100644
--- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug317216Proc.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug317216Proc.java
new file mode 100644
index 0000000..9e23e07
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug317216Proc.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2016 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ *******************************************************************************/
+
+package org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests;
+
+import java.util.Set;
+
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.util.ElementFilter;
+
+import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor;
+
+/**
+ * A processor that should not be invoked. Reports an error if invoked.
+ */
+@SupportedAnnotationTypes({"targets.AnnotationProcessorTests.bug317216.Gen"})
+@SupportedSourceVersion(SourceVersion.RELEASE_6)
+public class Bug317216Proc extends BaseProcessor {
+
+	@Override
+	public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+		for (TypeElement typeElement : annotations) {
+			if (typeElement.getQualifiedName().toString().equals("targets.AnnotationProcessorTests.bug317216.Gen")) {
+					for (Element element : roundEnv.getElementsAnnotatedWith(typeElement)) {
+						if (element.getKind() == ElementKind.CLASS) {
+							printEntrySet((TypeElement) element);
+						}
+					}
+				}
+			}
+		return true;
+	}
+
+	public void printEntrySet(TypeElement element) {
+		ProcessingEnvironment pe = processingEnv;
+		for (ExecutableElement method : ElementFilter.methodsIn(pe.getElementUtils().getAllMembers(element))) {
+			if (!method.toString().contains("getFoo")) {
+				continue;
+			}
+			TypeElement element2 = (TypeElement) pe.getTypeUtils().asElement(method.getReturnType());
+			// element2 == java.util.Map
+			for (ExecutableElement method2 : ElementFilter.methodsIn(pe.getElementUtils().getAllMembers(element2))) {
+				if (method2.getSimpleName().toString().contains("entrySet")) {
+					TypeMirror s = method2.getReturnType();
+					DeclaredType st = (DeclaredType) s;
+
+					TypeMirror e = st.getTypeArguments().get(0);
+					DeclaredType de = (DeclaredType) e;
+					TypeMirror[] eargs = new TypeMirror[2];
+					eargs[0] = de.getTypeArguments().get(0);
+					eargs[1] = de.getTypeArguments().get(1);
+					TypeMirror e2 = pe.getTypeUtils().getDeclaredType((TypeElement) de.asElement(), eargs);
+					// e2.toString breaks without fix
+					e2.toString();
+					TypeMirror[] sargs = new TypeMirror[1];
+					sargs[0] = e2;
+
+					s = pe.getTypeUtils().getDeclaredType((TypeElement) st.asElement(), sargs);
+					s.toString();
+				}
+			}
+		}
+	}
+
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug317216/Foo.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug317216/Foo.java
new file mode 100644
index 0000000..abae723
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug317216/Foo.java
@@ -0,0 +1,9 @@
+package targets.AnnotationProcessorTests.bug317216;
+
+import java.util.Map;
+
+@Gen
+public class Foo {
+	 Map<String, String> getFoo() { return null; }
+}
+
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug317216/Gen.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug317216/Gen.java
new file mode 100644
index 0000000..63a07bb
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug317216/Gen.java
@@ -0,0 +1,4 @@
+package targets.AnnotationProcessorTests.bug317216;
+
+public @interface Gen {
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java
index f15338c..574420d 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java
@@ -41,6 +41,11 @@
 				count++;
 				buffer.append(diagnostic.getMessage(Locale.getDefault()));
 				buffer.append("\n");
+			} else if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
+				count++;
+				buffer.append(diagnostic.getMessage(Locale.getDefault()));
+				buffer.append("\n");
+				System.out.println(buffer.toString());
 			}
 		}
 		public Diagnostic<? extends S> getErrorAt(int index) {
@@ -140,4 +145,20 @@
 		options.add("-proc:only");
 		BatchTestUtils.compileTree(compiler, options, targetFolder, null);
 	}
+	public void testBug317216() throws IOException {
+		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+		File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "AnnotationProcessorTests", "bug317216");
+		BatchTestUtils.copyResources("targets/AnnotationProcessorTests/bug317216", targetFolder);
+		List<String> options = new ArrayList<String>();
+		final String PROC = "org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests.Bug317216Proc";
+		options.add("-processorpath");
+		options.add(" ");
+		options.add("-processor");
+		options.add(PROC);
+		DiagnosticReport<JavaFileObject> diagnosticListener = new DiagnosticReport<JavaFileObject>();
+		BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, diagnosticListener, true);
+		assertNull(System.getProperty(PROC));
+		assertEquals("incorrect number of messages", 0, diagnosticListener.count);
+		assertNull(System.getProperty(PROC));
+	}
 }