Bug 82647

Summary: [compiler][1.5] Erroneous error with autoboxing and conditional operand
Product: [Eclipse Project] JDT Reporter: R Lenard <rlenard>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M5   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

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