Bug 36857

Summary: Using the operator += with a String on the right side results in a compile error.
Product: [Eclipse Project] JDT Reporter: Robert Baccus <rbaccus>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 2.1   
Target Milestone: 3.0 M1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Robert Baccus CLA 2003-04-24 13:25:06 EDT
The following code segment will fail to compile using the Eclipse JDT.

	int[] intArray;
	Object[] oa = hash.keySet().toArray();
	Arrays.sort(oa); // mmmmm, Java.util.Arrays 
	for (int i=0; i< oa.length; i++) {
	    intArray=(int[])hash.get(oa[i]);
	    int rowTotal = intArray[0] + intArray[1] + intArray[2];
	    while (((String) oa[i]).length() < 4) { // pad w/ leading '0's as 
needed
		oa[i]= "0" + oa[i];
	    }
FAILS	    oa[i] += "     |   " + rowTotal + "   |";
	    for (int j=0; j<intArray.length-1; j++) {
FAILS		oa[i] += "     " + intArray[j] + "    ";
	    }
FAILS	    oa[i] += "|     " + intArray[intArray.length-1] + "/" + (rowTotal-
intArray[intArray.length-1]);
	    System.out.println(oa[i]);
	}
	System.out.println();
    }

The error message is 
"The operator += is undefined for the argument type(s) Object, String"


When compiled using ANT with JDK1.4.1_02 this compiles and runs without errors.
Comment 1 Olivier Thomann CLA 2003-04-24 16:02:33 EDT
This is a bug in javac 1.4.1_02 which has been fixed in 1.4.2_b19.

D:\temp>java -version
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)

D:\temp>javac X1.java
X1.java:17: incompatible types
found   : java.lang.Object
required: java.lang.String
                        oa[i] += "     |   " + rowTotal + "   |";
                          ^
X1.java:19: incompatible types
found   : java.lang.Object
required: java.lang.String
                                oa[i] += "     " + intArray[j] + "    ";
                                  ^
X1.java:21: incompatible types
found   : java.lang.Object
required: java.lang.String
                        oa[i] += "|     "
                          ^
3 errors

See http://developer.java.sun.com/developer/bugParade/bugs/4642850.html for
further reference.

Closed as INVALID.