#107 Class.getResourceAsStream() fails from Java source

v2.0.2
closed-fixed
Robert Pes
6
2010-03-29
2010-02-11
Robert Pes
No

The class.getResourceAsStream() Java method allows to load files through the class loader relative to the calling class. This is very convenient because one can package for example template images together with the Java test code into one class path or even JAR file.

This way of loading files works well when Java test scripts are executed independently using their own main() method. It however fails when Java source code (.java) is executed by T-Plan Robot either through CLI or from the GUI. The files do not seem to be loaded from the same directory as the Java source code file.

Discussion

  • Robert Pes
    Robert Pes
    2010-02-11

    The Java source code is compiled internally into an object in the memory. Such classes are then instantiated through a special class loader (com.tplan.robot.scripting.interpret.java.MemoryClassLoader) .

    Having inspected the code I found out that the loader passes calls of the getResourceAsStream() method to the parent loader which causes the tool to look for the files in the path where the core T-Plan Robot classes are located (typically inside the robot.jar file). As the Java source code test scripts are usually located outside of this path, the loading mechanism fails.

    The class loader must be updated to keep track of the Java source file location and resolve such requests against it.

     
  • Robert Pes
    Robert Pes
    2010-02-11

    • status: open --> open-fixed
     
  • Robert Pes
    Robert Pes
    2010-02-11

    Fixed and committed to CVS. Targeted for 2.0.3.

     
  • Robert Pes
    Robert Pes
    2010-03-29

    Fix delivered in 2.0.3 on 29 March 2010.

     
  • Robert Pes
    Robert Pes
    2010-03-29

    • status: open-fixed --> closed-fixed