Skip to content

Commit

Permalink
Upgrade Error Prone
Browse files Browse the repository at this point in the history
  • Loading branch information
liblit committed Sep 2, 2023
1 parent 1b7c4c8 commit 44df486
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ eclipse-ecj = "org.eclipse.jdt:ecj:3.21.0"
eclipse-osgi = "org.eclipse.platform:org.eclipse.osgi:3.17.0"
eclipse-wst-jsdt-core = { module = "org.eclipse.wst.jsdt:core", version.ref = "eclipse-wst-jsdt" }
eclipse-wst-jsdt-ui = { module = "org.eclipse.wst.jsdt:ui", version.ref = "eclipse-wst-jsdt" }
errorprone-core = "com.google.errorprone:error_prone_core:2.18.0"
errorprone-core = "com.google.errorprone:error_prone_core:2.21.1"
gradle-goomph-plugin = "com.diffplug.gradle:goomph:3.42.2"
gradle-download-task = "de.undercouch:gradle-download-task:5.5.0"
gradle-errorprone-plugin = "net.ltgt.gradle:gradle-errorprone-plugin:3.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private static List<Pair<CGNode, SSACheckCastInstruction>> findFailingCasts(
if (ir == null) continue;
SSAInstruction[] instrs = ir.getInstructions();
for (SSAInstruction instr : instrs) {
if (numSafe + numMightFail > MAX_CASTS) break outer;
if ((long) numSafe + numMightFail > MAX_CASTS) break outer;
SSAInstruction instruction = instr;
if (instruction instanceof SSACheckCastInstruction) {
SSACheckCastInstruction castInstr = (SSACheckCastInstruction) instruction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ public class ImmutableStack<T> implements Iterable<T> {

private static final int MAX_SIZE = Integer.MAX_VALUE;

/**
* Checks whether the given size would exceed {@link #MAX_SIZE}.
*
* <p>In a standard WALA build, {@link #MAX_SIZE} is {@link Integer#MAX_VALUE}, and therefore this
* check must always return {@code true}. For that reason, Error Prone warns about a {@code
* ComparisonOutOfRange}. However, one might choose to change how {@link #MAX_SIZE} is
* initialized, thereby creating the possibility for this check to return {@code fail}. We want to
* retain that as an option, so we still perform this check and use {@link SuppressWarnings} to
* suppress the Error Check warning.
*
* @param proposedSize possible new size
* @return true if the proposed size would exceed {@link #MAX_SIZE}
*/
@SuppressWarnings("ComparisonOutOfRange")
private static boolean isWithinSizeLimit(final int proposedSize) {
return proposedSize <= MAX_SIZE;
}

public static int getMaxSize() {
return MAX_SIZE;
}
Expand Down Expand Up @@ -97,7 +115,7 @@ public ImmutableStack<T> push(T entry) {
}
int size = entries.length + 1;
T[] tmpEntries = null;
if (size <= MAX_SIZE) {
if (isWithinSizeLimit(size)) {
tmpEntries = makeInternalArray(size);
System.arraycopy(entries, 0, tmpEntries, 0, entries.length);
tmpEntries[size - 1] = entry;
Expand Down Expand Up @@ -161,7 +179,7 @@ public T get(int i) {
@Override
public String toString() {
String objArrayToString = Arrays.toString(entries);
assert entries.length <= MAX_SIZE : objArrayToString;
assert isWithinSizeLimit(entries.length) : objArrayToString;
return objArrayToString;
}

Expand Down Expand Up @@ -220,7 +238,7 @@ public ImmutableStack<T> pushAll(ImmutableStack<T> other) {
}
int size = entries.length + other.entries.length;
T[] tmpEntries = null;
if (size <= MAX_SIZE) {
if (isWithinSizeLimit(size)) {
tmpEntries = (T[]) new Object[size];
System.arraycopy(entries, 0, tmpEntries, 0, entries.length);
System.arraycopy(other.entries, 0, tmpEntries, entries.length, other.entries.length);
Expand Down

0 comments on commit 44df486

Please sign in to comment.