Bug 57113 - ImportHandler not returning class properly from resolveClass()
ImportHandler not returning class properly from resolveClass()
Status: RESOLVED FIXED
Product: Tomcat 8
Classification: Unclassified
Component: EL
8.0.x-trunk
PC All
: P2 normal (vote)
: ----
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2014-10-18 07:52 UTC by Arthur Fiedler
Modified: 2014-10-21 19:26 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arthur Fiedler 2014-10-18 07:52:40 UTC
Typically the importHandler.resolveClass(String) function is used something like...
  result = ctx.getImportHandler().resolveClass("MyClass");
  if (result != null)
    return result;

However the current functionality will fail (before classes are cached) if MyClass is in package "com.test" and "org.apache" is imported after com.test is... eg.

ctx.getImportHandler().importPackage("com.test");
ctx.getImportHandler().importPackage("org.apache");

Object result = ctx.getImportHandler().resolveClass("MyClass");

At this point result is null the first time ran through, because resolveClass loops through all packages finding the className in each package before it returns the temp variable its been using... which when it comes to org.apache.MyClass it will be null, when com.test.MyClass was actually found... but method returns null. 

I would think the expected result should be to return the first matching class. To continue its current logic for multi match detection, it can be modified to save the first match and return that variable... Like so.


public java.lang.Class<?> resolveClass(String name) {
    Class<?> result = clazzes.get(name);

    if (result == null) {
        // Search the package imports - note there may be multiple matches
        // (which correctly triggers an error)
        for (String p : packages) {
            String className = p + '.' + name;
            Class<?> tmpClass = findClass(className, true);
            if (result == null && tmpClass != null) {
                result = tmpClass;
            } 
        }
    }

    return result;
}
Comment 1 Mark Thomas 2014-10-21 19:26:29 UTC
Thanks for the report. This has been fixed in 8.0.x for 8.0.15 onwards.