diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
index 79e92700c1..76de723ce5 100644
--- a/buildSrc/build.gradle
+++ b/buildSrc/build.gradle
@@ -8,5 +8,5 @@ repositories {
dependencies {
implementation 'com.diffplug.spotless:spotless-plugin-gradle:6.25.0'
- implementation 'com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.15'
+ implementation 'net.ltgt.gradle:gradle-errorprone-plugin:4.0.0'
}
diff --git a/buildSrc/src/main/groovy/rhino.library-conventions.gradle b/buildSrc/src/main/groovy/rhino.library-conventions.gradle
index 39934b335c..3f98be524e 100644
--- a/buildSrc/src/main/groovy/rhino.library-conventions.gradle
+++ b/buildSrc/src/main/groovy/rhino.library-conventions.gradle
@@ -1,13 +1,14 @@
plugins {
id 'rhino.java-conventions'
- id 'com.github.spotbugs'
id 'maven-publish'
id 'checkstyle'
id 'jacoco'
+ id 'net.ltgt.errorprone'
}
-import com.github.spotbugs.snom.Confidence
-import com.github.spotbugs.snom.Effort
+dependencies {
+ errorprone "com.google.errorprone:error_prone_core:2.28.0"
+}
version = project.version
@@ -26,20 +27,30 @@ tasks.withType(Jar).configureEach {
}
}
-spotbugs {
- effort = Effort.valueOf('LESS')
- reportLevel = Confidence.valueOf('MEDIUM')
- excludeFilter = file("${projectDir}/../config/spotbugs/spotbugs-exclude.xml")
-}
-
-spotbugsMain {
- reports {
- html {
- required = true
- outputLocation = file("$buildDir/reports/spotbugs/main/spotbugs.html")
- stylesheet = 'fancy-hist.xsl'
- }
- }
+tasks.withType(JavaCompile).configureEach {
+ options.errorprone.disable(
+ // JavaDoc stuff
+ "AlmostJavadoc",
+ "EmptyBlockTag",
+ "EscapedEntity",
+ "MissingSummary",
+ "InvalidBlockTag",
+ "InvalidLink",
+ "InvalidParam",
+ "NotJavadoc",
+ "UnicodeEscape",
+ // Great ideas for when minimum version is more than Java 11
+ "PatternMatchingInstanceof",
+ // Stuff that we just love to do but should do less of eventually
+ "EmptyCatch",
+ "LabelledBreakTarget",
+ "JavaUtilDate",
+ // Less important for now, more stylistic than bug
+ "InlineMeSuggester",
+ // This one either alerts for parameters that we don't use,
+ // or spuriously for local variables in my opinion.
+ "UnusedVariable")
+ options.errorprone.excludedPaths = '.+/src/test/java/.+'
}
jacocoTestReport {
diff --git a/config/spotbugs/spotbugs-exclude.xml b/config/spotbugs/spotbugs-exclude.xml
deleted file mode 100644
index 8f6e0e133a..0000000000
--- a/config/spotbugs/spotbugs-exclude.xml
+++ /dev/null
@@ -1,166 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/rhino-engine/src/main/java/org/mozilla/javascript/engine/Builtins.java b/rhino-engine/src/main/java/org/mozilla/javascript/engine/Builtins.java
index b3726dd4ec..ba1f1f3ae6 100644
--- a/rhino-engine/src/main/java/org/mozilla/javascript/engine/Builtins.java
+++ b/rhino-engine/src/main/java/org/mozilla/javascript/engine/Builtins.java
@@ -7,6 +7,7 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
import javax.script.ScriptContext;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
@@ -30,7 +31,7 @@ public class Builtins {
void register(Context cx, ScriptableObject scope, ScriptContext sc) {
if (sc.getWriter() == null) {
- stdout = new OutputStreamWriter(System.out);
+ stdout = new OutputStreamWriter(System.out, StandardCharsets.UTF_8);
} else {
stdout = sc.getWriter();
}
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java
index c4385c77f1..a1ec46c3b3 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/Dim.java
@@ -11,6 +11,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -78,10 +79,10 @@ public class Dim {
/**
* Synchronization object used to allow script evaluations to happen when a thread is resumed.
*/
- private Object monitor = new Object();
+ private final Object monitor = new Object();
/** Synchronization object used to wait for valid {@link #interruptedContextData}. */
- private Object eventThreadMonitor = new Object();
+ private final Object eventThreadMonitor = new Object();
/** The action to perform to end the interruption loop. */
private volatile int returnValue = -1;
@@ -254,11 +255,11 @@ private String loadSource(String sourceUrl) {
}
}
- is = (new URL(sourceUrl)).openStream();
+ is = new URL(sourceUrl).openStream();
}
try {
- source = Kit.readReader(new InputStreamReader(is));
+ source = Kit.readReader(new InputStreamReader(is, StandardCharsets.UTF_8));
} finally {
is.close();
}
@@ -1130,6 +1131,9 @@ public static class SourceInfo {
/** Array indicating whether a breakpoint is set on the line. */
private boolean[] breakpoints;
+ /** Lock for same */
+ private final Object breakpointsLock = new Object();
+
/** Array of FunctionSource objects for the functions in the script. */
private FunctionSource[] functionSources;
@@ -1260,7 +1264,7 @@ public boolean breakpoint(int line, boolean value) {
throw new IllegalArgumentException(String.valueOf(line));
}
boolean changed;
- synchronized (breakpoints) {
+ synchronized (breakpointsLock) {
if (breakpoints[line] != value) {
breakpoints[line] = value;
changed = true;
@@ -1273,7 +1277,7 @@ public boolean breakpoint(int line, boolean value) {
/** Removes all breakpoints from the script. */
public void removeAllBreakpoints() {
- synchronized (breakpoints) {
+ synchronized (breakpointsLock) {
for (int line = 0; line != breakpoints.length; ++line) {
breakpoints[line] = false;
}
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/SwingGui.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/SwingGui.java
index a56ae50021..3ec49246c8 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/SwingGui.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/debugger/SwingGui.java
@@ -21,7 +21,6 @@
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.MenuComponent;
-import java.awt.Point;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.Toolkit;
@@ -41,6 +40,8 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
@@ -48,6 +49,7 @@
import java.io.PrintStream;
import java.io.Reader;
import java.lang.reflect.Method;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -55,6 +57,7 @@
import java.util.EventObject;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
@@ -318,7 +321,7 @@ public boolean accept(File f) {
String n = f.getName();
int i = n.lastIndexOf('.');
if (i > 0 && i < n.length() - 1) {
- String ext = n.substring(i + 1).toLowerCase();
+ String ext = n.substring(i + 1).toLowerCase(Locale.ROOT);
if (ext.equals("js")) {
return true;
}
@@ -716,7 +719,7 @@ static void setResizeWeight(JSplitPane pane, double weight) {
private String readFile(String fileName) {
String text;
try {
- try (Reader r = new FileReader(fileName)) {
+ try (Reader r = new FileReader(fileName, StandardCharsets.UTF_8)) {
text = Kit.readReader(r);
}
} catch (IOException ex) {
@@ -834,9 +837,6 @@ public void actionPerformed(ActionEvent e) {
console.show();
desk.getDesktopManager().activateFrame(console);
console.consoleTextArea.requestFocus();
- } else if (cmd.equals("Cut")) {
- } else if (cmd.equals("Copy")) {
- } else if (cmd.equals("Paste")) {
} else if (cmd.equals("Go to function...")) {
FindFunction dlg = new FindFunction(this, "Go to function", "Function");
dlg.showDialog(this);
@@ -1010,6 +1010,7 @@ public void select(int start, int end) {
}
/** Called when Enter is pressed. */
+ @SuppressWarnings("CatchAndPrintStackTrace")
private synchronized void returnPressed() {
Document doc = getDocument();
int len = doc.getLength();
@@ -1335,26 +1336,27 @@ public void select(int pos) {
if (pos >= 0) {
try {
int line = getLineOfOffset(pos);
- Rectangle rect = modelToView(pos);
+ Rectangle2D rect = modelToView2D(pos);
if (rect == null) {
select(pos, pos);
} else {
try {
- Rectangle nrect = modelToView(getLineStartOffset(line + 1));
+ Rectangle2D nrect = modelToView2D(getLineStartOffset(line + 1));
if (nrect != null) {
rect = nrect;
}
} catch (Exception exc) {
}
JViewport vp = (JViewport) getParent();
- Rectangle viewRect = vp.getViewRect();
- if (viewRect.y + viewRect.height > rect.y) {
+ Rectangle2D viewRect = vp.getViewRect();
+ if (viewRect.getY() + viewRect.getHeight() > rect.getY()) {
// need to scroll up
select(pos, pos);
} else {
// need to scroll down
- rect.y += (viewRect.height - rect.height) / 2;
- scrollRectToVisible(rect);
+ double newY = rect.getY() + ((viewRect.getHeight() - rect.getHeight()) / 2);
+ rect.setRect(rect.getX(), newY, rect.getWidth(), rect.getHeight());
+ scrollRectToVisible(rect.getBounds());
select(pos, pos);
}
}
@@ -1421,7 +1423,7 @@ public void popupMenuCanceled(PopupMenuEvent e) {}
/** Performs an action. */
@Override
public void actionPerformed(ActionEvent e) {
- int pos = viewToModel(new Point(popup.x, popup.y));
+ int pos = viewToModel2D(new Point2D.Double(popup.x, popup.y));
popup.setVisible(false);
String cmd = e.getActionCommand();
int line = -1;
@@ -1511,7 +1513,7 @@ class MoreWindows extends JDialog implements ActionListener {
// model.fireIntervalAdded(model, 0, data.length);
setButton.setEnabled(true);
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
- list.addMouseListener(new MouseHandler());
+ list.addMouseListener(new MWMouseHandler());
JScrollPane listScroller = new JScrollPane(list);
listScroller.setPreferredSize(new Dimension(320, 240));
// XXX: Must do the following, too, or else the scroller thinks
@@ -1585,7 +1587,7 @@ public void actionPerformed(ActionEvent e) {
}
/** MouseListener implementation for {@link #list}. */
- private class MouseHandler extends MouseAdapter {
+ private class MWMouseHandler extends MouseAdapter {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
@@ -1640,7 +1642,7 @@ public FindFunction(SwingGui debugGui, String title, String labelText) {
setButton.setEnabled(a.length > 0);
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
- list.addMouseListener(new MouseHandler());
+ list.addMouseListener(new FFMouseHandler());
JScrollPane listScroller = new JScrollPane(list);
listScroller.setPreferredSize(new Dimension(320, 240));
listScroller.setMinimumSize(new Dimension(250, 80));
@@ -1725,7 +1727,7 @@ public void actionPerformed(ActionEvent e) {
}
/** MouseListener implementation for {@link #list}. */
- class MouseHandler extends MouseAdapter {
+ class FFMouseHandler extends MouseAdapter {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/jsc/Main.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/jsc/Main.java
index 058065e414..a34e18f747 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/jsc/Main.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/jsc/Main.java
@@ -304,7 +304,7 @@ String getClassName(String name) {
s[j] = '_';
}
}
- return (new String(s)).trim();
+ return new String(s).trim();
}
private static void p(String s) {
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/ConsoleTextArea.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/ConsoleTextArea.java
index 0ef70bdf72..acd0ae6bbd 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/ConsoleTextArea.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/ConsoleTextArea.java
@@ -14,6 +14,7 @@
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
@@ -39,11 +40,11 @@ public void run() {
class ConsoleWriter extends java.io.OutputStream {
private ConsoleTextArea textArea;
- private StringBuffer buffer;
+ private StringBuilder buffer;
public ConsoleWriter(ConsoleTextArea textArea) {
this.textArea = textArea;
- buffer = new StringBuffer();
+ buffer = new StringBuilder();
}
@Override
@@ -101,6 +102,7 @@ public void select(int start, int end) {
super.select(start, end);
}
+ @SuppressWarnings("CatchAndPrintStackTrace")
public ConsoleTextArea(String[] argv) {
super();
history = new java.util.ArrayList();
@@ -109,7 +111,7 @@ public ConsoleTextArea(String[] argv) {
out = new PrintStream(console1, true);
err = new PrintStream(console2, true);
PipedOutputStream outPipe = new PipedOutputStream();
- inPipe = new PrintWriter(outPipe);
+ inPipe = new PrintWriter(outPipe, false, StandardCharsets.UTF_8);
in = new PipedInputStream();
try {
outPipe.connect(in);
@@ -122,6 +124,7 @@ public ConsoleTextArea(String[] argv) {
setFont(new Font("Monospaced", 0, 12));
}
+ @SuppressWarnings("CatchAndPrintStackTrace")
synchronized void returnPressed() {
Document doc = getDocument();
int len = doc.getLength();
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/Global.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/Global.java
index a5031376ae..4164d82f2c 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/Global.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/Global.java
@@ -25,6 +25,7 @@
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -398,7 +399,7 @@ public static Object doctest(Context cx, Scriptable thisObj, Object[] args, Func
public int runDoctest(
Context cx, Scriptable scope, String session, String sourceName, int lineNumber) {
doctestCanonicalizations = new HashMap();
- String[] lines = session.split("\r\n?|\n");
+ String[] lines = session.split("\r\n?|\n", -1);
String prompt0 = this.prompts[0].trim();
String prompt1 = this.prompts[1].trim();
int testCount = 0;
@@ -446,7 +447,8 @@ public int runDoctest(
this.setOut(savedOut);
this.setErr(savedErr);
cx.setErrorReporter(savedErrorReporter);
- resultString += err.toString() + out.toString();
+ resultString +=
+ err.toString(StandardCharsets.UTF_8) + out.toString(StandardCharsets.UTF_8);
}
if (!doctestOutputMatches(expectedString.toString(), resultString)) {
String message =
@@ -698,11 +700,11 @@ public static Object runCommand(Context cx, Scriptable thisObj, Object[] args, F
int exitCode = runProcess(cmd, environment, wd, in, out, err);
if (outBytes != null) {
- String s = ScriptRuntime.toString(outObj) + outBytes.toString();
+ String s = ScriptRuntime.toString(outObj) + outBytes.toString(StandardCharsets.UTF_8);
ScriptableObject.putProperty(params, "output", s);
}
if (errBytes != null) {
- String s = ScriptRuntime.toString(errObj) + errBytes.toString();
+ String s = ScriptRuntime.toString(errObj) + errBytes.toString(StandardCharsets.UTF_8);
ScriptableObject.putProperty(params, "err", s);
}
@@ -983,7 +985,7 @@ private static InputStream toInputStream(Object value) throws IOException {
if (s == null) {
s = ScriptRuntime.toString(value);
}
- is = new ByteArrayInputStream(s.getBytes());
+ is = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
}
return is;
}
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/JSConsole.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/JSConsole.java
index e4c4a9f98b..d6dfdf88e1 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/JSConsole.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/JSConsole.java
@@ -10,6 +10,7 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
+import java.util.Locale;
import javax.swing.ButtonGroup;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
@@ -66,7 +67,7 @@ public boolean accept(File f) {
String name = f.getName();
int i = name.lastIndexOf('.');
if (i > 0 && i < name.length() - 1) {
- String ext = name.substring(i + 1).toLowerCase();
+ String ext = name.substring(i + 1).toLowerCase(Locale.ROOT);
if (ext.equals("js")) {
return true;
}
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/JavaPolicySecurity.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/JavaPolicySecurity.java
index 98bc6e452a..19d5b72eec 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/JavaPolicySecurity.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/JavaPolicySecurity.java
@@ -100,6 +100,7 @@ public Permission nextElement() {
}
@Override
+ @SuppressWarnings("ObjectToString")
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getName());
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/ShellConsole.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/ShellConsole.java
index 2cfc445144..87409ffbfd 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/ShellConsole.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/ShellConsole.java
@@ -15,6 +15,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Kit;
@@ -243,7 +244,7 @@ private static class SimpleShellConsole extends ShellConsole {
SimpleShellConsole(InputStream in, PrintStream ps, Charset cs) {
this.in = in;
- this.out = new PrintWriter(ps);
+ this.out = new PrintWriter(ps, false, StandardCharsets.UTF_8);
this.reader = new BufferedReader(new InputStreamReader(in, cs));
}
diff --git a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/Timers.java b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/Timers.java
index 9f97b8585f..6e7ed03495 100644
--- a/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/Timers.java
+++ b/rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/Timers.java
@@ -143,11 +143,10 @@ public int compareTo(Timeout o) {
@Override
public boolean equals(Object obj) {
- try {
- return expiration == ((Timeout) obj).expiration;
- } catch (ClassCastException cce) {
+ if (!(obj instanceof Timeout)) {
return false;
}
+ return expiration == ((Timeout) obj).expiration;
}
@Override
diff --git a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/Namespace.java b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/Namespace.java
index 7e346a9506..ac646d224c 100644
--- a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/Namespace.java
+++ b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/Namespace.java
@@ -6,6 +6,7 @@
package org.mozilla.javascript.xmlimpl;
+import java.util.Objects;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.IdScriptableObject;
@@ -58,14 +59,13 @@ public String toLocaleString() {
return toString();
}
- private boolean equals(Namespace n) {
- return uri().equals(n.uri());
- }
-
@Override
- public boolean equals(Object obj) {
- if (!(obj instanceof Namespace)) return false;
- return equals((Namespace) obj);
+ public boolean equals(Object o) {
+ if (!(o instanceof Namespace)) {
+ return false;
+ }
+ Namespace n = (Namespace) o;
+ return uri().equals(n.uri());
}
@Override
@@ -114,7 +114,7 @@ protected int findInstanceIdInfo(String s) {
X = "prefix";
id = Id_prefix;
}
- if (X != null && X != s && !X.equals(s)) id = 0;
+ if (!Objects.equals(X, s)) id = 0;
break L0;
}
// #/generated#
@@ -187,7 +187,7 @@ protected int findPrototypeId(String s) {
X = "constructor";
id = Id_constructor;
}
- if (X != null && X != s && !X.equals(s)) id = 0;
+ if (!Objects.equals(X, s)) id = 0;
break L0;
}
// #/generated#
diff --git a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/QName.java b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/QName.java
index 0dbaa316e5..41c860ecf1 100644
--- a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/QName.java
+++ b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/QName.java
@@ -6,6 +6,7 @@
package org.mozilla.javascript.xmlimpl;
+import java.util.Objects;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.IdScriptableObject;
@@ -91,7 +92,7 @@ final XmlNode.QName getDelegate() {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof QName)) return false;
- return equals((QName) obj);
+ return equalsInternal((QName) obj);
}
@Override
@@ -106,7 +107,7 @@ protected Object equivalentValues(Object value) {
return result ? Boolean.TRUE : Boolean.FALSE;
}
- private boolean equals(QName q) {
+ private boolean equalsInternal(QName q) {
return this.delegate.equals(q.delegate);
}
@@ -144,7 +145,7 @@ protected int findInstanceIdInfo(String s) {
X = "localName";
id = Id_localName;
}
- if (X != null && X != s && !X.equals(s)) id = 0;
+ if (!Objects.equals(X, s)) id = 0;
break L0;
}
// #/generated#
@@ -216,7 +217,7 @@ protected int findPrototypeId(String s) {
X = "constructor";
id = Id_constructor;
}
- if (X != null && X != s && !X.equals(s)) id = 0;
+ if (!Objects.equals(X, s)) id = 0;
break L0;
}
// #/generated#
diff --git a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLCtor.java b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLCtor.java
index 59e9333863..a1e535988d 100644
--- a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLCtor.java
+++ b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLCtor.java
@@ -6,6 +6,7 @@
package org.mozilla.javascript.xmlimpl;
+import java.util.Objects;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.ScriptRuntime;
@@ -115,7 +116,7 @@ protected int findInstanceIdInfo(String s) {
id = Id_ignoreProcessingInstructions;
break L;
}
- if (X != null && X != s && !X.equals(s)) id = 0;
+ if (!Objects.equals(X, s)) id = 0;
break L0;
}
// #/generated#
@@ -220,7 +221,7 @@ protected int findPrototypeId(String s) {
X = "defaultSettings";
id = Id_defaultSettings;
}
- if (X != null && X != s && !X.equals(s)) id = 0;
+ if (!Objects.equals(X, s)) id = 0;
break L0;
}
// #/generated#
diff --git a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLName.java b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLName.java
index 9e6ccd4228..c4649e4ac1 100644
--- a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLName.java
+++ b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLName.java
@@ -409,7 +409,7 @@ final boolean matches(XML node) {
return false;
}
} else {
- if (this.uri() == null || ((node.isElement()) && this.uri().equals(nodeUri))) {
+ if (this.uri() == null || (node.isElement() && this.uri().equals(nodeUri))) {
if (localName().equals("*")) return true;
if (node.isElement()) {
if (localName().equals(qname.getLocalName())) return true;
diff --git a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLObjectImpl.java b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLObjectImpl.java
index 1b0bafa922..ea973a8ffb 100644
--- a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLObjectImpl.java
+++ b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLObjectImpl.java
@@ -6,6 +6,7 @@
package org.mozilla.javascript.xmlimpl;
+import java.util.Objects;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.Kit;
@@ -647,7 +648,7 @@ protected int findPrototypeId(String s) {
id = Id_processingInstructions;
break L;
}
- if (X != null && X != s && !X.equals(s)) id = 0;
+ if (!Objects.equals(X, s)) id = 0;
break L0;
}
// #/generated#
diff --git a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLWithScope.java b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLWithScope.java
index bc907b8e9e..aebbc9fbc8 100644
--- a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLWithScope.java
+++ b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XMLWithScope.java
@@ -37,7 +37,7 @@ void initAsDotQuery() {
if (prototype instanceof XMLList) {
XMLList xl = (XMLList) prototype;
if (xl.length() > 0) {
- setPrototype((Scriptable) (xl.get(0, null)));
+ setPrototype((Scriptable) xl.get(0, null));
}
}
// Always return the outer-most type of XML lValue of
@@ -70,7 +70,7 @@ protected Object updateDotQuery(boolean value) {
// reset the expression to run with this object as
// the WITH selector.
_currIndex = idx;
- setPrototype((Scriptable) (orgXmlL.get(idx, null)));
+ setPrototype((Scriptable) orgXmlL.get(idx, null));
// continue looping
return null;
diff --git a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XmlNode.java b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XmlNode.java
index fb2b24eafc..d3c109bd57 100644
--- a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XmlNode.java
+++ b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XmlNode.java
@@ -334,11 +334,6 @@ void declare(Namespace n) {
}
}
- Namespace getNamespaceByUri(String uri) {
- if (uriToPrefix.get(uri) == null) return null;
- return Namespace.create(uri, uriToPrefix.get(uri));
- }
-
Namespace getNamespace(String prefix) {
if (map.get(prefix) == null) return null;
return Namespace.create(prefix, map.get(prefix));
@@ -506,7 +501,7 @@ final void setLocalName(String localName) {
}
final QName getQname() {
- String uri = (dom.getNamespaceURI()) == null ? "" : dom.getNamespaceURI();
+ String uri = dom.getNamespaceURI() == null ? "" : dom.getNamespaceURI();
String prefix = (dom.getPrefix() == null) ? "" : dom.getPrefix();
return QName.create(uri, dom.getLocalName(), prefix);
}
@@ -706,7 +701,7 @@ private boolean namespacesEqual(Namespace one, Namespace two) {
return equals(one.getUri(), two.getUri());
}
- final boolean equals(QName other) {
+ private final boolean equalsInternal(QName other) {
if (!namespacesEqual(this.namespace, other.namespace)) return false;
if (!equals(this.localName, other.localName)) return false;
return true;
@@ -717,7 +712,7 @@ public boolean equals(Object obj) {
if (!(obj instanceof QName)) {
return false;
}
- return equals((QName) obj);
+ return equalsInternal((QName) obj);
}
@Override
@@ -835,10 +830,10 @@ void addToList(Object toAdd) {
if (toAdd instanceof XMLList) {
XMLList xmlSrc = (XMLList) toAdd;
for (int i = 0; i < xmlSrc.length(); i++) {
- this._add((xmlSrc.item(i)).getAnnotation());
+ this._add(xmlSrc.item(i).getAnnotation());
}
} else if (toAdd instanceof XML) {
- this._add(((XML) (toAdd)).getAnnotation());
+ this._add(((XML) toAdd).getAnnotation());
} else if (toAdd instanceof XmlNode) {
this._add((XmlNode) toAdd);
}
diff --git a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XmlProcessor.java b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XmlProcessor.java
index 0d0bf2d66c..ee67ac1815 100644
--- a/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XmlProcessor.java
+++ b/rhino-xml/src/main/java/org/mozilla/javascript/xmlimpl/XmlProcessor.java
@@ -461,7 +461,7 @@ final String ecmaToXmlString(Node node) {
if (node instanceof Text) {
String data = ((Text) node).getData();
// TODO Does Java trim() work same as XMLWhitespace?
- String v = (prettyPrint) ? data.trim() : data;
+ String v = prettyPrint ? data.trim() : data;
s.append(escapeElementValue(v));
return s.toString();
}
diff --git a/rhino/src/main/java/org/mozilla/classfile/ClassFileWriter.java b/rhino/src/main/java/org/mozilla/classfile/ClassFileWriter.java
index 42c48e95f0..de78d70194 100644
--- a/rhino/src/main/java/org/mozilla/classfile/ClassFileWriter.java
+++ b/rhino/src/main/java/org/mozilla/classfile/ClassFileWriter.java
@@ -244,7 +244,7 @@ public void startMethod(String methodName, String type, short flags) {
* @param maxLocals the maximum number of local variable slots (a.k.a. Java registers) used by
* the method
*/
- public void stopMethod(short maxLocals) {
+ public void stopMethod(int maxLocals) {
if (itsCurrentMethod == null) throw new IllegalStateException("No method to stop");
fixLabelGotos();
@@ -1224,7 +1224,7 @@ public void markLabel(int label) {
itsLabelTable[label] = itsCodeBufferTop;
}
- public void markLabel(int label, short stackTop) {
+ public void markLabel(int label, int stackTop) {
markLabel(label);
itsStackTop = stackTop;
}
@@ -1292,7 +1292,7 @@ public int getCurrentCodeOffset() {
return itsCodeBufferTop;
}
- public short getStackTop() {
+ public int getStackTop() {
return itsStackTop;
}
@@ -2719,12 +2719,12 @@ private int getWriteSize() {
size += 2; // writeShort(itsFields.size());
for (int i = 0; i < itsFields.size(); i++) {
- size += ((ClassFileField) (itsFields.get(i))).getWriteSize();
+ size += ((ClassFileField) itsFields.get(i)).getWriteSize();
}
size += 2; // writeShort(itsMethods.size());
for (int i = 0; i < itsMethods.size(); i++) {
- size += ((ClassFileMethod) (itsMethods.get(i))).getWriteSize();
+ size += ((ClassFileMethod) itsMethods.get(i)).getWriteSize();
}
size += 2; // writeShort(1); attributes count, could be zero
@@ -2774,7 +2774,7 @@ public byte[] toByteArray() {
offset = putInt16(itsSuperClassIndex, data, offset);
offset = putInt16(itsInterfaces.size(), data, offset);
for (int i = 0; i < itsInterfaces.size(); i++) {
- int interfaceIndex = ((Short) (itsInterfaces.get(i))).shortValue();
+ int interfaceIndex = ((Short) itsInterfaces.get(i)).shortValue();
offset = putInt16(interfaceIndex, data, offset);
}
offset = putInt16(itsFields.size(), data, offset);
@@ -4367,15 +4367,7 @@ private void finalizeSuperBlockStarts() {
// Based on the version numbers we scrape, we can also determine what
// bytecode features we need. For example, Java 6 bytecode (classfile
// version 50) should have stack maps generated.
- InputStream is = null;
- int major = 48, minor = 0;
- try {
- is = ClassFileWriter.class.getResourceAsStream("ClassFileWriter.class");
- if (is == null) {
- is =
- ClassLoader.getSystemResourceAsStream(
- "org/mozilla/classfile/ClassFileWriter.class");
- }
+ try (InputStream is = readClassFile()) {
byte[] header = new byte[8];
// read loop is required since JDK7 will only provide 2 bytes
// on the first read() - see bug #630111
@@ -4385,21 +4377,22 @@ private void finalizeSuperBlockStarts() {
if (c < 0) throw new IOException();
read += c;
}
- minor = (header[4] << 8) | (header[5] & 0xff);
- major = (header[6] << 8) | (header[7] & 0xff);
- } catch (Exception e) {
- // Unable to get class file, use default bytecode version
- } finally {
- MinorVersion = minor;
- MajorVersion = major;
- GenerateStackMap = major >= 50;
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- }
- }
+ MinorVersion = (header[4] << 8) | (header[5] & 0xff);
+ MajorVersion = (header[6] << 8) | (header[7] & 0xff);
+ GenerateStackMap = MajorVersion >= 50;
+ } catch (IOException ioe) {
+ throw new AssertionError("Can't read ClassFileWriter.class to get bytecode version");
+ }
+ }
+
+ static InputStream readClassFile() {
+ InputStream is = ClassFileWriter.class.getResourceAsStream("ClassFileWriter.class");
+ if (is == null) {
+ is =
+ ClassLoader.getSystemResourceAsStream(
+ "org/mozilla/classfile/ClassFileWriter.class");
}
+ return is;
}
final class BootstrapEntry {
@@ -4489,19 +4482,19 @@ public String toString() {
private ConstantPool itsConstantPool;
private ClassFileMethod itsCurrentMethod;
- private short itsStackTop;
+ private int itsStackTop;
- private short itsMaxStack;
- private short itsMaxLocals;
+ private int itsMaxStack;
+ private int itsMaxLocals;
private ObjArray itsMethods = new ObjArray();
private ObjArray itsFields = new ObjArray();
private ObjArray itsInterfaces = new ObjArray();
- private short itsFlags;
- private short itsThisClassIndex;
- private short itsSuperClassIndex;
- private short itsSourceFileNameIndex;
+ private int itsFlags;
+ private int itsThisClassIndex;
+ private int itsSuperClassIndex;
+ private int itsSourceFileNameIndex;
private static final int MIN_LABEL_TABLE_SIZE = 32;
private int[] itsLabelTable;
diff --git a/rhino/src/main/java/org/mozilla/classfile/ConstantPool.java b/rhino/src/main/java/org/mozilla/classfile/ConstantPool.java
index 22f9ddb5db..85fe05651f 100644
--- a/rhino/src/main/java/org/mozilla/classfile/ConstantPool.java
+++ b/rhino/src/main/java/org/mozilla/classfile/ConstantPool.java
@@ -49,7 +49,7 @@ int addConstant(int k) {
itsPool[itsTop++] = CONSTANT_Integer;
itsTop = ClassFileWriter.putInt32(k, itsPool, itsTop);
itsPoolTypes.put(itsTopIndex, CONSTANT_Integer);
- return (short) (itsTopIndex++);
+ return (short) itsTopIndex++;
}
int addConstant(long k) {
@@ -219,7 +219,7 @@ private short addNameAndType(String name, String type) {
itsTop = ClassFileWriter.putInt16(nameIndex, itsPool, itsTop);
itsTop = ClassFileWriter.putInt16(typeIndex, itsPool, itsTop);
itsPoolTypes.put(itsTopIndex, CONSTANT_NameAndType);
- return (short) (itsTopIndex++);
+ return (short) itsTopIndex++;
}
short addClass(String className) {
@@ -298,7 +298,7 @@ short addInterfaceMethodRef(String className, String methodName, String methodTy
FieldOrMethodRef r = new FieldOrMethodRef(className, methodName, methodType);
setConstantData(itsTopIndex, r);
itsPoolTypes.put(itsTopIndex, CONSTANT_InterfaceMethodref);
- return (short) (itsTopIndex++);
+ return (short) itsTopIndex++;
}
short addInvokeDynamic(String methodName, String methodType, int bootstrapIndex) {
@@ -317,7 +317,7 @@ short addInvokeDynamic(String methodName, String methodType, int bootstrapIndex)
setConstantData(theIndex, methodType);
itsPoolTypes.put(theIndex, CONSTANT_InvokeDynamic);
}
- return (short) (theIndex);
+ return (short) theIndex;
}
short addMethodHandle(ClassFileWriter.MHandle mh) {
@@ -341,7 +341,7 @@ short addMethodHandle(ClassFileWriter.MHandle mh) {
itsConstantHash.put(mh, theIndex);
itsPoolTypes.put(theIndex, CONSTANT_MethodHandle);
}
- return (short) (theIndex);
+ return (short) theIndex;
}
Object getConstantData(int index) {
diff --git a/rhino/src/main/java/org/mozilla/javascript/Context.java b/rhino/src/main/java/org/mozilla/javascript/Context.java
index 6542f10984..09a70e25dd 100644
--- a/rhino/src/main/java/org/mozilla/javascript/Context.java
+++ b/rhino/src/main/java/org/mozilla/javascript/Context.java
@@ -633,6 +633,7 @@ public final void unseal(Object sealKey) {
this.sealKey = null;
}
+ @SuppressWarnings("DoNotCallSuggester")
static void onSealedMutation() {
throw new IllegalStateException();
}
diff --git a/rhino/src/main/java/org/mozilla/javascript/DToA.java b/rhino/src/main/java/org/mozilla/javascript/DToA.java
index acd4ee406d..3b968d9843 100644
--- a/rhino/src/main/java/org/mozilla/javascript/DToA.java
+++ b/rhino/src/main/java/org/mozilla/javascript/DToA.java
@@ -25,6 +25,7 @@
package org.mozilla.javascript;
import java.math.BigInteger;
+import java.util.Objects;
class DToA {
@@ -141,7 +142,7 @@ private static void stuffBits(byte[] bits, int offset, int val) {
bits[offset] = (byte) (val >> 24);
bits[offset + 1] = (byte) (val >> 16);
bits[offset + 2] = (byte) (val >> 8);
- bits[offset + 3] = (byte) (val);
+ bits[offset + 3] = (byte) val;
}
/* Convert d into the form b*2^e, where b is an odd integer. b is the returned
@@ -152,7 +153,7 @@ private static BigInteger d2b(double d, int[] e, int[] bits) {
int i, k, y, z, de;
long dBits = Double.doubleToLongBits(d);
int d0 = (int) (dBits >>> 32);
- int d1 = (int) (dBits);
+ int d1 = (int) dBits;
z = d0 & Frac_mask;
d0 &= 0x7fffffff; /* clear sign bit, which we ignore */
@@ -216,7 +217,7 @@ static String JS_dtobasestr(int base, double d) {
long lfloor = (long) dfloor;
if (lfloor == dfloor) {
// int part fits long
- intDigits = Long.toString((negative) ? -lfloor : lfloor, base);
+ intDigits = Long.toString(negative ? -lfloor : lfloor, base);
} else {
// BigInteger should be used
long floorBits = Double.doubleToLongBits(dfloor);
@@ -257,7 +258,7 @@ static String JS_dtobasestr(int base, double d) {
long dBits = Double.doubleToLongBits(d);
int word0 = (int) (dBits >> 32);
- int word1 = (int) (dBits);
+ int word1 = (int) dBits;
int[] e = new int[1];
int[] bbits = new int[1];
@@ -297,8 +298,8 @@ static String JS_dtobasestr(int base, double d) {
b = b.multiply(bigBase);
BigInteger[] divResult = b.divideAndRemainder(s);
b = divResult[1];
- digit = (char) (divResult[0].intValue());
- if (mlo == mhi) mlo = mhi = mlo.multiply(bigBase);
+ digit = (char) divResult[0].intValue();
+ if (Objects.equals(mlo, mhi)) mlo = mhi = mlo.multiply(bigBase);
else {
mlo = mlo.multiply(bigBase);
mhi = mhi.multiply(bigBase);
@@ -383,7 +384,7 @@ static double setWord0(double d, int i) {
static int word1(double d) {
long dBits = Double.doubleToLongBits(d);
- return (int) (dBits);
+ return (int) dBits;
}
/* Return b * 5^k. k must be nonnegative. */
@@ -514,7 +515,7 @@ static int JS_dtoa(
: ((long) word1(d)) << (32 - i);
// d2 = x;
// word0(d2) -= 31*Exp_msk1; /* adjust exponent */
- d2 = setWord0(x, word0(x) - 31 * Exp_msk1);
+ d2 = setWord0((double) x, word0((double) x) - 31 * Exp_msk1);
i -= (Bias + (P - 1) - 1) + 1;
denorm = true;
}
@@ -781,7 +782,7 @@ static int JS_dtoa(
mhi = mlo = null;
if (leftright) {
if (mode < 2) {
- i = (denorm) ? be[0] + (Bias + (P - 1) - 1 + 1) : 1 + P - bbits[0];
+ i = denorm ? be[0] + (Bias + (P - 1) - 1 + 1) : 1 + P - bbits[0];
/* i is 1 plus the number of trailing zero bits in d's significand. Thus,
(2^m2 * 5^m5) / (2^(s2+i) * 5^s5) = (1/2 lsb of d)/10^k. */
} else {
@@ -892,7 +893,7 @@ static int JS_dtoa(
Output either zero or the minimum nonzero output depending on which is closer to d. */
if ((ilim < 0)
|| ((i = b.compareTo(S = S.multiply(BigInteger.valueOf(5)))) < 0)
- || ((i == 0 && !biasUp))) {
+ || (i == 0 && !biasUp)) {
/* Always emit at least one digit. If the number appears to be zero
using the current mode, then emit one '0' digit and set decpt to 1. */
/*no_digits:
@@ -988,7 +989,7 @@ static int JS_dtoa(
buf.append(dig);
if (i == ilim) break;
b = b.multiply(BigInteger.valueOf(10));
- if (mlo == mhi) mlo = mhi = mhi.multiply(BigInteger.valueOf(10));
+ if (Objects.equals(mlo, mhi)) mlo = mhi = mhi.multiply(BigInteger.valueOf(10));
else {
mlo = mlo.multiply(BigInteger.valueOf(10));
mhi = mhi.multiply(BigInteger.valueOf(10));
diff --git a/rhino/src/main/java/org/mozilla/javascript/ES6Generator.java b/rhino/src/main/java/org/mozilla/javascript/ES6Generator.java
index 94d6cac678..e150937a87 100644
--- a/rhino/src/main/java/org/mozilla/javascript/ES6Generator.java
+++ b/rhino/src/main/java/org/mozilla/javascript/ES6Generator.java
@@ -6,6 +6,8 @@
package org.mozilla.javascript;
+import java.util.Objects;
+
public final class ES6Generator extends IdScriptableObject {
private static final long serialVersionUID = 1645892441041347273L;
@@ -420,7 +422,7 @@ protected int findPrototypeId(String s) {
X = "return";
id = Id_return;
}
- if (X != null && X != s && !X.equals(s)) id = 0;
+ if (!Objects.equals(X, s)) id = 0;
break L0;
}
return id;
diff --git a/rhino/src/main/java/org/mozilla/javascript/EqualObjectGraphs.java b/rhino/src/main/java/org/mozilla/javascript/EqualObjectGraphs.java
index 023dcf2f47..559e592d89 100644
--- a/rhino/src/main/java/org/mozilla/javascript/EqualObjectGraphs.java
+++ b/rhino/src/main/java/org/mozilla/javascript/EqualObjectGraphs.java
@@ -55,9 +55,9 @@ final class EqualObjectGraphs {
// Object pairs already known to be equal. Used to short-circuit repeated traversals of objects
// reachable through
// different paths as well as to detect structural inequality.
- private final Map