Java 8 and up you can call Math.toIntExact():
import static java.lang.Math.toIntExact;
long longVal = 1L;
int intVal = toIntExact(longVal);
Otherwise you can rewrite your code as follows:
public static int safeLongToInt(long l) {
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
throw new IllegalArgumentException
(l + " cannot be cast to int without changing its value.");
}
return (int) l;
}