Created
June 2, 2014 16:50
-
-
Save mcy/9b1a0e6fad89a0c7d2d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Field; | |
import java.lang.reflect.Modifier; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.List; | |
public class DestroyInt { | |
public static void main(String[] args) throws Throwable { | |
Class<?> cache = Integer.class.getDeclaredClasses()[0]; | |
Field c = cache.getDeclaredField("cache"); | |
nonFinal(c); | |
c.setAccessible(true); | |
Integer[] array = (Integer[]) c.get(null); | |
array = array.clone(); | |
List<Integer> list = Arrays.asList(array); | |
Collections.shuffle(list); | |
c.set(null, list.toArray(new Integer[list.size()])); | |
System.out.printf("2 + 2 = %d", 2 + 2); | |
} | |
public static void nonFinal(Field f) throws Throwable{ | |
Field mod = Field.class.getDeclaredField("modifiers"); | |
mod.setAccessible(true); | |
mod.setInt(f, f.getModifiers() & ~Modifier.FINAL); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment