Skip to content

Commit

Permalink
FURNACE-59: Fixed NullPointerException in Annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jul 14, 2015
1 parent 7401f30 commit 6aca3c7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,30 +185,32 @@ private static <A extends Annotation> A getAnnotation(final Set<Annotation> seen
public static <A extends Annotation> A getAnnotation(final Class<?> c, final Class<A> type)
{
A result = null;
result = getAnnotationFromType(c, type);
if (result == null)
if (c != null)
{
Class<?> superclass = c.getSuperclass();
while (superclass != null)
result = getAnnotationFromType(c, type);
if (result == null)
{
result = getAnnotation(superclass, type);
if (result != null)
break;
superclass = superclass.getSuperclass();
Class<?> superclass = c.getSuperclass();
while (superclass != null)
{
result = getAnnotation(superclass, type);
if (result != null)
break;
superclass = superclass.getSuperclass();
}
}
}

if (result == null)
{
Class<?>[] interfaces = c.getInterfaces();
for (Class<?> i : interfaces)
if (result == null)
{
result = getAnnotation(i, type);
if (result != null)
break;
Class<?>[] interfaces = c.getInterfaces();
for (Class<?> i : interfaces)
{
result = getAnnotation(i, type);
if (result != null)
break;
}
}
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

public interface MockInterface
{
@MockAnnotation
@MockMethodAnnotation
public void method();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
*/
package org.jboss.forge.furnace.util;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;

import org.jboss.forge.furnace.mock.InheritsRemote;
import org.jboss.forge.furnace.mock.InheritsRemoteFromExtendedInterface;
import org.jboss.forge.furnace.mock.InheritsRemoteFromSuperClassInheriting;
import org.jboss.forge.furnace.mock.MockAnnotation;
import org.jboss.forge.furnace.mock.MockMethodAnnotation;
import org.jboss.forge.furnace.mock.SuperClassAnnotatedWithRemote;
import org.jboss.forge.furnace.mock.MockInterface;
import org.jboss.forge.furnace.mock.SuperClassAnnotatedWithRemote;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -23,12 +22,13 @@
*/
public class AnnotationsTest
{

@Test
public void testMethodAnnotation() throws Exception
{
MockMethodAnnotation annotation = Annotations.getAnnotation(MockInterface.class.getMethod("method"),
MockMethodAnnotation.class);
Assert.assertThat(annotation, notNullValue());
MockAnnotation annotation = Annotations.getAnnotation(MockInterface.class.getMethod("method"),
MockAnnotation.class);
Assert.assertThat(annotation, nullValue());
}

@Test
Expand Down

0 comments on commit 6aca3c7

Please sign in to comment.