A little while back, we had a Bring Your own Code called The Disgruntled Bomb that sought to answer, "what is the worst thing a disgruntled employee could leave behind in the source code?"

The comments were great and featured all sorts of solutions. Most were in C and C++, but there were few unique ones like a cronjob and even an incredible one-liner for .NET.

While C and C++ give programmers enough rope to shoot themselves (or build a crazy bomb), managed platforms like .NET and Java limit your options. That is, unless you know where to look. Alexander Keul took advantage of Java's cached boxing conversions to come up with this concept:

package dont.try_this.at_home;
import java.lang.*;

class ValueMunger extends Thread {
    public void run() {
        while(true) {
            try { sleep(1000); } catch (Throwable t) { }
    public void munge() {
        try {
            Field field = Integer.class.getDeclaredField( "value" );
            field.setAccessible( true );
            for(int i = -127; i<=128; i++)
                // either the same (90%), +1 (10%), or 42 (1%)
                Math.random() < 0.9 ? i : Math.random() < 0.1 ? 42 : i+1  );
        } catch (Throwable t) { ; }


A simple call to (new ValueMunger()).start(); will spin off a new thread that will randomly redefines the values of integers between -127 and 128, ensuring that maths will never be the same again:

Integer a = 2;
Integer b = 3;

System.out.println( a + b ); // could be 5, 6, 7, 44, 45, or 84 

To extend the fun, this works for Boolean and several other primative types like BigInteger, Long, Short, etc.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!