jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-275

Allows assignment of a value to a numeric type which is too large for it to hold

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: 1.0-beta-4
  • Fix Version/s: None
  • Component/s: parser
  • Labels:
    None
  • Environment:
    All

Description

Integer x = 2147483648;
println x.class
println x

This will create a long and "successfully" assign it to an Integer, resulting in the following output:
class java.lang.Integer
-2147483648

This could be a little confusing for a user.

Issue Links

depends upon

Improvement - An improvement or enhancement to an existing feature or task. GROOVY-256 Numeric literals: default BigDecimal for decimals, support suffixes

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.
is depended upon by

Task - A task that needs to be done. GROOVY-753 complete parser

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.
is related to

Bug - A problem which impairs or prevents the functions of the product. GROOVY-339 Problem coercing 7/3 to double

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Brian Larson added a comment - 14/Mar/04 5:08 PM

This issue should be resolved after the code from issue 256 is committed.

Show
Brian Larson added a comment - 14/Mar/04 5:08 PM This issue should be resolved after the code from issue 256 is committed.
Hide
Permalink
Brian Larson added a comment - 08/Apr/04 9:13 AM

I did not fix this issue with 256. I'll submit a separate patch for it.

Show
Brian Larson added a comment - 08/Apr/04 9:13 AM I did not fix this issue with 256. I'll submit a separate patch for it.
Hide
Permalink
blackdrag blackdrag added a comment - 07/Feb/05 3:29 PM

I changed the "Component/s" from classgen to parser, because the bytecode is ok, it's a task for the parser to print an error message here

Show
blackdrag blackdrag added a comment - 07/Feb/05 3:29 PM I changed the "Component/s" from classgen to parser, because the bytecode is ok, it's a task for the parser to print an error message here
Hide
Permalink
Paul King added a comment - 15/Oct/07 2:54 AM - edited

The code for this is easy, but it is not clear what the behaviour should be.

The current code in DefaultTypeTransformation:

} else if (type == Integer.class) {
    return new Integer(n.intValue());

coudl be changed to:

} else if (type == Integer.class) {
        long longValue = n.longValue();
        if (longValue > Integer.MAX_VALUE || longValue < Integer.MIN_VALUE) {
            throw new GroovyRuntimeException("Automatic coercion of " + n.getClass().getName()
                   + " value " + n + " to int failed.  Value is out of range.");
       }
       return new Integer(n.intValue());

which would then give the error message:

Caught: groovy.lang.GroovyRuntimeException: Automatic coercion of java.lang.Long value 2147483648 to int failed.  Value is out of range.
	at testBits.run(testBits.groovy:1282)
	at testBits.main(testBits.groovy)

But, perhaps the rounding is the exected behaviour if you consider this Java code:

Number n = new Integer(Integer.MAX_VALUE - 100);
System.out.println("n = " + n);
System.out.println("n.shortValue() = " + n.shortValue());

which produces:

n = 2147483547
n.shortValue() = -101
Show
Paul King added a comment - 15/Oct/07 2:54 AM - edited The code for this is easy, but it is not clear what the behaviour should be. The current code in DefaultTypeTransformation:
} else if (type == Integer.class) {
    return new Integer(n.intValue());
coudl be changed to:
} else if (type == Integer.class) {
        long longValue = n.longValue();
        if (longValue > Integer.MAX_VALUE || longValue < Integer.MIN_VALUE) {
            throw new GroovyRuntimeException("Automatic coercion of " + n.getClass().getName()
                   + " value " + n + " to int failed.  Value is out of range.");
       }
       return new Integer(n.intValue());
which would then give the error message:
Caught: groovy.lang.GroovyRuntimeException: Automatic coercion of java.lang.Long value 2147483648 to int failed.  Value is out of range.
	at testBits.run(testBits.groovy:1282)
	at testBits.main(testBits.groovy)
But, perhaps the rounding is the exected behaviour if you consider this Java code:
Number n = new Integer(Integer.MAX_VALUE - 100);
System.out.println("n = " + n);
System.out.println("n.shortValue() = " + n.shortValue());
which produces:
n = 2147483547
n.shortValue() = -101
Hide
Permalink
Guillaume Laforge added a comment - 02/Nov/07 7:02 AM

Please reopen if it's still an issue.

Show
Guillaume Laforge added a comment - 02/Nov/07 7:02 AM Please reopen if it's still an issue.

People

  • Assignee:
    Guillaume Laforge
    Reporter:
    Brian Larson
Vote (0)
Watch (0)

Dates

  • Created:
    14/Mar/04 5:07 PM
    Updated:
    02/Nov/07 7:02 AM
    Resolved:
    02/Nov/07 7:02 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.