albertogoffi / toradocu

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

Toradocu fail due to multiple executable members found #233

Open ariannab opened 6 years ago

ariannab commented 6 years ago

On class org.apache.commons.math3.util.IterationManager, Toradocu fails and stop with the following error:

Exception in thread "main" java.lang.AssertionError: Found multiple reflection executable members corresponding to IterationManager(int, Incrementor.MaxCountExceededC$
[public org.apache.commons.math3.util.IterationManager(int,org.apache.commons.math3.util.Incrementor$MaxCountExceededCallback), public org.apache.commons.math3.util.I$
        at org.toradocu.extractor.JavadocExtractor.mapExecutables(JavadocExtractor.java:553)
        at org.toradocu.extractor.JavadocExtractor.extract(JavadocExtractor.java:87)
        at org.toradocu.Toradocu.main(Toradocu.java:93)

We could include this in the non-blocking errors that do not stop the Toradocu analysis - in this case, excluding the problematic method from the analysis.

albertogoffi commented 6 years ago

The issue is caused by the way the JavadocExtractor class heuristically matches parameter types in source code with parameter types loaded by reflection. In particular, the issue is the following: The Javadoc extractor needs to match the constructor in source code:

IterationManager(int, Incrementor.MaxCountExceededCallback)

with either one of the following constructors loaded with reflection:

IterationManager(int, org.apache.commons.math3.util.IntegerSequence$Incrementor$MaxCountExceededCallback)
IterationManager(int,org.apache.commons.math3.util.Incrementor$MaxCountExceededCallback)

The current heuristic selects both, while only the second one should be selected.

To properly fix this we should resolve source code types correctly, checking the import statements. Javaparser symbol solver could actually help us: https://github.com/javaparser/javasymbolsolver.

Test case to reproduce the problem:

@Test
public void issue233() {
  String[] toradocuArgs =
      new String[] {
          "--target-class",
          "org.apache.commons.math3.util.IterationManager",
          "--class-dir",
          "src/test/resources/bin/commons-math3-3.6.1.jar",
          "--source-dir",
          "src/test/resources/src/commons-math3-3.6.1-src/src/main/java",
          "--oracle-generation",
          "false",
          "--debug"
      };
  Toradocu.main(toradocuArgs);
}