Menu

#645 ClassPathScanningCandidateComponentProvider.findCandidateComponents doesn't find anly class

v5.3.3
open-works-for-me
None
5
2017-05-23
2017-05-19
JAgent_Team
No

Hi,

I am encountering a problem with my obfuscated code using Proguard v5.3.3.
I am using Java version 8 update 131.

Here is the problem: I am using spring-beans (v4.1.6) to find some classes as follows:

List<Class<T>> classes = new ArrayList<Class<T>>();
        ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
        scanner.addIncludeFilter(new AssignableTypeFilter(type));
        for (BeanDefinition bd : scanner.findCandidateComponents(pckg)) {
            try {
                Class<T> klass = (Class<T>) Class.forName(bd.getBeanClassName());
                classes.add(klass);
            } catch (ClassNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

        }

The problem is that scanner.findCandidateComponents(pckg) doesn't find any class (without obfuscation, it is ok). There is no exception.

Do you know what can be wrong ?

Thanks and regards

Discussion

  • Eric Lafortune

    Eric Lafortune - 2017-05-21

    The scanner uses reflection to find matching classes -- in this case all classes that extend some type. ProGuard doesn't realize this and probably removes these extensions in its shrinking step, if they seem unused. You therefore need to preserve them explicitly, with something like

    -keep,allowobfuscation class * extends com.example.MyType
    
     
  • Eric Lafortune

    Eric Lafortune - 2017-05-21
    • status: open --> open-works-for-me
    • assigned_to: Eric Lafortune
     
  • JAgent_Team

    JAgent_Team - 2017-05-23

    Hi,
    Thank you for your prompt reply.

    I tried that and, unfortunately, even if I could see that my classes were preserved, I still got the same issue.

    Interesting point to note, I could finally solve the issue by unzipping then rezipping the jar containing the classes to be found.

     

Log in to post a comment.