Bug 531717 - TypesImpl.erasure() should not throw CCE for NoType and
NullType

Change-Id: I15803f8171f60905b5b6affaefe341d383d34c7c
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
index fb1d9f4..1e01a67 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/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java
index 028b997..809ea6a 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java
@@ -42,6 +42,8 @@
 import javax.lang.model.type.ArrayType;
 import javax.lang.model.type.DeclaredType;
 import javax.lang.model.type.ExecutableType;
+import javax.lang.model.type.NoType;
+import javax.lang.model.type.NullType;
 import javax.lang.model.type.TypeKind;
 import javax.lang.model.type.TypeMirror;
 import javax.lang.model.util.ElementFilter;
@@ -1057,7 +1059,14 @@
 			assertEquals("Parameter type should be same", param.asType(), asType2);
 		}
 	}
-	
+	public void testBug531717() {
+		NoType noType = _typeUtils.getNoType(TypeKind.NONE);
+		TypeMirror erasure = _typeUtils.erasure(noType);
+		assertSame("NoType should be same", noType, erasure);
+		NullType nullType = _typeUtils.getNullType();
+		erasure = _typeUtils.erasure(nullType);
+		assertSame("NoType should be same", nullType, erasure);
+	}
 	private void createPackageBinary() throws IOException {
 		String path = packageName.replace('.', '/');
 		ClassLoader loader = getClass().getClassLoader();
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java
index f19a85c..a2beb52 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java
@@ -369,6 +369,10 @@
 		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
 		internalTestWithBinary(compiler, JAVA8_ANNOTATION_PROC, "testEnumConstArguments", null, "bug521812");
 	}
+	public void testBug531717() throws Exception {
+		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+		internalTestWithBinary(compiler, JAVA8_ANNOTATION_PROC, "testBug531717", null, "bug521812");
+	}
 	private void internalTest(JavaCompiler compiler, String processor, String testMethod) throws IOException {
 		internalTest(compiler, processor, testMethod, null);
 	}
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/NoTypeImpl.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/NoTypeImpl.java
index adc4932..6aac233 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/NoTypeImpl.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/model/NoTypeImpl.java
@@ -22,20 +22,39 @@
 import javax.lang.model.type.TypeKind;
 import javax.lang.model.type.TypeVisitor;
 
+import org.eclipse.jdt.internal.compiler.lookup.Binding;
+import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
+
 /**
  * An implementation of NoType, which is used to represent certain pseudo-types.
  * @see NoType
  */
-public class NoTypeImpl implements NoType, NullType
+public class NoTypeImpl extends TypeMirrorImpl implements NoType, NullType
 {
 	private final TypeKind _kind;
 	
 	public static final NoType NO_TYPE_NONE = new NoTypeImpl(TypeKind.NONE);
-	public static final NoType NO_TYPE_VOID = new NoTypeImpl(TypeKind.VOID);
+	public static final NoType NO_TYPE_VOID = new NoTypeImpl(TypeKind.VOID, TypeBinding.VOID);
 	public static final NoType NO_TYPE_PACKAGE = new NoTypeImpl(TypeKind.PACKAGE);
-	public static final NullType NULL_TYPE = new NoTypeImpl(TypeKind.NULL);
+	public static final NullType NULL_TYPE = new NoTypeImpl(TypeKind.NULL, TypeBinding.NULL);
+	public static final Binding NO_TYPE_BINDING = new Binding() {
+		@Override
+		public int kind() {
+			throw new IllegalStateException();
+		}
+	
+		@Override
+		public char[] readableName() {
+			throw new IllegalStateException();
+		}
+	};
 	
 	public NoTypeImpl(TypeKind kind) {
+		super(null, NO_TYPE_BINDING);
+		_kind = kind;
+	}
+	public NoTypeImpl(TypeKind kind, Binding binding) {
+		super(null, binding);
 		_kind = kind;
 	}