You are here

Eclipse debugger can change final primitive value

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.

Comments

It's good to know that eclipse does that. I've had interesting scenario because of that today. I've changed one Boolean value from false to true and it didn't affect only my application but the whole application server (I'm using WAS CE). Every configuration option changed from false to true and everything suddenly stopped working. Actually I had to reinstall WASCE one more time because it was easier then search for every configuration file and revert all changes. Changing value during debug is scary stuff :]

Thanks for sharing your funny story about insidious effects :-)