You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by Bjoern Wuest <bj...@gmx.net> on 2003/04/26 22:53:01 UTC

Incompatible argument -> Method signature

Hello All,

 

I'm not so experienced with BCEL or ByteCode at all, however, I had to
implement an extended version of the Java Proxy
(java.lang.reflect.Proxy).

Please let me say that I am aware of the problems raised by
instrumenting whole objects and that it requires several constraints
hold by the object to properly work but I need this mechanism.

Now, I am faced with a problem where I need a help with:

While the generation works fine and even in the debugger (d-java) the
things look nice, I can't load my class into the virtual machine. The
process terminates with:

 

java.lang.VerifyError: (class: CNormalProxy, method: toString signature:
()Ljava/lang/String;) Incompatible argument to function

      at java.lang.Class.getDeclaredConstructors0(Native Method)

      at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)

      at java.lang.Class.getConstructor0(Class.java:1762)

      at java.lang.Class.getConstructor(Class.java:1002)

      at test.CWrapper.wrap(CWrapper.java:409)

      at test.main(test.java:40)

 

The method I want to create is the ,public java.lang.String toString()'
method. Please find the complete sourcecode to my wrapper class at

 

 

http://www.comtec.e-technik.uni-kassel.de/content/users/bjoern/CWrapper.
java

 

 

(Sorry for the inconvenience of so much code)

 

Thanks a lot for you help

  Bjoern


Re: Getting JavaClass from class instance

Posted by Juozas Baliuka <ba...@mwm.lt>.
I think it is no way to implement this with standard java API or custom
ClassLoder,
classes like java.lang.reflect.Proxy call native methods to define class,
use JNI hooks if possible.

----- Original Message -----
From: "Bjoern Wuest" <bj...@gmx.net>
To: "'BCEL Users List'" <bc...@jakarta.apache.org>;
<bj...@gmx.net>
Sent: Friday, May 02, 2003 11:10 AM
Subject: Getting JavaClass from class instance


> Hello All
>
> I am working on a runtime wrapper for object instances. While I get
> everything working with classes available on secondary storage (file
> system), I have problems to use the mechanism on wrapper objects created
> in memory and now wrapped a second time.
> To solve this, I would require a method looking like:
>
> public JavaClass convert(Class MyClassInstance);
>
> Unfortunately, I could not find some similar method. The only think I
> found was the ClassLoaderRepository (CLR) of BCEL. However, this
> mechanism does not work. The CLR will use the filesystem where the class
> is not available since it is purely "in-memory".
>
> Thanks for tips
>   Bjoern
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
>


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


RE: Getting JavaClass from class instance

Posted by Bjoern Wuest <bj...@gmx.net>.
Hello All

I oversee a possibility with the ClassLoaderRepository. Now I am able to
get an instance of JavaClass for "in-memory" created objects (classes).
Currently I am fighting with the constructor (telling me something about
wrong arguments) but I am quite sure to fix this problem, too.

Regards
  Bjoern


-----Original Message-----
From: Bjoern Wuest [mailto:bjoern.wuest@gmx.net] 
Sent: Freitag, 2. Mai 2003 11:10
To: 'BCEL Users List'; bjoern.wuest@gmx.net
Subject: Getting JavaClass from class instance

Hello All

I am working on a runtime wrapper for object instances. While I get
everything working with classes available on secondary storage (file
system), I have problems to use the mechanism on wrapper objects created
in memory and now wrapped a second time.
To solve this, I would require a method looking like:

public JavaClass convert(Class MyClassInstance);

Unfortunately, I could not find some similar method. The only think I
found was the ClassLoaderRepository (CLR) of BCEL. However, this
mechanism does not work. The CLR will use the filesystem where the class
is not available since it is purely "in-memory".

Thanks for tips
  Bjoern



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


Getting JavaClass from class instance

Posted by Bjoern Wuest <bj...@gmx.net>.
Hello All

I am working on a runtime wrapper for object instances. While I get
everything working with classes available on secondary storage (file
system), I have problems to use the mechanism on wrapper objects created
in memory and now wrapped a second time.
To solve this, I would require a method looking like:

public JavaClass convert(Class MyClassInstance);

Unfortunately, I could not find some similar method. The only think I
found was the ClassLoaderRepository (CLR) of BCEL. However, this
mechanism does not work. The CLR will use the filesystem where the class
is not available since it is purely "in-memory".

Thanks for tips
  Bjoern



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


RE: Incompatible argument -> Method signature

Posted by Bjoern Wuest <bj...@comtec.e-technik.uni-kassel.de>.
Hello

Thanks for all the help. In the first try, I also used the BCELifier but
because of any reason, it didn't work. I slightly modified the "wrapper"
template I wrote and re-BCELified it again and now it seems to work (after
some String-acrobatics :) ).
I will focus on the return type now (which is still missing), run some tests
with various kinds of methods and classes and look what will happen with
nested classes :).

If everything works fine, I will post my code again at the mailing list and
offer for download for some period of time.

Thanks for all the help.
  Bjoern


PS: I appreciate the BCELifier very much since it is an invaluable source
for learning byte-code. I am into byte-code for 6 days now (2 days net-time)
and without BCELifier I would be in the very early beginning.

-----Original Message-----
From: news [mailto:news@main.gmane.org] On Behalf Of Berin Loritsch
Sent: Dienstag, 29. April 2003 16:29
To: bcel-user@jakarta.apache.org
Subject: Re: Incompatible argument -> Method signature


Bjoern Wuest wrote:
> Hello
> 
> Thanks for the hint. I already tried this but as the 
> java.lang.reflect.Proxy class, it supports interfaces only (at least 
> this is what it says). Unfortunately, I have to wrap (proxy) classes. 
> I downloaded to code to study but got very confused because of the 
> many method invocations. I prefer to have few but efficient calls, but 
> others like to have more structure :) I hope I am not wrong but this 
> is what I found in the docu and in the pieces of source code. If you 
> have some hint or tweak how to run with classes, I would appreciate 
> very much.

Bjoern, I put some results of my experiences with BCEL on the Wiki. Perhaps
they can be of some help to you:

http://nagoya.apache.org/wiki/apachewiki.cgi?BCELUserFAQ

I ran into many of the same issues when I wrote the BCEL Compiler for my
binary XML project (http://d-haven.org/bxml).  One thing that helped me was
hand writing the code the way I thought it should be, and then using the
BCELifier (should be available in BCEL 5.1) to see how to write it useing
BCEL.

The Verifier that comes with BCEL is another invaluable tool to help find
out what is going on.  Use that in conjunction with the javap tool (comes
with the JDK), and you will be able to solve most problems.



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


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


Re: Incompatible argument -> Method signature

Posted by Berin Loritsch <bl...@apache.org>.
Bjoern Wuest wrote:
> Hello
> 
> Thanks for the hint. I already tried this but as the
> java.lang.reflect.Proxy class, it supports interfaces only (at least
> this is what it says). Unfortunately, I have to wrap (proxy) classes.
> I downloaded to code to study but got very confused because of the many
> method invocations. I prefer to have few but efficient calls, but others
> like to have more structure :)
> I hope I am not wrong but this is what I found in the docu and in the
> pieces of source code. If you have some hint or tweak how to run with
> classes, I would appreciate very much.

Bjoern, I put some results of my experiences with BCEL on the Wiki.
Perhaps they can be of some help to you:

http://nagoya.apache.org/wiki/apachewiki.cgi?BCELUserFAQ

I ran into many of the same issues when I wrote the BCEL Compiler for
my binary XML project (http://d-haven.org/bxml).  One thing that
helped me was hand writing the code the way I thought it should be,
and then using the BCELifier (should be available in BCEL 5.1) to
see how to write it useing BCEL.

The Verifier that comes with BCEL is another invaluable tool to help
find out what is going on.  Use that in conjunction with the javap
tool (comes with the JDK), and you will be able to solve most problems.



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


Re: Incompatible argument -> Method signature

Posted by Juozas Baliuka <ba...@centras.lt>.
It supports classes too (the first argument in all methods is "class to
extend"), but it can be better documented.


> Hello
>
> Thanks for the hint. I already tried this but as the
> java.lang.reflect.Proxy class, it supports interfaces only (at least
> this is what it says). Unfortunately, I have to wrap (proxy) classes.
> I downloaded to code to study but got very confused because of the many
> method invocations. I prefer to have few but efficient calls, but others
> like to have more structure :)
> I hope I am not wrong but this is what I found in the docu and in the
> pieces of source code. If you have some hint or tweak how to run with
> classes, I would appreciate very much.
>
>
> I did some further tests on my code. If I run my wrapper with a class
> that has a method without parameters and return value, I will not
> receive an incompatible argument message but a stack size error (stack 5
> != 4 -> wow, clever :) ). As soon as I have any non-void signature or
> return value with my method, I receive the incompatible argument
> message.

 possible you have wrong "XRETURN" instruction.

>
>
> This happens if I write the code in Java, compile, BECLify and then run
> the BECELified code, too. I will receive the same errors! (I use BCEL5.1
> and JDK1.4.1_01)
>
>
> Here is what I want to achieve:
>
> >>>>>>>>>>>>>>>>>>>>>>
> protected String p_Nothing(Object A, boolean B, long C) {
> Object[] p = new Object[]{A, new Boolean(B), new Long(C)};
> Class[] c = new Class[]{Object.class, Boolean.TYPE, Long.TYPE};
> Method m = null;
> try { m = m_Instance.getClass().getMethod("p_Nothing", c); }
> catch (Throwable Cause) {
> // Something wrong with the reflections
> AEvent event = new CNoMethodEvent(this, m_Instance,
> "p_Nothing", c);
> m_Listener.invokeErrorListeners(event, Cause);
> }
> CInvokeMethodEvent event = new CInvokeMethodEvent(this,
> m_Instance, m, p);
> try { event = m_Invoke(event); }
> catch (Throwable Cause) { m_Listener.invokeErrorListeners(event,
> Cause); }
> return (String)(event.getReturn());
> }
> <<<<<<<<<<<<<<<<<<<<<
>
> Of course, the method signature, name and simply everything except the
> body can vary :)
>
>
> Thanks for your help,
>   Bjoern
>
>
> -----Original Message-----
> From: Juozas Baliuka [mailto:baliuka@centras.lt]
> Sent: Sonntag, 27. April 2003 19:00
> To: BCEL Users List
> Subject: Re: Incompatible argument -> Method signature
>
> see this :
> http://cglib.sourceforge.net, It  can be the same as you need.
>
> ----- Original Message -----
> From: "Bjoern Wuest" <bj...@gmx.net>
> To: <bc...@jakarta.apache.org>
> Sent: Saturday, April 26, 2003 10:53 PM
> Subject: Incompatible argument -> Method signature
>
>
> > Hello All,
> >
> >
> >
> > I'm not so experienced with BCEL or ByteCode at all, however, I had to
> > implement an extended version of the Java Proxy
> > (java.lang.reflect.Proxy).
> >
> > Please let me say that I am aware of the problems raised by
> > instrumenting whole objects and that it requires several constraints
> > hold by the object to properly work but I need this mechanism.
> >
> > Now, I am faced with a problem where I need a help with:
> >
> > While the generation works fine and even in the debugger (d-java) the
> > things look nice, I can't load my class into the virtual machine. The
> > process terminates with:
> >
> >
> >
> > java.lang.VerifyError: (class: CNormalProxy, method: toString
> signature:
> > ()Ljava/lang/String;) Incompatible argument to function
> >
> >       at java.lang.Class.getDeclaredConstructors0(Native Method)
> >
> >       at
> java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
> >
> >       at java.lang.Class.getConstructor0(Class.java:1762)
> >
> >       at java.lang.Class.getConstructor(Class.java:1002)
> >
> >       at test.CWrapper.wrap(CWrapper.java:409)
> >
> >       at test.main(test.java:40)
> >
> >
> >
> > The method I want to create is the ,public java.lang.String
> toString()'
> > method. Please find the complete sourcecode to my wrapper class at
> >
> >
> >
> >
> >
> >
> http://www.comtec.e-technik.uni-kassel.de/content/users/bjoern/CWrapper.
> > java
> >
> >
> >
> >
> >
> > (Sorry for the inconvenience of so much code)
> >
> >
> >
> > Thanks a lot for you help
> >
> >   Bjoern
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>


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


RE: Incompatible argument -> Method signature

Posted by Bjoern Wuest <bj...@gmx.net>.
Hello

Thanks for the hint. I already tried this but as the
java.lang.reflect.Proxy class, it supports interfaces only (at least
this is what it says). Unfortunately, I have to wrap (proxy) classes.
I downloaded to code to study but got very confused because of the many
method invocations. I prefer to have few but efficient calls, but others
like to have more structure :)
I hope I am not wrong but this is what I found in the docu and in the
pieces of source code. If you have some hint or tweak how to run with
classes, I would appreciate very much.


I did some further tests on my code. If I run my wrapper with a class
that has a method without parameters and return value, I will not
receive an incompatible argument message but a stack size error (stack 5
!= 4 -> wow, clever :) ). As soon as I have any non-void signature or
return value with my method, I receive the incompatible argument
message.


This happens if I write the code in Java, compile, BECLify and then run
the BECELified code, too. I will receive the same errors! (I use BCEL5.1
and JDK1.4.1_01)


Here is what I want to achieve:

>>>>>>>>>>>>>>>>>>>>>>
protected String p_Nothing(Object A, boolean B, long C) {
	Object[] p = new Object[]{A, new Boolean(B), new Long(C)};
	Class[] c = new Class[]{Object.class, Boolean.TYPE, Long.TYPE};
	Method m = null;
	try { m = m_Instance.getClass().getMethod("p_Nothing", c); }
	catch (Throwable Cause) {
		// Something wrong with the reflections
		AEvent event = new CNoMethodEvent(this, m_Instance,
"p_Nothing", c);
		m_Listener.invokeErrorListeners(event, Cause);
	}
	CInvokeMethodEvent event = new CInvokeMethodEvent(this,
m_Instance, m, p);
	try { event = m_Invoke(event); }
	catch (Throwable Cause) { m_Listener.invokeErrorListeners(event,
Cause); }
	return (String)(event.getReturn());
}
<<<<<<<<<<<<<<<<<<<<<

Of course, the method signature, name and simply everything except the
body can vary :)


Thanks for your help,
  Bjoern


-----Original Message-----
From: Juozas Baliuka [mailto:baliuka@centras.lt] 
Sent: Sonntag, 27. April 2003 19:00
To: BCEL Users List
Subject: Re: Incompatible argument -> Method signature

see this : 
http://cglib.sourceforge.net, It  can be the same as you need.

----- Original Message ----- 
From: "Bjoern Wuest" <bj...@gmx.net>
To: <bc...@jakarta.apache.org>
Sent: Saturday, April 26, 2003 10:53 PM
Subject: Incompatible argument -> Method signature


> Hello All,
> 
>  
> 
> I'm not so experienced with BCEL or ByteCode at all, however, I had to
> implement an extended version of the Java Proxy
> (java.lang.reflect.Proxy).
> 
> Please let me say that I am aware of the problems raised by
> instrumenting whole objects and that it requires several constraints
> hold by the object to properly work but I need this mechanism.
> 
> Now, I am faced with a problem where I need a help with:
> 
> While the generation works fine and even in the debugger (d-java) the
> things look nice, I can't load my class into the virtual machine. The
> process terminates with:
> 
>  
> 
> java.lang.VerifyError: (class: CNormalProxy, method: toString
signature:
> ()Ljava/lang/String;) Incompatible argument to function
> 
>       at java.lang.Class.getDeclaredConstructors0(Native Method)
> 
>       at
java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
> 
>       at java.lang.Class.getConstructor0(Class.java:1762)
> 
>       at java.lang.Class.getConstructor(Class.java:1002)
> 
>       at test.CWrapper.wrap(CWrapper.java:409)
> 
>       at test.main(test.java:40)
> 
>  
> 
> The method I want to create is the ,public java.lang.String
toString()'
> method. Please find the complete sourcecode to my wrapper class at
> 
>  
> 
>  
> 
>
http://www.comtec.e-technik.uni-kassel.de/content/users/bjoern/CWrapper.
> java
> 
>  
> 
>  
> 
> (Sorry for the inconvenience of so much code)
> 
>  
> 
> Thanks a lot for you help
> 
>   Bjoern
> 
> 


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


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


Re: Incompatible argument -> Method signature

Posted by Juozas Baliuka <ba...@centras.lt>.
see this : 
http://cglib.sourceforge.net, It  can be the same as you need.

----- Original Message ----- 
From: "Bjoern Wuest" <bj...@gmx.net>
To: <bc...@jakarta.apache.org>
Sent: Saturday, April 26, 2003 10:53 PM
Subject: Incompatible argument -> Method signature


> Hello All,
> 
>  
> 
> I'm not so experienced with BCEL or ByteCode at all, however, I had to
> implement an extended version of the Java Proxy
> (java.lang.reflect.Proxy).
> 
> Please let me say that I am aware of the problems raised by
> instrumenting whole objects and that it requires several constraints
> hold by the object to properly work but I need this mechanism.
> 
> Now, I am faced with a problem where I need a help with:
> 
> While the generation works fine and even in the debugger (d-java) the
> things look nice, I can't load my class into the virtual machine. The
> process terminates with:
> 
>  
> 
> java.lang.VerifyError: (class: CNormalProxy, method: toString signature:
> ()Ljava/lang/String;) Incompatible argument to function
> 
>       at java.lang.Class.getDeclaredConstructors0(Native Method)
> 
>       at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
> 
>       at java.lang.Class.getConstructor0(Class.java:1762)
> 
>       at java.lang.Class.getConstructor(Class.java:1002)
> 
>       at test.CWrapper.wrap(CWrapper.java:409)
> 
>       at test.main(test.java:40)
> 
>  
> 
> The method I want to create is the ,public java.lang.String toString()'
> method. Please find the complete sourcecode to my wrapper class at
> 
>  
> 
>  
> 
> http://www.comtec.e-technik.uni-kassel.de/content/users/bjoern/CWrapper.
> java
> 
>  
> 
>  
> 
> (Sorry for the inconvenience of so much code)
> 
>  
> 
> Thanks a lot for you help
> 
>   Bjoern
> 
> 


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