JDK-6646584 : Compound assignment with Byte, Short and Character
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-01-02
  • Updated: 2011-02-16
  • Resolved: 2008-01-30
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05)
Java HotSpot(TM) Client VM (build 1.5.0_13-b05, mixed mode, sharing)



A DESCRIPTION OF THE PROBLEM :
javac forbids compound assignment if lhs is of type Byte, Short, Character. However, it allows compound assignment for other wrappers and increment/decrement for all wrappers.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile attached source code

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
no compilation errors
ACTUAL -
Main.java:10: inconvertible types
found   : int
required: java.lang.Byte
                v += 1; // should be ok
                     ^
Main.java:23: inconvertible types
found   : int
required: java.lang.Short
                v += 1; // should be ok
                     ^
Main.java:36: inconvertible types
found   : int
required: java.lang.Character
                v += 1; // should be ok
                     ^
3 errors

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Main {

	public void assignop_byte(byte v) {
		v += 1;
	}
	public void inc_byte(byte v) {
		++v;
	}
	public void assignop_Byte(Byte v) {
		v += 1; // should be ok
	}
	public void inc_Byte(Byte v) {
		++v;
	}

	public void assignop_short(short v) {
		v += 1;
	}
	public void inc_short(short v) {
		++v;
	}
	public void assignop_Short(Short v) {
		v += 1; // should be ok
	}
	public void inc_Short(Short v) {
		++v;
	}

	public void assignop_char(char v) {
		v += 1;
	}
	public void inc_char(char v) {
		++v;
	}
	public void assignop_Character(Character v) {
		v += 1; // should be ok
	}
	public void inc_Character(Character v) {
		++v;
	}

	public void assignop_int(int v) {
		v += 1;
	}
	public void inc_int(int v) {
		++v;
	}
	public void assignop_Integer(Integer v) {
		v += 1;
	}
	public void inc_Integer(Integer v) {
		++v;
	}

	public void assignop_long(long v) {
		v += 1;
	}
	public void inc_long(long v) {
		++v;
	}
	public void assignop_Long(Long v) {
		v += 1;
	}
	public void inc_Long(Long v) {
		++v;
	}

	public void assignop_float(float v) {
		v += 1;
	}
	public void inc_float(float v) {
		++v;
	}
	public void assignop_Float(Float v) {
		v += 1;
	}
	public void inc_Float(Float v) {
		++v;
	}

	public void assignop_double(double v) {
		v += 1;
	}
	public void inc_double(double v) {
		++v;
	}
	public void assignop_Double(Double v) {
		v += 1;
	}
	public void inc_Double(Double v) {
		++v;
	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
do not use compound assignment for specifed wrapper types