Repository: morphiaorg/morphia
Issue: NullPointerException mapping class implementing an interface

Using Morphia 1.0.0-rc0:

Invoking Morphia.map() on a class which implements an interface produces a NullPointerException because:

in ReflectionUtils.getParameterizedClass:

```
public static Class getParameterizedClass(final Class c, final int index) {
    final TypeVariable[] typeVars = c.getTypeParameters();
    if (typeVars.length > 0) {
        final TypeVariable typeVariable = typeVars[index];
        final Type[] bounds = typeVariable.getBounds();

        final Type type = bounds[0];
        if (type instanceof Class) {
            return (Class) type; // broke for EnumSet, cause bounds contain
            // type instead of class
        } else {
            return null;
        }
    } else {
        final Type superclass = c.getGenericSuperclass();
        if (superclass instanceof ParameterizedType) {
            final Type[] actualTypeArguments = ((ParameterizedType) superclass).getActualTypeArguments();
            return actualTypeArguments.length > index ? (Class<?>) actualTypeArguments[index] : null;
        } else if (!Object.class.equals(superclass)) {
            return getParameterizedClass((Class) superclass);
        } else {
            return null;
        }
    }
}
```

This line: 

```
final Type superclass = c.getGenericSuperclass(); 
```

when executed on an interface results in superclass being null which causes a consequent invocation during execution of 

```
getParameterizedClass((Class) superclass) 
```

to fail with NPE.


Changed files:
morphia/src/test/java/org/mongodb/morphia/utils/ReflectionUtilsTest.java, morphia/src/main/java/org/mongodb/morphia/utils/ReflectionUtils.java

diff --git a/morphia/src/main/java/org/mongodb/morphia/utils/ReflectionUtils.java b/morphia/src/main/java/org/mongodb/morphia/utils/ReflectionUtils.java
index 4e92a715cae..e46147eb9c8 100644
--- a/morphia/src/main/java/org/mongodb/morphia/utils/ReflectionUtils.java
+++ b/morphia/src/main/java/org/mongodb/morphia/utils/ReflectionUtils.java
@@ -299,7 +299,13 @@ public final class ReflectionUtils {
                 return null;
             }
         } else {
-            final Type superclass = c.getGenericSuperclass();
+            Type superclass = c.getGenericSuperclass();
+            if (superclass == null && c.isInterface()) {
+                Type[] interfaces = c.getGenericInterfaces();
+                if (interfaces.length > 0) {
+                    superclass = interfaces[index];
+                }
+            }
             if (superclass instanceof ParameterizedType) {
                 final Type[] actualTypeArguments = ((ParameterizedType) superclass).getActualTypeArguments();
                 return actualTypeArguments.length > index ? (Class<?>) actualTypeArguments[index] : null;
diff --git a/morphia/src/test/java/org/mongodb/morphia/utils/ReflectionUtilsTest.java b/morphia/src/test/java/org/mongodb/morphia/utils/ReflectionUtilsTest.java
index e40035d842f..960abef4df2 100644
--- a/morphia/src/test/java/org/mongodb/morphia/utils/ReflectionUtilsTest.java
+++ b/morphia/src/test/java/org/mongodb/morphia/utils/ReflectionUtilsTest.java
@@ -1,6 +1,5 @@
 package org.mongodb.morphia.utils;
 
-import org.junit.Ignore;
 import org.junit.Test;
 import org.mongodb.morphia.TestBase;
 import org.mongodb.morphia.annotations.Entity;
@@ -16,6 +15,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import static org.hamcrest.CoreMatchers.isA;
@@ -31,9 +31,8 @@ import static org.mongodb.morphia.testutil.ExactClassMatcher.exactClass;
 public class ReflectionUtilsTest extends TestBase {
 
     @Test
-    @Ignore("Not implemented yet")
-    public void shouldAcceptInterfacesWithoutGenericParameters() {
-        Class parameterizedClass = ReflectionUtils.getParameterizedClass(InterfaceWithoutGenericTypes.class);
+    public void shouldAcceptMapWithoutItsOwnGenericParameters() {
+        Class parameterizedClass = ReflectionUtils.getParameterizedClass(MapWithoutGenericTypes.class);
 
         assertThat(parameterizedClass, is(exactClass(Integer.class)));
     }
@@ -107,7 +106,7 @@ public class ReflectionUtilsTest extends TestBase {
         assertThat(ReflectionUtils.getClassEntityAnnotation(Fooble.class).value(), is(Mapper.IGNORED_FIELDNAME));
     }
 
-    private interface InterfaceWithoutGenericTypes extends List<Integer> {
+    private interface MapWithoutGenericTypes extends Map<Integer, String> {
     }
 
     @Entity("generic_arrays")