Skip to content

Instantly share code, notes, and snippets.

@renatoapcosta
Created April 18, 2021 17:01
Show Gist options
  • Save renatoapcosta/aa3d6b0dbd844f40e9e06df583d43744 to your computer and use it in GitHub Desktop.
Save renatoapcosta/aa3d6b0dbd844f40e9e06df583d43744 to your computer and use it in GitHub Desktop.
Java Bug

Java Bug

2 + 2 = 5

import java.lang.reflect.Field;

public class Main {
  public static void main(String[] args) throws Exception{
    Class cache = Integer.class.getDeclaredClasses()[0];
    Field c = cache.getDeclaredField("cache");
    c.setAccessible(true);
    Integer[] array = (Integer[]) c.get(cache);
    array[132] = array[133];

    System.out.printf("%d",2+2);
    System.out.println();

  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment