Skip to content

Commit

Permalink
Update usage of Errorprone and also warnings
Browse files Browse the repository at this point in the history
Add warnings for unused imports, star imports, and possible Android
incompatibilities.

Remove checkstyle!
  • Loading branch information
gbrail committed Sep 24, 2024
1 parent 2eccdd1 commit 7050923
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 207 deletions.
10 changes: 9 additions & 1 deletion buildSrc/src/main/groovy/rhino.library-conventions.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'rhino.java-conventions'
id 'maven-publish'
id 'checkstyle'
id 'jacoco'
id 'net.ltgt.errorprone'
}
Expand Down Expand Up @@ -50,6 +49,15 @@ tasks.withType(JavaCompile).configureEach {
// This one either alerts for parameters that we don't use,
// or spuriously for local variables in my opinion.
"UnusedVariable")
options.errorprone.enable(
// These two do the last thing that Checkstyle used to do for us
"RemoveUnusedImports",
"WildcardImport",
// Warn us proactively that we are using things that might not work on Android.
// We will aggressively used "SuppressWarnings" for these, but these can be
// a reminder to check with an Android user since we don't have automated
// Android unit tests.
"AndroidJdkLibsChecker")
options.errorprone.excludedPaths = '.+/src/test/java/.+'
}

Expand Down
200 changes: 0 additions & 200 deletions config/checkstyle/checkstyle.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ public static Object doctest(Context cx, Scriptable thisObj, Object[] args, Func
return global.runDoctest(cx, global, session, null, 0);
}

@SuppressWarnings("AndroidJdkLibsChecker")
public int runDoctest(
Context cx, Scriptable scope, String session, String sourceName, int lineNumber) {
doctestCanonicalizations = new HashMap<String, String>();
Expand Down Expand Up @@ -601,6 +602,7 @@ public static Object sync(Context cx, Scriptable thisObj, Object[] args, Functio
* <li><code>dir</code> - the working direcotry to run the commands.
* </ul>
*/
@SuppressWarnings("AndroidJdkLibsChecker")
public static Object runCommand(Context cx, Scriptable thisObj, Object[] args, Function funObj)
throws IOException {
int L = args.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.swing.UIManager;
import org.mozilla.javascript.SecurityUtilities;

@SuppressWarnings("AndroidJdkLibsChecker")
public class JSConsole extends JFrame implements ActionListener {
static final long serialVersionUID = 2551225560631876300L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ private static Class<?> getAdapterClass(
return adapterClass;
}

@SuppressWarnings("AndroidJdkLibsChecker")
public static byte[] createAdapterCode(
Map<String, Integer> functionNames,
String adapterName,
Expand Down
4 changes: 3 additions & 1 deletion rhino/src/main/java/org/mozilla/javascript/JavaMembers.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ private Method[] discoverAccessibleMethods(
return map.values().toArray(new Method[0]);
}

@SuppressWarnings("deprecation")
private void discoverAccessibleMethods(
Class<?> clazz,
Map<MethodSignature, Method> map,
Expand Down Expand Up @@ -656,6 +657,7 @@ private Constructor<?>[] getAccessibleConstructors(boolean includePrivate) {
return cl.getConstructors();
}

@SuppressWarnings("deprecation")
private Field[] getAccessibleFields(boolean includeProtected, boolean includePrivate) {
if (includePrivate || includeProtected) {
try {
Expand All @@ -669,7 +671,7 @@ private Field[] getAccessibleFields(boolean includeProtected, boolean includePri
for (Field field : declared) {
int mod = field.getModifiers();
if (includePrivate || isPublic(mod) || isProtected(mod)) {
field.trySetAccessible();
if (!field.isAccessible()) field.setAccessible(true);
fieldsList.add(field);
}
}
Expand Down
1 change: 1 addition & 0 deletions rhino/src/main/java/org/mozilla/javascript/NativeDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* <p>Significant parts of this code are adapted from the venerable jsdate.cpp (also Mozilla):
* https://dxr.mozilla.org/mozilla-central/source/js/src/jsdate.cpp
*/
@SuppressWarnings("AndroidJdkLibsChecker")
final class NativeDate extends IdScriptableObject {
private static final long serialVersionUID = -8307438915861678966L;

Expand Down
3 changes: 3 additions & 0 deletions rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -3166,6 +3166,7 @@ public static Number multiply(Integer i1, Integer i2) {
return Double.valueOf((double) r);
}

@SuppressWarnings("AndroidJdkLibsChecker")
public static Number exponentiate(Number val1, Number val2) {
if (val1 instanceof BigInteger && val2 instanceof BigInteger) {
if (((BigInteger) val2).signum() == -1) {
Expand Down Expand Up @@ -3225,6 +3226,7 @@ public static Number bitwiseXOR(Number val1, Number val2) {
}
}

@SuppressWarnings("AndroidJdkLibsChecker")
public static Number leftShift(Number val1, Number val2) {
if (val1 instanceof BigInteger && val2 instanceof BigInteger) {
try {
Expand All @@ -3244,6 +3246,7 @@ public static Number leftShift(Number val1, Number val2) {
}
}

@SuppressWarnings("AndroidJdkLibsChecker")
public static Number signedRightShift(Number val1, Number val2) {
if (val1 instanceof BigInteger && val2 instanceof BigInteger) {
try {
Expand Down
1 change: 1 addition & 0 deletions rhino/src/main/java/org/mozilla/javascript/SlotMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
public interface SlotMap extends Iterable<Slot> {

@SuppressWarnings("AndroidJdkLibsChecker")
@FunctionalInterface
public interface SlotComputer<S extends Slot> {
S compute(Object key, int index, Slot existing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* This class extends the SlotMapContainer so that we have thread-safe access to all the properties
* of an object.
*/
@SuppressWarnings("AndroidJdkLibsChecker")
class ThreadSafeSlotMapContainer extends SlotMapContainer {

private final StampedLock lock = new StampedLock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ private static int stringToKeywordForES(String name, boolean isStrict) {
return id & 0xff;
}

@SuppressWarnings("AndroidJdkLibsChecker")
private static boolean isValidIdentifierName(String str) {
int i = 0;
for (int c : str.codePoints().toArray()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ protected void setContext(Object contextHelper, Context cx) {
storage[0] = cx;
}

@SuppressWarnings("deprecation")
@Override
protected boolean tryToMakeAccessible(AccessibleObject accessible) {
return accessible.trySetAccessible();
if (!accessible.isAccessible()) {
accessible.setAccessible(true);
}
return true;
}

@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ private static AstRoot parseStrict(String source, ErrorReporter reporter, boolea
return parser.parse(source, SOURCE_NAME, 1);
}

@SuppressWarnings("deprecation")
private static AstRoot parseStrict(Reader source, ErrorReporter reporter, boolean ide)
throws IOException {
Parser parser = new Parser(compilerEnv(reporter, ide));
Expand All @@ -544,6 +545,7 @@ public DataMap(Class<K> keyType) {
super(keyType);
}

@SuppressWarnings("unchecked")
public DataMap<K, V> putAll(V v, K... ks) {
for (K k : ks) {
put(k, v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

public class JavaIterableTest {

@SuppressWarnings("unchecked")
@Test
public void map() {
Map<Object, Object> map = new LinkedHashMap<>();
Expand Down
Loading

0 comments on commit 7050923

Please sign in to comment.