[groovy-user] Autobox issue with 1.5.2

0 views
Skip to first unread message

cmay4

unread,
Jan 29, 2008, 3:41:49 PM1/29/08
to us...@groovy.codehaus.org

We were having a strange issue with 1.5.2 today and we were able to boil it
down to auto-boxing. Below is code which works fine under 1.5.1 but returns
an exception under 1.5.2.

We can work around this issue by not using auto-boxing, but I wanted to make
sure you knew about this change in behavior between 1.5.1 and 1.5.2. In
addition, I tested it under a 1.6 snapshot from late last week and it fails
on that build as well.

Thanks,

Chuck

public class Autobox {

public static void main(String[] args) {
new GroovyShell().evaluate("Autobox.Util.printByte(\"1\",
Byte.valueOf((byte)1));");
new GroovyShell().evaluate("Autobox.Util.printByte(\"1\",
(byte)1);");
}

public static class Util {
public static void printByte(String str, Byte defaultValue) {
System.out.println(str + ", " + defaultValue);
}
}
}

[jboss@snook] ~/prj/groovy $ java -cp .:./groovy-all-1.5.1.jar Autobox
1, 1
1, 1
[jboss@snook] ~/prj/groovy $ java -cp .:./groovy-all-1.5.2.jar Autobox
1, 1
Exception in thread "main" groovy.lang.MissingMethodException: No signature
of method: static Autobox$Util.printByte() is applicable for argument types:
(java.lang.String, java.lang.Byte) values: {"1", 1}
at
groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1144)
at
groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1130)
at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:748)
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:167)
at Script1.run(Script1.groovy:1)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:543)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:518)
at Autobox.main(Autobox.java:7)

--
View this message in context: http://www.nabble.com/Autobox-issue-with-1.5.2-tp15168956p15168956.html
Sent from the groovy - user mailing list archive at Nabble.com.


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

http://xircles.codehaus.org/manage_email

Guillaume Laforge

unread,
Jan 29, 2008, 3:56:04 PM1/29/08
to us...@groovy.codehaus.org
Looks like a bug worth a JIRA issue!

--
Guillaume Laforge
Groovy Project Manager
G2One, Inc. Vice-President Technology
http://www.g2one.com

Jochen Theodorou

unread,
Jan 29, 2008, 4:06:44 PM1/29/08
to us...@groovy.codehaus.org
cmay4 schrieb:

> We were having a strange issue with 1.5.2 today and we were able to boil it
> down to auto-boxing. Below is code which works fine under 1.5.1 but returns
> an exception under 1.5.2.
>
> We can work around this issue by not using auto-boxing, but I wanted to make
> sure you knew about this change in behavior between 1.5.1 and 1.5.2. In
> addition, I tested it under a 1.6 snapshot from late last week and it fails
> on that build as well.
>
[...]

> public class Autobox {
>
> public static void main(String[] args) {
> new GroovyShell().evaluate("Autobox.Util.printByte(\"1\",
> Byte.valueOf((byte)1));");
> new GroovyShell().evaluate("Autobox.Util.printByte(\"1\",
> (byte)1);");
> }
>
> public static class Util {
> public static void printByte(String str, Byte defaultValue) {
> System.out.println(str + ", " + defaultValue);
> }
> }
> }

I guess you have good reasons for that, but you are making your life
here a bit more difficult than needed.

Autobox.Util.printByte("1",1)

that would do it already. Groovy is able to call a method taking a byte
by using a normal int. well... If the above does not work, then it is
another bug.

bye blackdrag

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
http://www.g2one.com/

cmay4

unread,
Jan 29, 2008, 4:06:53 PM1/29/08
to us...@groovy.codehaus.org

Ok..I'll submit one.


glaforge wrote:
>
> Looks like a bug worth a JIRA issue!
>

--
View this message in context: http://www.nabble.com/Autobox-issue-with-1.5.2-tp15168956p15169385.html

cmay4

unread,
Jan 29, 2008, 4:13:53 PM1/29/08
to us...@groovy.codehaus.org

Ok..I'll submit one.

Here it is:

http://jira.codehaus.org/browse/GROOVY-2553

cmay4

unread,
Jan 29, 2008, 4:25:47 PM1/29/08
to us...@groovy.codehaus.org

Taking the cast out doesn't work for me. It tries to convert it into an
Integer.

import groovy.lang.GroovyShell;

public class Autobox {

public static void main(String[] args) {
new GroovyShell().evaluate("Autobox.Util.printByte(\"1\",
Byte.valueOf((byte)1));");

new GroovyShell().evaluate("Autobox.Util.printByte(\"1\", 1);");


new GroovyShell().evaluate("Autobox.Util.printByte(\"1\",
(byte)1);");
}

public static class Util {
public static void printByte(String str, Byte defaultValue) {
System.out.println(str + ", " + defaultValue);
}
}
}

[jboss@snook] ~/prj/groovy $ java -cp .:./groovy-all-1.5.1.jar Autobox
1, 1


Exception in thread "main" groovy.lang.MissingMethodException: No signature
of method: static Autobox$Util.printByte() is applicable for argument types:

(java.lang.String, java.lang.Integer) values: {"1", 1}
at
groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1127)
at
groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1113)
at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:744)


at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:167)
at Script1.run(Script1.groovy:1)

at groovy.lang.GroovyShell.evaluate(GroovyShell.java:459)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:434)
at Autobox.main(Autobox.java:7)

Jochen Theodorou wrote:
>
> I guess you have good reasons for that, but you are making your life
> here a bit more difficult than needed.
>
> Autobox.Util.printByte("1",1)
>
> that would do it already. Groovy is able to call a method taking a byte
> by using a normal int. well... If the above does not work, then it is
> another bug.
>
> bye blackdrag
>
> --
> Jochen "blackdrag" Theodorou
> The Groovy Project Tech Lead (http://groovy.codehaus.org)
> http://blackdragsview.blogspot.com/
> http://www.g2one.com/
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>

--
View this message in context: http://www.nabble.com/Autobox-issue-with-1.5.2-tp15168956p15169762.html


Sent from the groovy - user mailing list archive at Nabble.com.

Jochen Theodorou

unread,
Jan 29, 2008, 4:55:16 PM1/29/08
to us...@groovy.codehaus.org
cmay4 schrieb:

> Taking the cast out doesn't work for me. It tries to convert it into an
> Integer.
>
> import groovy.lang.GroovyShell;
>
> public class Autobox {
>
> public static void main(String[] args) {
> new GroovyShell().evaluate("Autobox.Util.printByte(\"1\",
> Byte.valueOf((byte)1));");
> new GroovyShell().evaluate("Autobox.Util.printByte(\"1\", 1);");
> new GroovyShell().evaluate("Autobox.Util.printByte(\"1\",
> (byte)1);");
> }
>
> public static class Util {
> public static void printByte(String str, Byte defaultValue) {
> System.out.println(str + ", " + defaultValue);
> }
> }
> }

I didn't mean it will work that way, I wanted to tell you that it should
have worked that way. That it did not proves that there is a major error

Reply all
Reply to author
Forward
0 new messages