Comments (3)
I took a first stab at implementing this and it didn't go too well.
In ClassTransformer.java, I used this:
private boolean matches(String[] strs, String target)
{
for (String str : strs)
{
if (str.equals(MATCH_NONE))
{
continue;
}
else if (str.equals(MATCH_ALL) ||
target.contains(str))
{
return true;
}
else if (isAssignableFrom(str, target))
{
return true;
}
}
return false;
}
private boolean isAssignableFrom(String candidateInterface, String candidateImpl) {
TraceHandler.INSTANCE.writeTraceOutput("DEBUG: Is impl class [" + candidateImpl + "] assignable from interface [" + candidateInterface + "]");
System.out.println("XX DEBUG: Is impl class [" + candidateImpl + "] assignable from interface [" + candidateInterface + "]");
boolean rc = false;
Class klazCandidateInterface = null;
Class klazCandidateImpl = null;
try {
klazCandidateInterface = Class.forName(candidateInterface);
klazCandidateImpl = Class.forName(candidateImpl);
if (klazCandidateInterface.isInterface() &&
klazCandidateInterface.isAssignableFrom(klazCandidateImpl))
{
TraceHandler.INSTANCE.writeTraceOutput("DEBUG: isAssignableFrom=true");
return true;
}
} catch (Exception e)
{ //any exception from above means the imple does not implement the interface.
if ( e.getMessage().indexOf("TraceInterface")>0) {
e.printStackTrace();
}
System.out.println("exception [" + e.getMessage() + "]");
}
TraceHandler.INSTANCE.writeTraceOutput("DEBUG: isAssignableFrom=false");
System.out.println("DEBUG: isAssignableFrom=false");
return false;
}
Can't remember exactly what the problem was, but the code just seems wrong.
Before a class is loaded, this class is evaluating whether it implements an interface.
But it seems like the Java API must first load a class before you can make this determination.
So, I wonder if we should consider using this ASM-based library to determine if a class implements a particular interface:
** http://software.clapper.org/javautil/
** http://software.clapper.org/javautil/api/org/clapper/util/classutil/ClassFinder.html
Would appreciate any thoughts on this.
--Erik
from org.intrace.
I have pushed a commit with a quick implementation of this issue.
from org.intrace.
Martin, thanks. I gave that code a try and I needed a single line of code to get it to work.
Would you give it a try, and commit if it looks good?
Thanks,
--Erik
From org/intrace/agent/ClassTransformer.java, the method isToBeConsideredForInstrumentation().
// Don't modify classes which fail to match the regex
if ((settings.getClassRegex() == null)
|| !matches(settings.getClassRegex(), className))
{
// Actually we should modify if any of the interfaces match the regex
boolean matchedInterface = false;
for(String klassInterface : getInterfaces(className, originalClassfile))
{
/**
* ## ## ## ## ## ## ## ##
* I had to add this next line of code to get this work work.
* ## ## ## ## ## ## ## ##
*/
klassInterface = klassInterface.replace('/','.');
System.out.println("#@# Comparing [" + klassInterface + "]");
if ((settings.getClassRegex() != null)
&& matches(settings.getClassRegex(), klassInterface))
{
System.out.println("matched interface successfully!");
matchedInterface |= true;
}
}
from org.intrace.
Related Issues (20)
- Feature request: burst-mode network requests HOT 2
- Feature request: fixed, non-random trace port for firewall rule HOT 5
- Feature request: instrument multiple class names from paste buffer HOT 1
- InTrace UI won't allow class names with underscore character HOT 2
- Feature request & sample implementation: Ignore repeated methods HOT 4
- Class name length is restricted. HOT 2
- The latest UI is not available for download (Release 30)
- UI indicates that exceptions are returned when branch trace is disabled
- Does not work in W7 if Eclipse path has embedded space(s) HOT 2
- Instrumentation on class compiled with JDK7 HOT 3
- Eclipse plug in issue HOT 2
- Feature request: Add the hashCode() of the object being traced to the output log
- swt-gtk library issue HOT 1
- java.lang.InternalError
- method-level granularity
- server agent crash HOT 3
- enhancement #31 is really slow HOT 2
- InTrace.app requires legacy Java SE 6 (OS X)
- swtjar
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from org.intrace.