Bug 82647 - [compiler][1.5] Erroneous error with autoboxing and conditional operand
Summary: [compiler][1.5] Erroneous error with autoboxing and conditional operand
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-12 01:35 EST by R Lenard CLA
Modified: 2005-02-15 06:40 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description R Lenard CLA 2005-01-12 01:35:18 EST
For this code, notice that the autoboxing is not happening in 4 cases.  The 
error given is 
"Incompatible conditional operand types null and int"

The work around is to "force" the type conversion.

% cat Test.java
public class Test
{
    int counter = 0;

    public boolean wasNull()
    {
        return ++counter % 2 == 0;
    }

    private Byte getByte()
    {
        return (byte) 0;
    }

    private Short getShort()
    {
        return (short) 0;
    }

    private Long getLong()
    {
        return 0L;
    }

    private Integer getInt()
    {
        return 0; // autoboxed okay
    }

    // This should be the same as the second one.
    private Byte getBytey()
    {
        byte value = getByte();
        return wasNull() ? null : value;
    }

    private Byte getByteyNoBoxing()
    {
        byte value = getByte();
        return wasNull() ? null : (Byte)value;
    }

    // This should be the same as the second one.
    private Short getShorty()
    {
        short value = getShort();
        return wasNull() ? null : value;
    }

    private Short getShortyNoBoxing()
    {
        short value = getShort();
        return wasNull() ? null : (Short)value;
    }

    // This should be the same as the second one.
    private Long getLongy()
    {
        long value = getLong();
        return wasNull() ? null : value;
    }

    private Long getLongyNoBoxing()
    {
        long value = getLong();
        return wasNull() ? null : (Long)value;
    }

    // This should be the same as the second one.
    private Integer getIntegery()
    {
        int value = getInt();
        return wasNull() ? null : value;
    }

    private Integer getIntegeryNoBoxing()
    {
        int value = getInt();
        return wasNull() ? null : (Integer)value;
    }
}
Comment 1 Philipe Mulet CLA 2005-01-29 08:12:30 EST
Reproduced
Comment 2 Philipe Mulet CLA 2005-02-02 15:41:29 EST
Added AutoboxingTest#test083
Fixed
Comment 3 Jerome Lanneluc CLA 2005-02-15 06:40:04 EST
Verified in I20050214