Skip to content

Commit

Permalink
Update plugin versions and support Java 21 build
Browse files Browse the repository at this point in the history
Update spotbugs and add necessary exclusions
  Fix one small thing in Context that was making it upset
Update other plugins
Make spotless work -- currently only runs on Java 11
  • Loading branch information
gbrail committed May 24, 2024
1 parent 8b57367 commit 61ef39d
Show file tree
Hide file tree
Showing 23 changed files with 63 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
# Some tests require more CPU, and all can use multiple CPUs
max-parallel: 1
matrix:
java: [ '11', '17' ]
java: [ '11', '17', '21' ]
name: Rhino Java ${{ matrix.java }}
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ repositories {

dependencies {
implementation 'com.diffplug.spotless:spotless-plugin-gradle:6.25.0'
implementation 'com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.14'
implementation 'com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.15'
}
12 changes: 9 additions & 3 deletions buildSrc/src/main/groovy/rhino.java-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ test {
}

spotless {
java {
// Newer versions of GoogleJavaFormat seem to require JDK 15+
googleJavaFormat('1.10.0').aosp()
// There is no version of googleJavaFormat that works for Java 11 and 17,
// and different versions format differently. For now, only run spotless on Java 11.
// This will have to be changed when Java 11 support is removed.
if (JavaVersion.current() == JavaVersion.VERSION_11) {
java {
googleJavaFormat('1.10.0').aosp()
}
} else {
System.out.println("Not running Spotless: Java language version is " + JavaVersion.current())
}
}
7 changes: 5 additions & 2 deletions buildSrc/src/main/groovy/rhino.library-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ plugins {
id 'com.github.spotbugs'
}

import com.github.spotbugs.snom.Confidence
import com.github.spotbugs.snom.Effort

version = project.version

tasks.named('compileJava') {
Expand All @@ -21,8 +24,8 @@ tasks.withType(Jar).configureEach {
}

spotbugs {
effort = "less"
reportLevel = "medium"
effort = Effort.valueOf('LESS')
reportLevel = Confidence.valueOf('MEDIUM')
excludeFilter = file("${projectDir}/../spotbugs-exclude.xml")
}

Expand Down
1 change: 1 addition & 0 deletions examples/src/main/java/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class File extends ScriptableObject {

/** */
private static final long serialVersionUID = 2549960399774237828L;

/**
* The zero-parameter constructor.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ClassCache implements Serializable {
static class CacheKey {
final Class<?> cls;
final Object sec;

/** Constructor. */
public CacheKey(Class<?> cls, Object securityContext) {
this.cls = cls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void initFromContext(Context cx) {
activationNames = cx.activationNames;

// Observer code generation in compiled code :
generateObserverCount = cx.generateObserverCount;
generateObserverCount = cx.isGenerateObserverCount();
}

public final ErrorReporter getErrorReporter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,11 @@ public void setGenerateObserverCount(boolean generateObserverCount) {
this.generateObserverCount = generateObserverCount;
}

/** Determine if observer counts should be generated. */
public boolean isGenerateObserverCount() {
return this.generateObserverCount;
}

/**
* Allow application to monitor counter of executed script instructions in Context subclasses.
* Run-time calls this when instruction counting is enabled and the counter reaches limit set by
Expand Down Expand Up @@ -2711,7 +2716,7 @@ public static boolean isCurrentContextStrict() {
Scriptable scratchScriptable;

// Generate an observer count on compiled code
public boolean generateObserverCount = false;
boolean generateObserverCount = false;

boolean isTopLevelStrict;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public class LambdaConstructor extends LambdaFunction {

/** If this flag is set, the constructor may be invoked as an ordinary function */
public static final int CONSTRUCTOR_FUNCTION = 1;

/** If this flag is set, the constructor may be invoked using "new" */
public static final int CONSTRUCTOR_NEW = 1 << 1;

/** By default, the constructor may be invoked either way */
public static final int CONSTRUCTOR_DEFAULT = CONSTRUCTOR_FUNCTION | CONSTRUCTOR_NEW;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ static int findFunction(Context cx, MemberBox[] methodsOrCtors, Object[] args) {

private static final int PREFERENCE_FIRST_ARG = 1;
private static final int PREFERENCE_SECOND_ARG = 2;

/** No clear "easy" conversion */
private static final int PREFERENCE_AMBIGUOUS = 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ static class NoSuchMethodShim implements Callable {
this.noSuchMethodMethod = noSuchMethodMethod;
this.methodName = methodName;
}

/**
* Perform the call.
*
Expand All @@ -94,6 +95,7 @@ public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] ar
return noSuchMethodMethod.call(cx, scope, thisObj, nestedArgs);
}
}

/*
* There's such a huge space (and some time) waste for the Foo.class
* syntax: the compiler sticks in a test of a static field in the
Expand Down Expand Up @@ -2536,6 +2538,7 @@ public static boolean loadFromIterable(
}
return true;
}

/**
* Prepare for calling name(...): return function corresponding to name and make current top
* scope available as ScriptRuntime.lastStoredScriptable() for consumption as thisObj. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public abstract class ScriptableObject
public static final int UNINITIALIZED_CONST = 0x08;

public static final int CONST = PERMANENT | READONLY | UNINITIALIZED_CONST;

/** The prototype of this object. */
private Scriptable prototypeObject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public abstract class AstNode extends Node implements Comparable<AstNode> {

public static class PositionComparator implements Comparator<AstNode>, Serializable {
private static final long serialVersionUID = 1L;

/**
* Sorts nodes by (relative) start position. The start positions are relative to their
* parent, so this comparator is only meaningful for comparing siblings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public interface DebugFrame {
* @param args the array of arguments
*/
public void onEnter(Context cx, Scriptable activation, Scriptable thisObj, Object[] args);

/**
* Called when executed code reaches new line in the source.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public abstract class NativeArrayBufferView extends IdScriptableObject {

/** Many view objects can share the same backing array */
protected final NativeArrayBuffer arrayBuffer;

/** The offset, in bytes, from the start of the backing array */
protected final int offset;

/** The length, in bytes, of the portion of the backing array that we use */
protected final int byteLength;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
public class JTreeTable extends JTable {
/** */
private static final long serialVersionUID = -2103973006456695515L;

/** A subclass of JTree. */
protected TreeTableCellRenderer tree;

Expand Down Expand Up @@ -143,6 +144,7 @@ public JTree getTree() {
/** A TreeCellRenderer that displays a JTree. */
public class TreeTableCellRenderer extends JTree implements TableCellRenderer {
private static final long serialVersionUID = -193867880014600717L;

/** Last table/tree row asked to renderer. */
protected int visibleRow;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public String[] processOptions(String args[]) {
p(ToolErrorReporter.getMessage("msg.no.file"));
return null;
}

/** Print a usage message. */
private static void badUsage(String s) {
System.err.println(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ protected int findInstanceIdInfo(String s) {
}
return instanceIdInfo(attr, super.getMaxInstanceId() + id);
}

// #/string_id_map#

@Override
Expand Down Expand Up @@ -192,6 +193,7 @@ protected int findPrototypeId(String s) {
// #/generated#
return id;
}

// #/string_id_map#

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ protected int findInstanceIdInfo(String s) {
}
return instanceIdInfo(attr, super.getMaxInstanceId() + id);
}

// #/string_id_map#

@Override
Expand Down Expand Up @@ -221,6 +222,7 @@ protected int findPrototypeId(String s) {
// #/generated#
return id;
}

// #/string_id_map#

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class XMLCtor extends IdFunctionObject {
private static final Object XMLCTOR_TAG = "XMLCtor";

private XmlProcessor options;

// private XMLLibImpl lib;

XMLCtor(XML xml, Object tag, int id, int arity) {
Expand Down Expand Up @@ -225,6 +226,7 @@ protected int findPrototypeId(String s) {
// #/generated#
return id;
}

// #/string_id_map#

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public boolean has(String name, Scriptable start) {
Context cx = Context.getCurrentContext();
return hasXMLProperty(lib.toXMLNameFromString(cx, name));
}

/** Implementation of ECMAScript [[Get]] */
@Override
public final Object get(Context cx, Object id) {
Expand All @@ -261,6 +262,7 @@ public Object get(String name, Scriptable start) {
Context cx = Context.getCurrentContext();
return getXMLProperty(lib.toXMLNameFromString(cx, name));
}

/** Implementation of ECMAScript [[Put]] */
@Override
public final void put(Context cx, Object id, Object value) {
Expand All @@ -280,6 +282,7 @@ public void put(String name, Scriptable start, Object value) {
Context cx = Context.getCurrentContext();
putXMLProperty(lib.toXMLNameFromString(cx, name), value);
}

/** Implementation of ECMAScript [[Delete]]. */
@Override
public final boolean delete(Context cx, Object id) {
Expand Down Expand Up @@ -650,6 +653,7 @@ protected int findPrototypeId(String s) {
// #/generated#
return id;
}

// #/string_id_map#

@Override
Expand Down
13 changes: 13 additions & 0 deletions spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@
<Class name="org.mozilla.javascript.optimizer.OptRuntime$GeneratorState"/>
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"/>
</Match>
<Match>
<!-- Don't want to break decades of other code -->
<Class name="org.mozilla.javascript.ContextFactory"/>
<Bug pattern="SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR"/>
</Match>
<Match>
<!-- Lots of constructors in Rhino throw exceptions. -->
<Bug pattern="CT_CONSTRUCTOR_THROW"/>
</Match>
<Match>
<!-- Our serialization calls lots and lots of methods -->
<Bug pattern="MC_OVERRIDABLE_METHOD_CALL_IN_READ_OBJECT"/>
</Match>

<!-- Things below are things that we aspire to fix! -->
<Match>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SecurityControllerTest {

/** Sets up the security manager and loads the "grant-all-java.policy". */
static void setupSecurityManager() {}

/** Setup the security */
@BeforeClass
public static void setup() throws Exception {
Expand Down

0 comments on commit 61ef39d

Please sign in to comment.