jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zachary Palmer <zep_b...@bahj.com>
Subject Re: SyntheticRepository
Date Fri, 22 Jan 2010 21:18:58 GMT
After examining the BCEL source code (which was, at least for 
SyntheticRepository and ClassPath, a pretty nice experience) I have 
discovered that the SyntheticRepository implementation uses 
ClassPath.getInputStream(...) to obtain the binary.  
ClassPath.getInputStream(...) does not check the provided paths first; 
it checks the current system classloader.

Fortunately, ClassPath.getClassFile(...) errors out if the class is not 
in the explicitly-specified classpath entries.  This means I should be 
able to write my own Repository implementation to get things working for 
my specific project.  I just wanted to leave this explanation for anyone 
who might stumble into it in the archives.  :)

Cheers, and thanks again for the impressive library!

- Zachary Palmer
> Hi, all.  I'm new to both the list and to BCEL, but it looks like 
> precisely what I need for a research project on which I'm working.  I 
> need reflective access to the .class files which are on a given 
> classpath without loading them into my JVM, so I've been experimenting 
> with SyntheticRepository and ClassPath.  I've written small test app 
> and I'm getting results other than what I would expect.  (e-mail 
> continues below the following source)
>
>
> import org.apache.bcel.classfile.JavaClass;
> import org.apache.bcel.util.ClassPath;
> import org.apache.bcel.util.Repository;
> import org.apache.bcel.util.SyntheticRepository;
>
> public class BCELTest
> {
>    public static void main(String[] arg) throws Exception
>    {
>        ClassPath cp = new ClassPath("/some/path/bin1");
>        System.out.println(cp);
>        Repository repo = SyntheticRepository.getInstance(cp);
>        repo.clear();
>        test(repo, "Test");
>        test(repo, "BCELTest");
>    }
>      public static void test(Repository repo, String className) throws 
> Exception
>    {
>        JavaClass jc = repo.loadClass(className);
>        
> System.out.println("==============================================");
>        System.out.println(jc);
>    }
> }
>
>
> The BCELTest.class binary is located in /some/path/bin2; a 
> hello-world-style Test.class binary is located in /some/path/bin1.  I 
> would expect the above program to run the first test successfully 
> (loading Test.class and printing a summary of it) and then choke on 
> the second (since /some/path/bin2 is not in the ClassPath I 
> provided).  However, my little test application successfully loads 
> both classes.  Why is this?
>
> For the purposes of my project, I need to be able to reflectively 
> analyze classes on a specified classpath (such as might be used when 
> invoking the Java compiler) without accidentally polluting it with my 
> own JVM's classpath.  The above behavior has me a bit confused.  Am I 
> going about things wrong?  Any suggestions are welcome.
>
> And by the way, thanks for the incredible library.  :)  If all goes 
> well, I'll have something to add to the "BCEL Projects" list.
>
> Cheers,
>
> Zachary Palmer
>


---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org


Mime
View raw message