Discussion:
[groovy-dev] Inconsistent behavior when method name has spaces
Roshan Dawrani
2010-11-23 14:50:47 UTC
Permalink
Hi,

Can someone confirm the behavior I am seeing for the code below?

The code below works fine as is, but if I comment out the declaration inside
the method, then it fails saying "Caught: java.lang.ClassFormatError:
Illegal method name "can you figure out what I'm up to?" in class Test1"

---------------------------------------------------------------------------------------
class Test1 {
def "can you figure out what I'm up to?"() {
def name = []
}
}

assert Test1.methods.find{it.name.contains('can you')} != null
---------------------------------------------------------------------------------------
--
Roshan
http://roshandawrani.wordpress.com/
http://twitter.com/roshandawrani
Jochen Theodorou
2010-11-23 14:59:58 UTC
Permalink
Post by Roshan Dawrani
Hi,
Can someone confirm the behavior I am seeing for the code below?
The code below works fine as is, but if I comment out the declaration
java.lang.ClassFormatError: Illegal method name "can you figure out what
I'm up to?" in class Test1"
---------------------------------------------------------------------------------------
class Test1 {
def "can you figure out what I'm up to?"() {
def name = []
}
}
assert Test1.methods.find{it.name.contains('can you')} != null
---------------------------------------------------------------------------------------
haven't tested this, but what we accept as String and what the JVM
accepts is not the same. Normally we should do name mangling as for
example described in
http://blogs.sun.com/jrose/entry/symbolic_freedom_in_the_vm

In the case above I would guess, that at least the question mark is a
problem.

bye blackdrag
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead
http://blackdragsview.blogspot.com/
For Groovy programming sources visit http://groovy.codehaus.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Roshan Dawrani
2010-11-23 15:05:22 UTC
Permalink
I see the same behavior even if the method name is "not working"

I just changed it to "can you figure out what I'm up to?" as I remembered
that in some Spock example I had seen that working fine.

So, officially, does groovy support methods with names having spaces? Right
now, it seems inconsistent and I don't know depending on what..
Post by Roshan Dawrani
Hi,
Can someone confirm the behavior I am seeing for the code below?
The code below works fine as is, but if I comment out the declaration
Illegal method name "can you figure out what I'm up to?" in class Test1"
---------------------------------------------------------------------------------------
class Test1 {
def "can you figure out what I'm up to?"() {
def name = []
}
}
assert Test1.methods.find{it.name.contains('can you')} != null
---------------------------------------------------------------------------------------
haven't tested this, but what we accept as String and what the JVM accepts
is not the same. Normally we should do name mangling as for example
described in http://blogs.sun.com/jrose/entry/symbolic_freedom_in_the_vm
In the case above I would guess, that at least the question mark is a
problem.
bye blackdrag
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead
http://blackdragsview.blogspot.com/
For Groovy programming sources visit http://groovy.codehaus.org
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Jochen Theodorou
2010-11-23 15:23:25 UTC
Permalink
Post by Roshan Dawrani
I see the same behavior even if the method name is "not working"
I just changed it to "can you figure out what I'm up to?" as I
remembered that in some Spock example I had seen that working fine.
So, officially, does groovy support methods with names having spaces?
Right now, it seems inconsistent and I don't know depending on what..
supporting --- not so easy to answer... the mangling is unimplemented,
so it works in some cases and in others it does not. So it supports it
syntax wise, but defining a method with spaces and other non java
identifier characters will currently lead to a ClassFormatError. Maybe
Spock does some name mangling on its own.

bye blackdrag
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead
http://blackdragsview.blogspot.com/
For Groovy programming sources visit http://groovy.codehaus.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Roshan Dawrani
2010-11-23 15:31:00 UTC
Permalink
With no Spock involved, and with no name mangling done, below is the code
and its bytecode version, which works fine.

I don't think Spock does any name mangling - but may be the inconsistency is
at VM-internals level rather than at groovy level. I just wanted to know
what is the official stand right now on such method names (I was looking at
an issue reported by a user)...

-----------------------------Source Code---------------------
class Test1 {
def "can you figure out what I'm up to?"() {
def name = []
}
}
assert Test1.methods.find{it.name.contains('can you')} != null
-----------------------------Bytecode decompiled---------------------
......
public Object can you figure out what I'm up to?()
{
CallSite[] arrayOfCallSite = $getCallSiteArray();
.....
}
......
-----------------------------------------------------------
Post by Roshan Dawrani
I see the same behavior even if the method name is "not working"
I just changed it to "can you figure out what I'm up to?" as I remembered
that in some Spock example I had seen that working fine.
So, officially, does groovy support methods with names having spaces?
Right now, it seems inconsistent and I don't know depending on what..
supporting --- not so easy to answer... the mangling is unimplemented, so
it works in some cases and in others it does not. So it supports it syntax
wise, but defining a method with spaces and other non java identifier
characters will currently lead to a ClassFormatError. Maybe Spock does some
name mangling on its own.
bye blackdrag
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead
http://blackdragsview.blogspot.com/
For Groovy programming sources visit http://groovy.codehaus.org
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Jochen Theodorou
2010-11-23 17:36:31 UTC
Permalink
Roshan Dawrani wrote:
[...]
Post by Roshan Dawrani
I don't think Spock does any name mangling - but may be the
inconsistency is at VM-internals level rather than at groovy level. I
just wanted to know what is the official stand right now on such method
names (I was looking at an issue reported by a user)...
If you want to implement name mangling, then go on. I always wanted, but
never found the time to do it.

bye blackdrag
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead
http://blackdragsview.blogspot.com/
For Groovy programming sources visit http://groovy.codehaus.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Roshan Dawrani
2010-11-23 17:43:44 UTC
Permalink
I am not so sure about mangling of method names. That will mean that all
(explicit) method calls will need to be transformed too, right - for
instance in the method calls below?

Do you think all the ways of calling methods can be transformed reliably? Or
will it be more like un-necessarily supporting a trick that is more often
than not not-used?

------------------------------------------
class Test {
def "some method"() {}
}

new Test()."some method"()

def m = "some method"
new Test()."$m"()
------------------------------------------
Post by Roshan Dawrani
[...]
I don't think Spock does any name mangling - but may be the inconsistency
is at VM-internals level rather than at groovy level. I just wanted to know
what is the official stand right now on such method names (I was looking at
an issue reported by a user)...
If you want to implement name mangling, then go on. I always wanted, but
never found the time to do it.
bye blackdrag
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead
http://blackdragsview.blogspot.com/
For Groovy programming sources visit http://groovy.codehaus.org
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Jochen Theodorou
2010-11-23 18:00:32 UTC
Permalink
Post by Roshan Dawrani
I am not so sure about mangling of method names. That will mean that all
(explicit) method calls will need to be transformed too, right - for
instance in the method calls below?
I would transform the reflective information we get from the class
instead of transforming the method call name itself. So "some method"
stays some method, while in bytecode we have something else. An
alternative to this would be to have the transformed and untransformed
name appear.
Post by Roshan Dawrani
Do you think all the ways of calling methods can be transformed
reliably? Or will it be more like un-necessarily supporting a trick that
is more often than not not-used?
as long as the transformation works two ways, there shouldn't really be
a problem, if don like I suggested, I think.

bye blackdrag
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead
http://blackdragsview.blogspot.com/
For Groovy programming sources visit http://groovy.codehaus.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Loading...