Eclipse debugger, at least version 3.4.x, allows changing final primitive value. Classes like
Boolean
or
Integer
are build upon immutability, so any change of the immutable field will have insidious effect on all the places where the same instance is used:
final Boolean tru = Boolean.TRUE;
final Integer ONE = Integer.valueOf( 1 );
final Integer one = Integer.valueOf( 1 );
System.out.println( String.format( "value: %b, Boolean.TRUE: %b, one: %d, ONE: %d",
true, Boolean.TRUE, one, ONE ) );
// now change value of 'tru.value' to false and one.value to 0 in debugger
System.out.println( String.format( "value: %b, Boolean.TRUE: %b, one: %d, ONE: %d",
true, Boolean.TRUE, one, ONE ) );
Output will be:
value: true, Boolean.TRUE: true, one: 1, ONE: 1
value: true, Boolean.TRUE: true, one: 0, ONE: 0
Do you think that this is good idea? IntelliJ IDEA doesn't allow that and I think they are right. Even if you really know what you are doing, there is still more subtle hidden problem, the change of final value may not be propagated to all running threads.