title: Is there a limit to overriding final static field with Reflection?
body: <p>I have been faced in some of my Unit test with a strange behaviour with Reflection on final static field. Below is an example illustrating my issue.</p>
  
  <p>I have a basic Singleton class that holds an Integer</p>
  
  <pre><code>public class BasicHolder {
      private static BasicHolder instance = new BasicHolder();
  
      public static BasicHolder getInstance() {
          return instance;
      }
  
      private BasicHolder() {
      }
  
      private final static Integer VALUE = new Integer(0);
  
      public Integer getVALUE() {
          return VALUE;
      }
  
  }
  </code></pre>
  
  <p>My test case is looping and setting through Reflection the VALUE to the iteration index and then asserting that the VALUE is rightfully equal to the iteration index.</p>
  
  <pre><code>class TestStaticLimits {
      private static final Integer NB_ITERATION = 10_000;
  
      @Test
      void testStaticLimit() {
  
          for (Integer i = 0; i &lt; NB_ITERATION; i++) {
              setStaticFieldValue(BasicHolder.class, "VALUE", i);
              Assertions.assertEquals(i, BasicHolder.getInstance().getVALUE(), "REFLECTION DID NOT WORK for iteration "+i);
              System.out.println("iter " + i + " ok" );
  
          }
      }
  
      private static void setStaticFieldValue(final Class obj, final String fieldName, final Object fieldValue) {
          try {
              final Field field = obj.getDeclaredField(fieldName);
              field.setAccessible(true);
              final Field modifiersField = Field.class.getDeclaredField("modifiers");
              modifiersField.setAccessible(true);
              modifiersField.setInt(field, field.getModifiers() &amp; ~Modifier.FINAL);
              field.set(null, fieldValue);
          } catch (NoSuchFieldException | IllegalAccessException e) {
              throw new RuntimeException("Error while setting field [" + fieldName + "] on object " + obj + " Message " + e.getMessage(), e);
          }
      }
  
  }
  </code></pre>
  
  <p>The result is quite surprising because it's not constant,
  my test fails around iteration ~1000 but it never seems to be always the same.</p>
  
  <p>Anyone has already faced this issue ?</p>