If a class is compiled that does not have a package statement but is mistakenly 
loaded in Javassist as though it did have a package statement then Javassist 
will not detect this error and find the class and some methods will give 
incorrect results but not thow an exception whilst others will throw an 
exceptoion. EG:


  | // NoPackage.java - note no package statement
  | public class NoPackage {}
  | 


  | // NoPackageTest.java - note has package statement
  | package examples.javassisttests;
  | 
  | import javassist.*;
  | 
  | 
  | public class NoPackageTest {
  |     public static void main( final String[] notUsed ) throws 
NotFoundException {
  |         final CtClass noPackage = ClassPool.getDefault().get( 
"examples.javassisttests.NoPackage" );
  |         System.out.println( "package = " + noPackage.getPackageName() );
  |         System.out.println( "modifiers = " + noPackage.getModifiers() );
  |     }
  | }
  | 

When run, the above produces:

C:\Personal\Java>java -classpath javassist.jar;. 
examples.javassisttests.NoPackageTest
package = examples.javassisttests
Exception in thread "main" java.lang.RuntimeException: NoPackage in 
examples/javassisttests/NoPackage.java
        at javassist.CtClassType.getClassFile2(CtClassType.java:191)
        at javassist.CtClassType.getModifiers(CtClassType.java:343)
        at examples.javassisttests.NoPackageTest.main(NoPackageTest.java:10)

Showing that get found the class even though it shouldn't, getPackageName ran 
but gave the incorrect package, and getModifiers threw an exception with a less 
then ideal error message.

May I ask:

1. Is a known bug?
2. Is there a fix?
3. Any suggestions on how to code round the problem?

Keep up the good work, Howard.

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3872252#3872252

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3872252


-------------------------------------------------------
This SF.net email is sponsored by Demarc:
A global provider of Threat Management Solutions.
Download our HomeAdmin security software for free today!
http://www.demarc.com/info/Sentarus/hamr30
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to