siberider / javasnoop

Automatically exported from code.google.com/p/javasnoop
0 stars 0 forks source link

JavaSnoop Does Not Support Resources When Instrumenting #13

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Snoop on an application that loads resources required for something
2. Wait for java.lang.NullPointerException

What is the expected output? What do you see instead?
When JavaSnoop instruments a class it magically pulls in all the resources for 
that class. It currently doesn't do this at the moment.

What version of the product are you using? On what operating system?
1 FINAL on WinXP SP3

Please provide any additional information below.

Here's the method pseudo-code:

XXXXX method:
foo = new ImageIcon(Some.class.getResource("/path/to/some.png"));
bar(foo.getImage());

ImageIcon isn't happy with the null from class.getResources it seems. The jar 
does contain the some.png resource at the correct path. JavaSnoop doesn't seem 
to load the resource correctly.

Here's a partial stack trace:

java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(ImageIcon.java:167)
    at XXXXX method
    at java.lang.Class.forName(Class.java:247)
    at com.aspect.snoop.ui.hook.FunctionSearchView.populateResults(FunctionSearchView.java:265)
    at com.aspect.snoop.ui.hook.FunctionSearchView.txtMethodKeyTyped(FunctionSearchView.java:229)
    at com.aspect.snoop.ui.hook.FunctionSearchView.access$100(FunctionSearchView.java:34)
    at com.aspect.snoop.ui.hook.FunctionSearchView$2.keyTyped(FunctionSearchView.java:120)
    at java.awt.Component.processKeyEvent(Component.java:6222)
[...]

Original issue reported on code.google.com by jon.pas...@aspectsecurity.com on 21 Jan 2011 at 3:38

GoogleCodeExporter commented 9 years ago
I'm listing this as a defect because this is bad. Your analysis is correct: 
when JavaSnoop imports the classes into its ClassLoader, it doesn't get the 
resources. This is because classes are retrieved using the 
Instrumentation.getAllLoadedClasses() API, which properly does not return other 
resources that may reside in the JARs.

The model in JavaSnoop is totally class based, so I'm not sure how resources 
will fit into it, but I will take a long hard look at it.

Original comment by arshan.d...@gmail.com on 21 Jan 2011 at 4:19