albertogoffi / toradocu

Toradocu - automated generation of test oracles from Javadoc documentation
Other
42 stars 21 forks source link

NullPointerException at JavaElementsCollector #51

Closed khaeghar closed 7 years ago

khaeghar commented 7 years ago

NullPointerException at JavaElementsCollector

What was the expected outcome

Given the arguments for toradocu

--source-dir /home/sergio/Repositories/toradocu-dev/src/test/resources/src/guava-19.0-sources/  \
--class-dir /home/sergio/Repositories/toradocu-dev/bin/guava-19.0.jar \
--oracle-generation false \
--condition-translator-output /home/sergio/Toradocu/Ordering.json \
--debug

The expected outcome was the .json file with the analysis for that class.

What happened instead

Toradocu broke at JavaElementsCollector with the following output

Exception in thread "main" java.lang.NullPointerException
at org.toradocu.translator.JavaElementsCollector.collect(JavaElementsCollector.java:35)
at org.toradocu.translator.Matcher.subjectMatch(Matcher.java:36)
at org.toradocu.translator.ConditionTranslator.translatePropositions(ConditionTranslator.java:203)
at org.toradocu.translator.ConditionTranslator.processTag(ConditionTranslator.java:410)
at org.toradocu.translator.ConditionTranslator.translate(ConditionTranslator.java:37)
at org.toradocu.Toradocu.main(Toradocu.java:142)

What to do to reproduce the error

Have the toradocu repository up to date, then, execute toradocu at the class Ordering.java, from the Guava library, at com/common/collect/, as specified here:

--source-dir /home/sergio/Repositories/toradocu-dev/src/test/resources/src/guava-19.0-sources/  \
--class-dir /home/sergio/Repositories/toradocu-dev/bin/guava-19.0.jar \
--oracle-generation false \
--condition-translator-output /home/sergio/Toradocu/Ordering.json \
--debug

Change the route as needed.

albertogoffi commented 7 years ago

I investigated a bit the problem. The method org.toradocu.DocumentedMethod#getExecutable fails to load the proper Java (reflection) method corresponding to a DocumentedMethod. To understand which Java method correspond to a DocumentedMethod, Toradocu checks the equality of the methods names and parameters types (the signatures).

This procedure fails when a method is a generic method, using generic type arguments, for example, <E extends T> foo(E arg0, E arg1). In this case, the type for a generic argument in DocumentedMethod is E, while the type of the arguments loaded through reflection is java.lang.Object. This difference prevents the correct identification of a Java method as the corresponding method of a DocumentedMethod.