JPPF Issue Tracker
star_faded.png
Please log in to bookmark issues
bug_report_small.png
CLOSED  Bug report JPPF-203  -  Class loader resource cache generates duplicate resources
Posted Nov 27, 2013 - updated Nov 28, 2013
icon_info.png This issue has been closed with status "Closed" and resolution "RESOLVED".
Issue details
  • Type of issue
    Bug report
  • Status
     
    Closed
  • Assigned to
     lolo4j
  • Progress
       
  • Type of bug
    Not triaged
  • Likelihood
    Not triaged
  • Effect
    Not triaged
  • Posted by
     lolo4j
  • Owned by
    Not owned by anyone
  • Category
    Node
  • Resolution
    RESOLVED
  • Priority
    High
  • Reproducability
    Not determined
  • Severity
    Normal
  • Targetted for
    icon_milestones.png JPPF 3.3.7
Issue description
When multiple lookups are performed for a given resource name, for instance via AbstractJPPFClassLoader.getResources(some_name), a cache entry for that resource is created at each lookup. This causes duplicate entries and may cause conflicts with some frameworks like Hibernate, as reported in this forum thread.
Steps to reproduce this issue
The following task code:
public class ResourceLoadingTask extends JPPFTask {
  public static final String RES_NAME = "some_resource.txt";
 
  @Override
  public void run() {
    System.out.println("Starting the task");
    try {
      StringBuilder sb = new StringBuilder();
      for (int i=1; i<=3; i++) {
        sb.append("***** iteration ").append(i).append(" : ");
        sb.append(displayResourcePaths(getClass().getClassLoader(), RES_NAME));
      }
      setResult(sb.toString());
    } catch(Exception e) {
      setException(e);
      e.printStackTrace();
    } catch(Error e) {
      e.printStackTrace();
      setException(new JPPFException(e));
    }
  }
 
  public static String displayResourcePaths(final ClassLoader cl, final String name) {
    StringBuilder sb = new StringBuilder();
    try {
      Enumeration<URL> urls = cl.getResources(RES_NAME);
      if (urls == null) sb.append("lookup for '").append(RES_NAME).append("' returned null\n");
      else {
        sb.append("lookup results for '").append(RES_NAME).append("'\n");
        if (!urls.hasMoreElements()) sb.append("  not found in the classpath\n");
        else while (urls.hasMoreElements()) sb.append("  ").append(urls.nextElement()).append('\n');
      }
    } catch (IOException e) {
      e.printStackTrace();
      sb.append(ExceptionUtils.getStackTrace(e));
    }
    return sb.toString();
  }
}
results in the following display when printing the task result:
***** iteration 1 : lookup results for 'some_resource.txt'
  file:/C:/Users/lcohen/AppData/Local/Temp/.jppf/784aecb21875112b9fba367b84131b8a/some_resource.txt
***** iteration 2 : lookup results for 'some_resource.txt'
  file:/C:/Users/lcohen/AppData/Local/Temp/.jppf/784aecb21875112b9fba367b84131b8a/some_resource.txt
  file:/C:/Users/lcohen/AppData/Local/Temp/.jppf/784aecb21875112b9fba367b84131b8a_1/some_resource.txt
***** iteration 3 : lookup results for 'some_resource.txt'
  file:/C:/Users/lcohen/AppData/Local/Temp/.jppf/784aecb21875112b9fba367b84131b8a_1/some_resource.txt
  file:/C:/Users/lcohen/AppData/Local/Temp/.jppf/784aecb21875112b9fba367b84131b8a_2/some_resource.txt

#5
Comment posted by
 lolo4j
Nov 28, 05:15
Fixed in