Giter Club home page Giter Club logo

Comments (3)

eostermueller avatar eostermueller commented on August 30, 2024

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.

mchr3k avatar mchr3k commented on August 30, 2024

I have pushed a commit with a quick implementation of this issue.

from org.intrace.

eostermueller avatar eostermueller commented on August 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.