Created
September 18, 2017 12:12
-
-
Save WouterG/7c7581a8740d06b158783f142be6282a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public void properFecked() throws Exception { | |
| Class integerCacheClass = Class.forName("java.lang.Integer$IntegerCache"); | |
| Field cacheField = integerCacheClass.getDeclaredField("cache"); | |
| if (Modifier.isFinal(cacheField.getModifiers())) { | |
| Field modifiersField = Field.class.getDeclaredField("modifiers"); | |
| modifiersField.setAccessible(true); | |
| modifiersField.set(cacheField, cacheField.getModifiers() - Modifier.FINAL); | |
| } | |
| if (!cacheField.isAccessible()) { | |
| cacheField.setAccessible(true); | |
| } | |
| Integer[] cache = (Integer[]) cacheField.get(null); | |
| System.out.println("got cache. Fucking it up"); | |
| for (int i = 0; i < cache.length; i++) { | |
| cache[i] = cache[i] * 2; | |
| } | |
| System.out.println("writing cache back"); | |
| cacheField.set(null, cache); | |
| for (int i = 0; i < 100; i++) { | |
| System.out.println(String.format("Integer.valueOf(%d): %d")); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment