0

I have created a Maven project in Intellij IDEA to illustrate the issue; the code seeks to use the extCos scanner classes to find all classes implementing an interface.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>TestComponentScanner</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>net.sf.extcos</groupId>
            <artifactId>extcos</artifactId>
            <version>0.4b</version>
            <exclusions>
                <exclusion>
                    <groupId>org.ow2.asm</groupId>
                    <artifactId>asm-all</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
            <version>9.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.36</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.7.36</version>
        </dependency>
    </dependencies>
</project>

The ExampleComponentScanner class

package com.example;

import java.util.HashSet;
import java.util.Set;
import net.sf.extcos.ComponentQuery;
import net.sf.extcos.ComponentScanner;

public class ExampleComponentScanner {
    public Set<Class<?>> getImplementingClasses(){
    Set<Class<?>> classes = new HashSet<Class<?>>();

    ComponentScanner scanner = new ComponentScanner();
        Set<Class<?>> finalClasses = classes;
        classes = scanner.getClasses(new ComponentQuery() {
        @Override
        protected void query() {
            select().
                    from("com.example").
                    returning(allImplementing(ExampleInterface.class));
        }
    });
    return classes;
    }

    public static void main(String[] args){
        ExampleComponentScanner exConScan = new ExampleComponentScanner();
        Set<Class<?>> setClasses = exConScan.getImplementingClasses();
        for (Class exIntCl:setClasses) {
            System.out.println(exIntCl.getName());
            System.out.println(", ");
        }
    }
}

ExampleInterface

package com.example;

public interface ExampleInterface {
    public default String getInterfaceName(){
        return null;
    }
}

The implementing class

package com.example;

public class ExampleImplementer001 implements ExampleInterface{
}

This project runs as expected when built using JDK 1.8. It builds successfully with JDK 11 and JDK 17 as well, but when the ExampleComponentScanner class built with either of the newer Java versions (11 and 17) is executed, it throws the following exception:

C:\JDK\BellSoft\LibericaJDK-17-Full\bin\java.exe "-javaagent:C:\IntelliJ IDEA Community Edition 2020.3.3\lib\idea_rt.jar=64764:C:\IntelliJ IDEA Community Edition 2020.3.3\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\absoluteBeginner\IdeaProjects\TestComponentScanner\target\classes;C:\Users\absoluteBeginner\.m2\repository\net\sf\extcos\extcos\0.4b\extcos-0.4b.jar;C:\Users\absoluteBeginner\.m2\repository\org\ow2\asm\asm\5.0\asm-5.0.jar;C:\Users\absoluteBeginner\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\absoluteBeginner\.m2\repository\org\slf4j\slf4j-jdk14\1.7.36\slf4j-jdk14-1.7.36.jar com.example.ExampleComponentScanner
Exception in thread "eXtcos managed thread 1" java.lang.IllegalArgumentException
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at net.sf.extcos.internal.JavaResourceAccessor.readClassData(JavaResourceAccessor.java:362)
    at net.sf.extcos.internal.JavaResourceAccessor.setResourceUrl(JavaResourceAccessor.java:333)
    at net.sf.extcos.internal.URLResource.getResourceAccessor(URLResource.java:93)
    at net.sf.extcos.internal.URLResource.isClass(URLResource.java:126)
    at net.sf.extcos.internal.RootFilter.filter(RootFilter.java:22)
    at net.sf.extcos.internal.AbstractChainedFilter.filter(AbstractChainedFilter.java:89)
    at net.sf.extcos.internal.ThreadingFilterInterceptor$1.run(ThreadingFilterInterceptor.java:48)
    at java.base/java.lang.Thread.run(Thread.java:833)

I am using Bellsoft's Liberica JDK since I also need to integrate some JavaFX code.

Stefan Zobel
  • 3,182
  • 7
  • 28
  • 38
  • 3
    First I would hardly reconsider using of a lib which is of [2012 net.sf.extcos](https://search.maven.org/search?q=net.sf.extcos) and seemed to be abandoned ? Furthermore if you really exclude the asm-all dependency than you should add the same artifact instead of a different one in a newer version. Apart from that. I would expect that something like could really work...And the question is if such functionaltiy is worth using such an ancient old lib...? – khmarbaise Mar 06 '22 at 12:27
  • 1
    There are other ways to find classes that implement an interface; see https://stackoverflow.com/questions/347248 for some of them. – Stephen C Mar 08 '22 at 10:50
  • 1
    `C:\Users\absoluteBeginner\.m2\repository\org\ow2\asm\asm\5.0\asm-5.0.jar` - From the pom I infer that you want to use ASM 9.2. You use ASM 5.0. Which may fail with an IllegalArgumentException if you pass a newer ASM version as the first constructor parameter. – Johannes Kuhn Mar 08 '22 at 11:16

0 Answers0