Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: as long as we're fixing code, we don't need 'static'

...

Code Block
bgColor#FFcccc
class LongContainer {
  private static long i = 0;

  static void one(long j) {
    i = j; 
  }

  static void two() {
    System.out.println("i = " + i);
  }
}

...

Code Block
bgColor#ccccff
class LongContainer {
  private static volatile long i = 0;
 
  static void one(long j) { 
    i = j; 
  }
 
  static void two() {
    System.out.println("i = " + i);
  }
}

It is important to ensure that the argument to method one() is obtained from a volatile variable or as a result of explicitly passing an integer value. Otherwise, a read of the variable argument may itself expose a vulnerability.

...