Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: fixed compilation errors in NCE/CS(addition)

...

Code Block
bgColor#FFcccc
private volatile int a;
private volatile int b;

public int getSum() throws ArithmeticException {
  // Check for integer overflow
  if( b > 0 ? a > Integer.MAX_VALUE - b : a < Integer.MIN_VALUE - b ) { 
    throw new ArithmeticException("Not in range");
  }

  return a + b;
}

public intvoid setValues(int a, int b) {
  this.a = a;
  this.b = b;
}

...

Code Block
bgColor#ccccff
private volatile int a;
private volatile int b;

public synchronized int getSum() throws ArithmeticException {
  // Check for integer overflow
  if( b > 0 ? a > Integer.MAX_VALUE - b : a < Integer.MIN_VALUE - b ) { 
    throw new ArithmeticException("Not in range");
  }

  return a + b;
}

public synchronized intvoid setValues(int a, int b) {
  this.a = a;
  this.b = b;
}

...