Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Found bug in JUnitEntryPoints #1373

Closed
gustaavv opened this issue Mar 9, 2024 · 4 comments · Fixed by #1398
Closed

Found bug in JUnitEntryPoints #1373

gustaavv opened this issue Mar 9, 2024 · 4 comments · Fixed by #1398

Comments

@gustaavv
Copy link

gustaavv commented Mar 9, 2024

When using junit4 annotations, the static method make(IClassHierarchy cha) can not return any entrypoint.

I found that isTestEntryPoint(TypeName typeName) might be wrong:

  private static boolean isTestEntryPoint(TypeName typeName) {
    // WALA uses $ to refers to inner classes. We have to replace "$" by "."
    // to make it a valid class name in Java source code.
    String javaName =
        StringStuff.jvmToReadableType(typeName.getPackage() + "." + typeName.getClassName());

    return TEST_ENTRY_POINT_ANNOTATION_NAMES.contains(javaName);
  }

For the class Lorg/abc/Main, typeName.getPackage() will return org.abc and delete the starting L. While jvmToReadableType depends on this L to parse the className. Without the starting L, jvmToReadableType will return an empty string.

So, I changed the method to the following:

    private static boolean isTestEntryPoint(TypeName typeName) {
        // WALA uses $ to refers to inner classes. We have to replace "$" by "."
        // to make it a valid class name in Java source code.
        String javaName = StringStuff.jvmToReadableType(
                typeName.toString().replace('$', '.'));

        return TEST_ENTRY_POINT_ANNOTATION_NAMES.contains(javaName);
    }

And it works.

Note that in my case, I have no inner classes to test. So I just changed the code by the comment.

@msridhar
Copy link
Member

msridhar commented Mar 9, 2024

Thanks for the report @el-nino2020! Could you submit a pull request with your fix? That would be great.

@gustaavv
Copy link
Author

gustaavv commented Mar 10, 2024

In fact, I just copied the source code of JUnitEntryPoints to my project and did the modification above, and it is sufficient for my use. I have not been looking into how to contributing to this project (nor do I have a good knowledge of WALA). Without testing, I think it is imporper to submit a PR. So I made an issue instead of a PR.

@khatchad
Copy link
Contributor

When using junit4 annotations, the static method make(IClassHierarchy cha) can not return any entrypoint.

I found that isTestEntryPoint(TypeName typeName) might be wrong:

  private static boolean isTestEntryPoint(TypeName typeName) {
    // WALA uses $ to refers to inner classes. We have to replace "$" by "."
    // to make it a valid class name in Java source code.
    String javaName =
        StringStuff.jvmToReadableType(typeName.getPackage() + "." + typeName.getClassName());

    return TEST_ENTRY_POINT_ANNOTATION_NAMES.contains(javaName);
  }

For the class Lorg/abc/Main, typeName.getPackage() will return org.abc and delete the starting L.

Hm. I don't see where that is removed. I see it added here:

if (!isPrimitive) {
result.append('L');

@khatchad
Copy link
Contributor

Ah, but that's in toString(). If the problem is from getPackage(), the package comes from the constructor and can be any atom.

I guess different representations may not be prefixed with L.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants