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 knownEquals = new IdentityHashMap<>(); + private final IdentityHashMap knownEquals = new IdentityHashMap<>(); // Currently compared objects; used to avoid infinite recursion over cyclic object graphs. - private final Map currentlyCompared = new IdentityHashMap<>(); + private final IdentityHashMap currentlyCompared = new IdentityHashMap<>(); static T withThreadLocal(java.util.function.Function action) { final EqualObjectGraphs currEq = instance.get(); diff --git a/rhino/src/main/java/org/mozilla/javascript/FunctionObject.java b/rhino/src/main/java/org/mozilla/javascript/FunctionObject.java index 43db67d23a..e3b73a2ff0 100644 --- a/rhino/src/main/java/org/mozilla/javascript/FunctionObject.java +++ b/rhino/src/main/java/org/mozilla/javascript/FunctionObject.java @@ -363,7 +363,7 @@ public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] ar Boolean b = inNewExpr ? Boolean.TRUE : Boolean.FALSE; Object[] invokeArgs = {cx, args, this, b}; result = - (member.isCtor()) + member.isCtor() ? member.newInstance(invokeArgs) : member.invoke(null, invokeArgs); } diff --git a/rhino/src/main/java/org/mozilla/javascript/Hashtable.java b/rhino/src/main/java/org/mozilla/javascript/Hashtable.java index 53052d6c91..a022078455 100644 --- a/rhino/src/main/java/org/mozilla/javascript/Hashtable.java +++ b/rhino/src/main/java/org/mozilla/javascript/Hashtable.java @@ -24,6 +24,7 @@ * allow the collection to be modified, or even cleared completely, while iterators exist, and even * lets an iterator keep on iterating on a collection that was empty when it was created.. */ +@SuppressWarnings("ReferenceEquality") public class Hashtable implements Serializable, Iterable { private static final long serialVersionUID = -7151554912419543747L; @@ -37,12 +38,12 @@ public class Hashtable implements Serializable, Iterable { */ public static final class Entry implements Serializable { private static final long serialVersionUID = 4086572107122965503L; - protected Object key; - protected Object value; - protected boolean deleted; - protected Entry next; - protected Entry prev; - private final int hashCode; + Object key; + Object value; + boolean deleted; + Entry next; + Entry prev; + final int hashCode; Entry() { hashCode = 0; @@ -142,6 +143,7 @@ public void put(Object key, Object value) { * @deprecated use getEntry(Object key) instead because this returns null if the entry was not * found or the value of the entry is null */ + @Deprecated public Object get(Object key) { final Entry e = new Entry(key, null); final Entry v = map.get(e); @@ -165,6 +167,7 @@ public boolean has(Object key) { * @deprecated use deleteEntry(Object key) instead because this returns null if the entry was * not found or the value of the entry is null */ + @Deprecated public Object delete(Object key) { final Entry e = new Entry(key, null); final Entry v = map.remove(e); diff --git a/rhino/src/main/java/org/mozilla/javascript/IdScriptableObject.java b/rhino/src/main/java/org/mozilla/javascript/IdScriptableObject.java index 1ebb6b3ede..d617123811 100644 --- a/rhino/src/main/java/org/mozilla/javascript/IdScriptableObject.java +++ b/rhino/src/main/java/org/mozilla/javascript/IdScriptableObject.java @@ -270,8 +270,8 @@ final Object[] getNames(boolean getAll, boolean getSymbols, Object[] extraEntrie private Object ensureId(int id) { Object[] array = valueArray; - if (array == null) { - synchronized (this) { + synchronized (this) { + if (array == null) { array = valueArray; if (array == null) { array = new Object[maxId * SLOT_SPAN]; diff --git a/rhino/src/main/java/org/mozilla/javascript/ImporterTopLevel.java b/rhino/src/main/java/org/mozilla/javascript/ImporterTopLevel.java index 9baa40071b..fffd2e15a3 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ImporterTopLevel.java +++ b/rhino/src/main/java/org/mozilla/javascript/ImporterTopLevel.java @@ -59,7 +59,7 @@ public ImporterTopLevel(Context cx, boolean sealed) { @Override public String getClassName() { - return (topScopeFlag) ? "global" : "JavaImporter"; + return topScopeFlag ? "global" : "JavaImporter"; } public static void init(Context cx, Scriptable scope, boolean sealed) { diff --git a/rhino/src/main/java/org/mozilla/javascript/Interpreter.java b/rhino/src/main/java/org/mozilla/javascript/Interpreter.java index ef3262b775..9dd07aa134 100644 --- a/rhino/src/main/java/org/mozilla/javascript/Interpreter.java +++ b/rhino/src/main/java/org/mozilla/javascript/Interpreter.java @@ -315,6 +315,7 @@ private boolean isStrictTopFrame() { } } + @SuppressWarnings("ReferenceEquality") private static Boolean equals(CallFrame f1, CallFrame f2, EqualObjectGraphs equal) { // Iterative instead of recursive, as interpreter stack depth can // be larger than JVM stack depth. @@ -388,7 +389,7 @@ private static final class ContinuationJump implements Serializable { // Now walk parents in parallel until a shared frame is found // or until the root is reached. - while (chain1 != chain2 && chain1 != null) { + while (!Objects.equals(chain1, chain2) && chain1 != null) { chain1 = chain1.parentFrame; chain2 = chain2.parentFrame; } @@ -1781,8 +1782,7 @@ private static Object interpretLoop(Context cx, CallFrame frame, Object throwabl // condition are formulated so that they short-circuit the loop // if the function is already an interpreted function, which // should be the majority of cases. - for (boolean notInt = !(fun instanceof InterpretedFunction); - notInt; ) { + for (; ; ) { if (fun instanceof ArrowFunction) { ArrowFunction afun = (ArrowFunction) fun; fun = afun.getTargetFunction(); @@ -2702,7 +2702,7 @@ private static Object interpretLoop(Context cx, CallFrame frame, Object throwabl if (frame == null) { break; } - if (cjump != null && cjump.branchFrame == frame) { + if (cjump != null && Objects.equals(cjump.branchFrame, frame)) { // Continuation branch point was hit, // restart the state loop to reenter continuation indexReg = -1; @@ -3228,7 +3228,7 @@ private static CallFrame processThrowable( // Clear throwable to indicate that exceptions are OK throwable = null; - if (cjump.branchFrame != frame) Kit.codeBug(); + if (!Objects.equals(cjump.branchFrame, frame)) Kit.codeBug(); // Check that we have at least one frozen frame // in the case of detached continuation restoration: diff --git a/rhino/src/main/java/org/mozilla/javascript/InterpreterData.java b/rhino/src/main/java/org/mozilla/javascript/InterpreterData.java index b439a20d23..18f09a8f25 100644 --- a/rhino/src/main/java/org/mozilla/javascript/InterpreterData.java +++ b/rhino/src/main/java/org/mozilla/javascript/InterpreterData.java @@ -170,4 +170,9 @@ public int icodeHashCode() { } return h; } + + @Override + public String toString() { + return itsSourceFile + ':' + itsName; + } } diff --git a/rhino/src/main/java/org/mozilla/javascript/JavaAdapter.java b/rhino/src/main/java/org/mozilla/javascript/JavaAdapter.java index 5fa06b4af7..b7dd74adad 100644 --- a/rhino/src/main/java/org/mozilla/javascript/JavaAdapter.java +++ b/rhino/src/main/java/org/mozilla/javascript/JavaAdapter.java @@ -19,7 +19,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Map; +import java.util.Set; import org.mozilla.classfile.ByteCode; import org.mozilla.classfile.ClassFileWriter; @@ -460,8 +462,7 @@ static Method[] getOverridableMethods(Class clazz) { return list.toArray(new Method[0]); } - private static void appendOverridableMethods( - Class c, ArrayList list, HashSet skip) { + private static void appendOverridableMethods(Class c, List list, Set skip) { Method[] methods = c.isInterface() ? c.getMethods() : c.getDeclaredMethods(); for (Method method : methods) { @@ -582,7 +583,7 @@ public static Scriptable runScript(final Script script) { private static void generateCtor( ClassFileWriter cfw, String adapterName, String superName, Constructor superCtor) { - short locals = 3; // this + factory + delegee + int locals = 3; // this + factory + delegee Class[] parameters = superCtor.getParameterTypes(); // Note that we swapped arguments in app-facing constructors to avoid @@ -611,7 +612,7 @@ private static void generateCtor( // Invoke base class constructor cfw.add(ByteCode.ALOAD_0); // this - short paramOffset = 3; + int paramOffset = 3; for (Class parameter : parameters) { paramOffset += generatePushParam(cfw, paramOffset, parameter); } diff --git a/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java b/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java index f9c457b042..e315a049b4 100644 --- a/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java +++ b/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; /** @@ -327,8 +328,7 @@ private void discoverAccessibleMethods( if (isPublic(mods) || isProtected(mods) || includePrivate) { MethodSignature sig = new MethodSignature(method); if (!map.containsKey(sig)) { - if (includePrivate && !method.isAccessible()) - method.setAccessible(true); + if (includePrivate) method.trySetAccessible(); map.put(sig, method); } } @@ -476,7 +476,7 @@ private void reflect( if (scope != null) { ScriptRuntime.setFunctionProtoAndParent(fun, cx, scope, false); } - ht.put(entry.getKey(), fun); + entry.setValue(fun); } } @@ -556,7 +556,7 @@ private void reflect( char ch0 = nameComponent.charAt(0); if (Character.isUpperCase(ch0)) { if (nameComponent.length() == 1) { - beanPropertyName = nameComponent.toLowerCase(); + beanPropertyName = nameComponent.toLowerCase(Locale.ROOT); } else { char ch1 = nameComponent.charAt(1); if (!Character.isUpperCase(ch1)) { @@ -666,7 +666,7 @@ private Field[] getAccessibleFields(boolean includeProtected, boolean includePri for (Field field : declared) { int mod = field.getModifiers(); if (includePrivate || isPublic(mod) || isProtected(mod)) { - if (!field.isAccessible()) field.setAccessible(true); + field.trySetAccessible(); fieldsList.add(field); } } diff --git a/rhino/src/main/java/org/mozilla/javascript/JavaMembers_jdk11.java b/rhino/src/main/java/org/mozilla/javascript/JavaMembers_jdk11.java index 673b9b332e..b7ed6d5d0e 100644 --- a/rhino/src/main/java/org/mozilla/javascript/JavaMembers_jdk11.java +++ b/rhino/src/main/java/org/mozilla/javascript/JavaMembers_jdk11.java @@ -56,6 +56,7 @@ private static boolean isExportedClass(Class clazz) { // Obtain the module Method getmodule; + @SuppressWarnings("GetClassOnClass") Class cl = clazz.getClass(); try { getmodule = cl.getMethod("getModule"); diff --git a/rhino/src/main/java/org/mozilla/javascript/NativeArray.java b/rhino/src/main/java/org/mozilla/javascript/NativeArray.java index 7cf73ed43b..895cd897a5 100644 --- a/rhino/src/main/java/org/mozilla/javascript/NativeArray.java +++ b/rhino/src/main/java/org/mozilla/javascript/NativeArray.java @@ -115,7 +115,7 @@ protected String getInstanceIdName(int id) { @Override protected Object getInstanceIdValue(int id) { if (id == Id_length) { - return ScriptRuntime.wrapNumber(length); + return ScriptRuntime.wrapNumber((double) length); } return super.getInstanceIdValue(id); } @@ -1027,7 +1027,7 @@ static long getLengthProperty(Context cx, Scriptable obj) { } private static Object setLengthProperty(Context cx, Scriptable target, long length) { - Object len = ScriptRuntime.wrapNumber(length); + Object len = ScriptRuntime.wrapNumber((double) length); ScriptableObject.putProperty(target, "length", len); return len; } @@ -1377,7 +1377,7 @@ private static Object js_push(Context cx, Scriptable scope, Scriptable thisObj, na.dense[(int) na.length++] = arg; na.modCount++; } - return ScriptRuntime.wrapNumber(na.length); + return ScriptRuntime.wrapNumber((double) na.length); } } long length = getLengthProperty(cx, o); @@ -1488,7 +1488,7 @@ private static Object js_unshift( System.arraycopy(args, 0, na.dense, 0, args.length); na.length += args.length; na.modCount++; - return ScriptRuntime.wrapNumber(na.length); + return ScriptRuntime.wrapNumber((double) na.length); } } long length = getLengthProperty(cx, o); @@ -2236,7 +2236,8 @@ private static Object iterativeMethod( if (ScriptRuntime.toBoolean(result)) return elem; break; case Id_findIndex: - if (ScriptRuntime.toBoolean(result)) return ScriptRuntime.wrapNumber(i); + if (ScriptRuntime.toBoolean(result)) + return ScriptRuntime.wrapNumber((double) i); break; } } @@ -2541,17 +2542,17 @@ public List subList(int fromIndex, int toIndex) { "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); return new AbstractList() { - private int modCount = NativeArray.this.modCount; + private int mc = NativeArray.this.modCount; @Override public Object get(int index) { - checkModCount(modCount); + checkModCount(mc); return NativeArray.this.get(index + fromIndex); } @Override public int size() { - checkModCount(modCount); + checkModCount(mc); return toIndex - fromIndex; } }; diff --git a/rhino/src/main/java/org/mozilla/javascript/NativeBigInt.java b/rhino/src/main/java/org/mozilla/javascript/NativeBigInt.java index 139ba26cdc..c65a17ce52 100644 --- a/rhino/src/main/java/org/mozilla/javascript/NativeBigInt.java +++ b/rhino/src/main/java/org/mozilla/javascript/NativeBigInt.java @@ -153,13 +153,13 @@ private static Object execConstructorCall(int id, Object[] args) { if (mod == 0) { newBytes[0] = newBytes[1] < 0 ? (byte) -1 : 0; } else if ((newBytes[0] & (1 << (mod - 1))) != 0) { - newBytes[0] |= -1 << mod; + newBytes[0] = (byte) (newBytes[0] | (-1 << mod)); } else { - newBytes[0] &= (1 << mod) - 1; + newBytes[0] = (byte) (newBytes[0] & ((1 << mod) - 1)); } break; case ConstructorId_asUintN: - newBytes[0] &= (1 << mod) - 1; + newBytes[0] = (byte) (newBytes[0] & ((1 << mod) - 1)); break; } return new BigInteger(newBytes); diff --git a/rhino/src/main/java/org/mozilla/javascript/NativeBoolean.java b/rhino/src/main/java/org/mozilla/javascript/NativeBoolean.java index 1f11751cba..b286836992 100644 --- a/rhino/src/main/java/org/mozilla/javascript/NativeBoolean.java +++ b/rhino/src/main/java/org/mozilla/javascript/NativeBoolean.java @@ -84,8 +84,8 @@ public Object execIdCall( // // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean b = - args[0] instanceof ScriptableObject - && ((ScriptableObject) args[0]).avoidObjectDetection() + ((args[0] instanceof ScriptableObject) + && ((ScriptableObject) args[0]).avoidObjectDetection()) ? false : ScriptRuntime.toBoolean(args[0]); } diff --git a/rhino/src/main/java/org/mozilla/javascript/NativeCallSite.java b/rhino/src/main/java/org/mozilla/javascript/NativeCallSite.java index 1647e13d40..05cb18591b 100644 --- a/rhino/src/main/java/org/mozilla/javascript/NativeCallSite.java +++ b/rhino/src/main/java/org/mozilla/javascript/NativeCallSite.java @@ -22,7 +22,7 @@ static void init(Scriptable scope, boolean sealed) { static NativeCallSite make(Scriptable scope, Scriptable ctorObj) { NativeCallSite cs = new NativeCallSite(); - Scriptable proto = (Scriptable) (ctorObj.get("prototype", ctorObj)); + Scriptable proto = (Scriptable) ctorObj.get("prototype", ctorObj); cs.setParentScope(scope); cs.setPrototype(proto); return cs; diff --git a/rhino/src/main/java/org/mozilla/javascript/NativeDate.java b/rhino/src/main/java/org/mozilla/javascript/NativeDate.java index c28b216e2d..805c4685bf 100644 --- a/rhino/src/main/java/org/mozilla/javascript/NativeDate.java +++ b/rhino/src/main/java/org/mozilla/javascript/NativeDate.java @@ -529,10 +529,10 @@ private static boolean IsLeapYear(int year) { * floor((1968 - 1969) / 4) == -1 */ private static double DayFromYear(double y) { - return ((365 * ((y) - 1970) - + Math.floor(((y) - 1969) / 4.0) - - Math.floor(((y) - 1901) / 100.0) - + Math.floor(((y) - 1601) / 400.0))); + return (365 * (y - 1970) + + Math.floor((y - 1969) / 4.0) + - Math.floor((y - 1901) / 100.0) + + Math.floor((y - 1601) / 400.0)); } private static double TimeFromYear(double y) { diff --git a/rhino/src/main/java/org/mozilla/javascript/NativeError.java b/rhino/src/main/java/org/mozilla/javascript/NativeError.java index 01a85cc9db..f766ebf454 100644 --- a/rhino/src/main/java/org/mozilla/javascript/NativeError.java +++ b/rhino/src/main/java/org/mozilla/javascript/NativeError.java @@ -41,7 +41,7 @@ static void init(Scriptable scope, boolean sealed) { } static NativeError make(Context cx, Scriptable scope, IdFunctionObject ctorObj, Object[] args) { - Scriptable proto = (Scriptable) (ctorObj.get("prototype", ctorObj)); + Scriptable proto = (Scriptable) ctorObj.get("prototype", ctorObj); NativeError obj = new NativeError(); obj.setPrototype(proto); diff --git a/rhino/src/main/java/org/mozilla/javascript/NativeJSON.java b/rhino/src/main/java/org/mozilla/javascript/NativeJSON.java index a02c74bc10..1711c33e61 100644 --- a/rhino/src/main/java/org/mozilla/javascript/NativeJSON.java +++ b/rhino/src/main/java/org/mozilla/javascript/NativeJSON.java @@ -8,13 +8,13 @@ import java.lang.reflect.Array; import java.math.BigInteger; +import java.util.ArrayDeque; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.Map; -import java.util.Stack; import org.mozilla.javascript.json.JsonParser; import org.mozilla.javascript.xml.XMLObject; @@ -173,7 +173,7 @@ private static class StringifyState { this.propertyList = propertyList; } - Stack stack = new Stack<>(); + ArrayDeque stack = new ArrayDeque<>(); String indent; String gap; Callable replacer; @@ -372,7 +372,7 @@ private static String jo(Scriptable value, StringifyState state) { trackValue = unwrapped = ((Wrapper) value).unwrap(); } - if (state.stack.search(trackValue) != -1) { + if (state.stack.contains(trackValue)) { throw ScriptRuntime.typeErrorById("msg.cyclic.value", trackValue.getClass().getName()); } state.stack.push(trackValue); @@ -415,7 +415,7 @@ private static String jo(Scriptable value, StringifyState state) { k = value.getIds(); } - Collection partial = new LinkedList<>(); + ArrayList partial = new ArrayList<>(); for (Object p : k) { Object strP = str(p, value, state); @@ -453,14 +453,14 @@ private static String ja(Scriptable value, StringifyState state) { if (value instanceof Wrapper) { trackValue = unwrapped = ((Wrapper) value).unwrap(); } - if (state.stack.search(trackValue) != -1) { + if (state.stack.contains(trackValue)) { throw ScriptRuntime.typeErrorById("msg.cyclic.value", trackValue.getClass().getName()); } state.stack.push(trackValue); String stepback = state.indent; state.indent = state.indent + state.gap; - Collection partial = new LinkedList<>(); + ArrayList partial = new ArrayList<>(); if (unwrapped != null) { Object[] elements = null; @@ -579,7 +579,7 @@ private static boolean isObjectArrayLike(Object o) { } if (o instanceof NativeJavaObject) { Object unwrapped = ((NativeJavaObject) o).unwrap(); - return (unwrapped instanceof Collection) || (unwrapped.getClass().isArray()); + return (unwrapped instanceof Collection) || unwrapped.getClass().isArray(); } return false; } diff --git a/rhino/src/main/java/org/mozilla/javascript/NativeJavaObject.java b/rhino/src/main/java/org/mozilla/javascript/NativeJavaObject.java index 39d7e4e249..033737b68f 100644 --- a/rhino/src/main/java/org/mozilla/javascript/NativeJavaObject.java +++ b/rhino/src/main/java/org/mozilla/javascript/NativeJavaObject.java @@ -833,6 +833,7 @@ private static long toInteger(Object value, Class type, double min, double ma return (long) d; } + @SuppressWarnings("DoNotCallSuggester") static void reportConversionError(Object value, Class type) { // It uses String.valueOf(value), not value.toString() since // value can be null, bug 282447. @@ -989,6 +990,7 @@ protected String getTag() { } @Override + @SuppressWarnings("EqualsGetClass") public boolean equals(Object obj) { return obj != null && obj.getClass().equals(getClass()) diff --git a/rhino/src/main/java/org/mozilla/javascript/NativeMath.java b/rhino/src/main/java/org/mozilla/javascript/NativeMath.java index bc855404c8..f4c7c2db34 100644 --- a/rhino/src/main/java/org/mozilla/javascript/NativeMath.java +++ b/rhino/src/main/java/org/mozilla/javascript/NativeMath.java @@ -250,8 +250,8 @@ private static Object floor(Context cx, Scriptable scope, Scriptable thisObj, Ob private static Object fround(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { double x = ScriptRuntime.toNumber(args, 0); // Rely on Java to truncate down to a "float" here" - x = (float) x; - return ScriptRuntime.wrapNumber(x); + float fx = (float) x; + return ScriptRuntime.wrapNumber(fx); } // Based on code from diff --git a/rhino/src/main/java/org/mozilla/javascript/NativeObject.java b/rhino/src/main/java/org/mozilla/javascript/NativeObject.java index a62de8de6e..c3aea11948 100644 --- a/rhino/src/main/java/org/mozilla/javascript/NativeObject.java +++ b/rhino/src/main/java/org/mozilla/javascript/NativeObject.java @@ -14,6 +14,7 @@ import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Objects; import java.util.Set; import org.mozilla.javascript.ScriptRuntime.StringIdOrIndex; @@ -744,7 +745,7 @@ public boolean containsKey(Object key) { @Override public boolean containsValue(Object value) { for (Object obj : values()) { - if (value == obj || value != null && value.equals(obj)) { + if (Objects.equals(value, obj)) { return true; } } diff --git a/rhino/src/main/java/org/mozilla/javascript/NativeSymbol.java b/rhino/src/main/java/org/mozilla/javascript/NativeSymbol.java index 6157398a79..8add15dae2 100644 --- a/rhino/src/main/java/org/mozilla/javascript/NativeSymbol.java +++ b/rhino/src/main/java/org/mozilla/javascript/NativeSymbol.java @@ -254,6 +254,7 @@ private Object js_for(Context cx, Scriptable scope, Object[] args) { return ret; } + @SuppressWarnings("ReferenceEquality") private Object js_keyFor(Context cx, Scriptable scope, Object[] args) { Object s = (args.length > 0 ? args[0] : Undefined.instance); if (!(s instanceof NativeSymbol)) { @@ -315,6 +316,7 @@ public void put(Symbol key, Scriptable start, Object value) { * object is still used. Account for that here: an "Object" that was created from a Symbol has a * different value of the slot. */ + @SuppressWarnings("ReferenceEquality") public boolean isSymbol() { return (symbolData == this); } diff --git a/rhino/src/main/java/org/mozilla/javascript/ObjToIntMap.java b/rhino/src/main/java/org/mozilla/javascript/ObjToIntMap.java index 9adf9f79b6..afaf1c7167 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ObjToIntMap.java +++ b/rhino/src/main/java/org/mozilla/javascript/ObjToIntMap.java @@ -172,7 +172,7 @@ public Object intern(Object keyArg) { } int index = ensureIndex(keyArg); values[index] = 0; - return (nullKey) ? null : keys[index]; + return nullKey ? null : keys[index]; } public void remove(Object key) { diff --git a/rhino/src/main/java/org/mozilla/javascript/RhinoSecurityManager.java b/rhino/src/main/java/org/mozilla/javascript/RhinoSecurityManager.java index 0a268fc4aa..fb442a7671 100644 --- a/rhino/src/main/java/org/mozilla/javascript/RhinoSecurityManager.java +++ b/rhino/src/main/java/org/mozilla/javascript/RhinoSecurityManager.java @@ -22,7 +22,7 @@ public class RhinoSecurityManager extends SecurityManager { protected Class getCurrentScriptClass() { Class[] context = getClassContext(); for (Class c : context) { - if (c != InterpretedFunction.class && NativeFunction.class.isAssignableFrom(c) + if (((c != InterpretedFunction.class) && NativeFunction.class.isAssignableFrom(c)) || PolicySecurityController.SecureCaller.class.isAssignableFrom(c)) { return c; } diff --git a/rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java b/rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java index c16ba509c4..468727e16a 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java +++ b/rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java @@ -147,7 +147,7 @@ public static ScriptableObject initSafeStandardObjects( } scope.associateValue(LIBRARY_SCOPE_KEY, scope); - (new ClassCache()).associate(scope); + new ClassCache().associate(scope); BaseFunction.init(cx, scope, sealed); NativeObject.init(scope, sealed); @@ -593,7 +593,7 @@ private static double stringToNumber( case ZEROS_AFTER_54: // x1.1 -> x1 + 1 (round up) // x0.1 -> x0 (round down) - if (bit54 & bit53) sum += 1.0; + if (bit54 && bit53) sum += 1.0; sum *= factor; break; case MIXED_AFTER_54: @@ -2965,7 +2965,7 @@ public static boolean isObject(Object value) { return "object".equals(type) || "function".equals(type); } if (value instanceof Scriptable) { - return (!(value instanceof Callable)); + return !(value instanceof Callable); } return false; } @@ -3868,7 +3868,7 @@ private static boolean compareTo(Comparable val1, T val2, int op) { } } - private static boolean compareTo(double d1, double d2, int op) { + private static boolean compareTo(double d1, double d2, int op) { switch (op) { case Token.GE: return d1 >= d2; @@ -3950,12 +3950,9 @@ public static Object doTopCall( // Cleanup cached references cx.cachedXMLLib = null; cx.isTopLevelStrict = previousTopLevelStrict; - - if (cx.currentActivationCall != null) { - // Function should always call exitActivationFunction - // if it creates activation record - throw new IllegalStateException(); - } + // Function should always call exitActivationFunction + // if it creates activation record + assert (cx.currentActivationCall == null); } return result; } @@ -4985,7 +4982,7 @@ static boolean isGeneratedScript(String sourceUrl) { * just by using an "instanceof" check. */ static boolean isSymbol(Object obj) { - return (((obj instanceof NativeSymbol) && ((NativeSymbol) obj).isSymbol())) + return ((obj instanceof NativeSymbol) && ((NativeSymbol) obj).isSymbol()) || (obj instanceof SymbolKey); } diff --git a/rhino/src/main/java/org/mozilla/javascript/ScriptableObject.java b/rhino/src/main/java/org/mozilla/javascript/ScriptableObject.java index 6a8efb6060..9a67285682 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ScriptableObject.java +++ b/rhino/src/main/java/org/mozilla/javascript/ScriptableObject.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.function.Consumer; @@ -1268,7 +1269,7 @@ private static String getPropertyName(String methodName, String prefix, Annotati propName = methodName.substring(3); if (Character.isUpperCase(propName.charAt(0))) { if (propName.length() == 1) { - propName = propName.toLowerCase(); + propName = propName.toLowerCase(Locale.ROOT); } else if (!Character.isUpperCase(propName.charAt(1))) { propName = Character.toLowerCase(propName.charAt(0)) diff --git a/rhino/src/main/java/org/mozilla/javascript/ThreadSafeSlotMapContainer.java b/rhino/src/main/java/org/mozilla/javascript/ThreadSafeSlotMapContainer.java index f0ced5ec06..6d744b4fe5 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ThreadSafeSlotMapContainer.java +++ b/rhino/src/main/java/org/mozilla/javascript/ThreadSafeSlotMapContainer.java @@ -41,7 +41,7 @@ public int size() { @Override public int dirtySize() { - assert (lock.isReadLocked()); + assert lock.isReadLocked(); return map.size(); } @@ -140,7 +140,7 @@ public void unlockRead(long stamp) { @Override public Iterator iterator() { - assert (lock.isReadLocked()); + assert lock.isReadLocked(); return map.iterator(); } @@ -150,7 +150,7 @@ public Iterator iterator() { */ @Override protected void checkMapSize() { - assert (lock.isWriteLocked()); + assert lock.isWriteLocked(); super.checkMapSize(); } } diff --git a/rhino/src/main/java/org/mozilla/javascript/TokenStream.java b/rhino/src/main/java/org/mozilla/javascript/TokenStream.java index 604f3548e9..ce96ee24b5 100644 --- a/rhino/src/main/java/org/mozilla/javascript/TokenStream.java +++ b/rhino/src/main/java/org/mozilla/javascript/TokenStream.java @@ -2389,10 +2389,12 @@ private static String convertLastCharToHex(String str) { return buf.toString(); } + @Override public int getPosition() { return tokenBeg; } + @Override public int getLength() { return tokenEnd - tokenBeg; } diff --git a/rhino/src/main/java/org/mozilla/javascript/Undefined.java b/rhino/src/main/java/org/mozilla/javascript/Undefined.java index 3b30bac193..6d09126831 100644 --- a/rhino/src/main/java/org/mozilla/javascript/Undefined.java +++ b/rhino/src/main/java/org/mozilla/javascript/Undefined.java @@ -37,7 +37,7 @@ public Object readResolve() { @Override public boolean equals(Object obj) { - return isUndefined(obj) || super.equals(obj); + return isUndefined(obj) || obj == this; } @Override @@ -132,7 +132,7 @@ public String toString() { @Override public boolean equals(Object obj) { - return isUndefined(obj) || super.equals(obj); + return isUndefined(obj) || (obj == this); } @Override diff --git a/rhino/src/main/java/org/mozilla/javascript/ast/BreakStatement.java b/rhino/src/main/java/org/mozilla/javascript/ast/BreakStatement.java index ec0ea3026c..ad4a9589ab 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ast/BreakStatement.java +++ b/rhino/src/main/java/org/mozilla/javascript/ast/BreakStatement.java @@ -17,7 +17,7 @@ public class BreakStatement extends Jump { private Name breakLabel; - private AstNode target; + private AstNode targetNode; { type = Token.BREAK; @@ -63,7 +63,7 @@ public void setBreakLabel(Name label) { * @return the break target. Only {@code null} if the source code has an error in it. */ public AstNode getBreakTarget() { - return target; + return targetNode; } /** @@ -74,7 +74,7 @@ public AstNode getBreakTarget() { */ public void setBreakTarget(Jump target) { assertNotNull(target); - this.target = target; + this.targetNode = target; setJumpStatement(target); } diff --git a/rhino/src/main/java/org/mozilla/javascript/ast/ComputedPropertyKey.java b/rhino/src/main/java/org/mozilla/javascript/ast/ComputedPropertyKey.java index 608807a485..eed44b5309 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ast/ComputedPropertyKey.java +++ b/rhino/src/main/java/org/mozilla/javascript/ast/ComputedPropertyKey.java @@ -39,11 +39,7 @@ public boolean hasSideEffects() { @Override public String toSource(int depth) { - return new StringBuilder(makeIndent(depth)) - .append('[') - .append(expression.toSource(depth)) - .append(']') - .toString(); + return makeIndent(depth) + '[' + expression.toSource(depth) + ']'; } /** Visits this node, then the expression. */ diff --git a/rhino/src/main/java/org/mozilla/javascript/ast/ContinueStatement.java b/rhino/src/main/java/org/mozilla/javascript/ast/ContinueStatement.java index 162546d14f..ac0ed149ce 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ast/ContinueStatement.java +++ b/rhino/src/main/java/org/mozilla/javascript/ast/ContinueStatement.java @@ -17,7 +17,7 @@ public class ContinueStatement extends Jump { private Name label; - private Loop target; + private Loop targetLoop; { type = Token.CONTINUE; @@ -51,7 +51,7 @@ public ContinueStatement(int pos, int len, Name label) { /** Returns continue target */ public Loop getTarget() { - return target; + return targetLoop; } /** @@ -63,8 +63,8 @@ public Loop getTarget() { */ public void setTarget(Loop target) { assertNotNull(target); - this.target = target; - setJumpStatement(target); + this.targetLoop = target; + setJumpStatement(targetLoop); } /** diff --git a/rhino/src/main/java/org/mozilla/javascript/ast/InfixExpression.java b/rhino/src/main/java/org/mozilla/javascript/ast/InfixExpression.java index 3168fdbecc..afdde7c84f 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ast/InfixExpression.java +++ b/rhino/src/main/java/org/mozilla/javascript/ast/InfixExpression.java @@ -142,8 +142,8 @@ public boolean hasSideEffects() { return right != null && right.hasSideEffects(); case Token.AND: case Token.OR: - return left != null && left.hasSideEffects() - || (right != null && right.hasSideEffects()); + return ((left != null) && left.hasSideEffects()) + || ((right != null) && right.hasSideEffects()); default: return super.hasSideEffects(); } diff --git a/rhino/src/main/java/org/mozilla/javascript/ast/StringLiteral.java b/rhino/src/main/java/org/mozilla/javascript/ast/StringLiteral.java index 289dd45788..e1a9683588 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ast/StringLiteral.java +++ b/rhino/src/main/java/org/mozilla/javascript/ast/StringLiteral.java @@ -72,11 +72,10 @@ public void setQuoteCharacter(char c) { @Override public String toSource(int depth) { - return new StringBuilder(makeIndent(depth)) - .append(quoteChar) - .append(ScriptRuntime.escapeString(value, quoteChar)) - .append(quoteChar) - .toString(); + return makeIndent(depth) + + quoteChar + + ScriptRuntime.escapeString(value, quoteChar) + + quoteChar; } /** Visits this node. There are no children to visit. */ diff --git a/rhino/src/main/java/org/mozilla/javascript/ast/TemplateCharacters.java b/rhino/src/main/java/org/mozilla/javascript/ast/TemplateCharacters.java index 2166e450c5..333207d222 100755 --- a/rhino/src/main/java/org/mozilla/javascript/ast/TemplateCharacters.java +++ b/rhino/src/main/java/org/mozilla/javascript/ast/TemplateCharacters.java @@ -71,7 +71,7 @@ public void setRawValue(String rawValue) { @Override public String toSource(int depth) { - return new StringBuilder(makeIndent(depth)).append(rawValue).toString(); + return makeIndent(depth) + rawValue; } /** Visits this node. There are no children to visit. */ diff --git a/rhino/src/main/java/org/mozilla/javascript/ast/VariableDeclaration.java b/rhino/src/main/java/org/mozilla/javascript/ast/VariableDeclaration.java index d92e54eb7d..ea17804995 100644 --- a/rhino/src/main/java/org/mozilla/javascript/ast/VariableDeclaration.java +++ b/rhino/src/main/java/org/mozilla/javascript/ast/VariableDeclaration.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Locale; import org.mozilla.javascript.Token; /** @@ -112,7 +113,7 @@ public void setIsStatement(boolean isStatement) { } private String declTypeName() { - return Token.typeToName(type).toLowerCase(); + return Token.typeToName(type).toLowerCase(Locale.ROOT); } @Override diff --git a/rhino/src/main/java/org/mozilla/javascript/commonjs/module/provider/MultiModuleScriptProvider.java b/rhino/src/main/java/org/mozilla/javascript/commonjs/module/provider/MultiModuleScriptProvider.java index b8155b1946..93fe51a88d 100644 --- a/rhino/src/main/java/org/mozilla/javascript/commonjs/module/provider/MultiModuleScriptProvider.java +++ b/rhino/src/main/java/org/mozilla/javascript/commonjs/module/provider/MultiModuleScriptProvider.java @@ -5,8 +5,7 @@ package org.mozilla.javascript.commonjs.module.provider; import java.net.URI; -import java.util.LinkedList; -import java.util.List; +import java.util.ArrayList; import org.mozilla.javascript.Context; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.commonjs.module.ModuleScript; @@ -27,7 +26,7 @@ public class MultiModuleScriptProvider implements ModuleScriptProvider { * @param providers the providers to multiplex. */ public MultiModuleScriptProvider(Iterable providers) { - final List l = new LinkedList<>(); + final ArrayList l = new ArrayList<>(); for (ModuleScriptProvider provider : providers) { l.add(provider); } diff --git a/rhino/src/main/java/org/mozilla/javascript/jdk18/VMBridge_jdk18.java b/rhino/src/main/java/org/mozilla/javascript/jdk18/VMBridge_jdk18.java index 51aa64f19e..d006cd8c62 100644 --- a/rhino/src/main/java/org/mozilla/javascript/jdk18/VMBridge_jdk18.java +++ b/rhino/src/main/java/org/mozilla/javascript/jdk18/VMBridge_jdk18.java @@ -54,15 +54,7 @@ protected void setContext(Object contextHelper, Context cx) { @Override protected boolean tryToMakeAccessible(AccessibleObject accessible) { - if (accessible.isAccessible()) { - return true; - } - try { - accessible.setAccessible(true); - } catch (Exception ex) { - } - - return accessible.isAccessible(); + return accessible.trySetAccessible(); } @Override diff --git a/rhino/src/main/java/org/mozilla/javascript/optimizer/Block.java b/rhino/src/main/java/org/mozilla/javascript/optimizer/Block.java index 363a52f12d..e5f5e710d8 100644 --- a/rhino/src/main/java/org/mozilla/javascript/optimizer/Block.java +++ b/rhino/src/main/java/org/mozilla/javascript/optimizer/Block.java @@ -26,7 +26,7 @@ private static Block[] reduceToArray(ObjToIntMap map) { int i = 0; ObjToIntMap.Iterator iter = map.newIterator(); for (iter.start(); !iter.done(); iter.next()) { - FatBlock fb = (FatBlock) (iter.getKey()); + FatBlock fb = (FatBlock) iter.getKey(); result[i++] = fb.realBlock; } } @@ -161,13 +161,13 @@ private static Block[] buildBlocks(Node[] statementNodes) { // build successor and predecessor links for (int i = 0; i < theBlocks.size(); i++) { - FatBlock fb = (FatBlock) (theBlocks.get(i)); + FatBlock fb = (FatBlock) theBlocks.get(i); Node blockEndNode = statementNodes[fb.realBlock.itsEndNodeIndex]; int blockEndNodeType = blockEndNode.getType(); if ((blockEndNodeType != Token.GOTO) && (i < (theBlocks.size() - 1))) { - FatBlock fallThruTarget = (FatBlock) (theBlocks.get(i + 1)); + FatBlock fallThruTarget = (FatBlock) theBlocks.get(i + 1); fb.addSuccessor(fallThruTarget); fallThruTarget.addPredecessor(fb); } @@ -186,7 +186,7 @@ private static Block[] buildBlocks(Node[] statementNodes) { Block[] result = new Block[theBlocks.size()]; for (int i = 0; i < theBlocks.size(); i++) { - FatBlock fb = (FatBlock) (theBlocks.get(i)); + FatBlock fb = (FatBlock) theBlocks.get(i); Block b = fb.realBlock; b.itsSuccessors = fb.getSuccessors(); b.itsPredecessors = fb.getPredecessors(); diff --git a/rhino/src/main/java/org/mozilla/javascript/optimizer/BodyCodegen.java b/rhino/src/main/java/org/mozilla/javascript/optimizer/BodyCodegen.java index 1b23af272b..94c12595ca 100644 --- a/rhino/src/main/java/org/mozilla/javascript/optimizer/BodyCodegen.java +++ b/rhino/src/main/java/org/mozilla/javascript/optimizer/BodyCodegen.java @@ -3,12 +3,12 @@ import static org.mozilla.classfile.ClassFileWriter.ACC_PRIVATE; import static org.mozilla.classfile.ClassFileWriter.ACC_STATIC; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.HashMap; import java.util.IdentityHashMap; -import java.util.LinkedList; +import java.util.Iterator; import java.util.List; -import java.util.ListIterator; import java.util.Map; import org.mozilla.classfile.ByteCode; import org.mozilla.classfile.ClassFileWriter; @@ -180,7 +180,7 @@ private void initBodyGeneration() { if (hasVarsInRegs) { int n = fnCurrent.fnode.getParamAndVarCount(); if (n != 0) { - varRegisters = new short[n]; + varRegisters = new int[n]; } } inDirectCallFunction = fnCurrent.isTargetOfDirectCall(); @@ -227,7 +227,7 @@ private void generatePrologue() { // make sure that all parameters are objects itsForcedObjectParameters = true; for (int i = 0; i != directParameterCount; ++i) { - short reg = varRegisters[i]; + int reg = varRegisters[i]; cfw.addALoad(reg); cfw.add(ByteCode.GETSTATIC, "java/lang/Void", "TYPE", "Ljava/lang/Class;"); int isObjectLabel = cfw.acquireLabel(); @@ -362,9 +362,9 @@ private void generatePrologue() { // REMIND - only need to initialize the vars that don't get a value // before the next call and are used in the function - short firstUndefVar = -1; + int firstUndefVar = -1; for (int i = 0; i != varCount; ++i) { - short reg = -1; + int reg = -1; if (i < paramCount) { if (!inDirectCallFunction) { reg = getNewWordLocal(); @@ -1218,7 +1218,7 @@ private void generateExpression(Node node, Node parent) { addScriptRuntimeInvoke("toBoolean", "(Ljava/lang/Object;)Z"); int elseTarget = cfw.acquireLabel(); cfw.add(ByteCode.IFEQ, elseTarget); - short stack = cfw.getStackTop(); + int stack = cfw.getStackTop(); generateExpression(ifThen, node); int afterHook = cfw.acquireLabel(); cfw.add(ByteCode.GOTO, afterHook); @@ -2015,7 +2015,7 @@ private void visitArrayLiteral(Node node, Node child, boolean topLevel) { && !isGenerator && !inLocalBlock) { if (literals == null) { - literals = new LinkedList<>(); + literals = new ArrayList<>(); } literals.add(node); String methodName = @@ -2104,10 +2104,10 @@ private void addLoadProperty( child = child.getNext(); } - short keysArrayLocal = firstFreeLocal; + int keysArrayLocal = firstFreeLocal; ++firstFreeLocal; ++localsMax; - short valuesArrayLocal = firstFreeLocal; + int valuesArrayLocal = firstFreeLocal; ++firstFreeLocal; ++localsMax; addNewObjectArray(count); @@ -2200,7 +2200,7 @@ private void visitObjectLiteral(Node node, Node child, boolean topLevel) { && !isGenerator && !inLocalBlock) { if (literals == null) { - literals = new LinkedList<>(); + literals = new ArrayList<>(); } literals.add(node); String methodName = @@ -2937,7 +2937,7 @@ private static String exceptionTypeToName(int exceptionType) { */ private class ExceptionManager { ExceptionManager() { - exceptionInfo = new LinkedList<>(); + exceptionInfo = new ArrayDeque<>(); } /** @@ -3026,9 +3026,9 @@ void markInlineFinallyStart(Node finallyBlock, int finallyStart) { // the exception handler table have priority when determining which // handler to use. Therefore, we start with the most nested try // block and move outward. - ListIterator iter = exceptionInfo.listIterator(exceptionInfo.size()); - while (iter.hasPrevious()) { - ExceptionInfo ei = iter.previous(); + Iterator iter = exceptionInfo.descendingIterator(); + while (iter.hasNext()) { + ExceptionInfo ei = iter.next(); for (int i = 0; i < EXCEPTION_MAX; i++) { if (ei.handlerLabels[i] != 0 && ei.currentFinally == null) { endCatch(ei, i, finallyStart); @@ -3052,9 +3052,9 @@ void markInlineFinallyStart(Node finallyBlock, int finallyStart) { * @param finallyEnd the label of the end of the inlined code */ void markInlineFinallyEnd(Node finallyBlock, int finallyEnd) { - ListIterator iter = exceptionInfo.listIterator(exceptionInfo.size()); - while (iter.hasPrevious()) { - ExceptionInfo ei = iter.previous(); + Iterator iter = exceptionInfo.descendingIterator(); + while (iter.hasNext()) { + ExceptionInfo ei = iter.next(); for (int i = 0; i < EXCEPTION_MAX; i++) { if (ei.handlerLabels[i] != 0 && ei.currentFinally == finallyBlock) { ei.exceptionStarts[i] = finallyEnd; @@ -3111,7 +3111,7 @@ private class ExceptionInfo { } // A stack of try/catch block information ordered by lexical scoping - private LinkedList exceptionInfo; + private ArrayDeque exceptionInfo; } private ExceptionManager exceptionManager = new ExceptionManager(); @@ -3255,7 +3255,7 @@ private void visitTypeofname(Node node) { cfw.add(ByteCode.GETSTATIC, "java/lang/Void", "TYPE", "Ljava/lang/Class;"); int isNumberLabel = cfw.acquireLabel(); cfw.add(ByteCode.IF_ACMPEQ, isNumberLabel); - short stack = cfw.getStackTop(); + int stack = cfw.getStackTop(); cfw.addALoad(dcp_register); addScriptRuntimeInvoke("typeof", "(Ljava/lang/Object;" + ")Ljava/lang/String;"); int beyond = cfw.acquireLabel(); @@ -3320,7 +3320,7 @@ private void visitIncDec(Node node) { if (!hasVarsInRegs) Kit.codeBug(); boolean post = ((incrDecrMask & Node.POST_FLAG) != 0); int varIndex = fnCurrent.getVarIndex(child); - short reg = varRegisters[varIndex]; + int reg = varRegisters[varIndex]; boolean[] constDeclarations = fnCurrent.fnode.getParamAndVarConst(); if (constDeclarations[varIndex]) { if (node.getIntProp(Node.ISNUMBER_PROP, -1) != -1) { @@ -3748,7 +3748,7 @@ private void visitIfJumpRelOp(Node node, Node child, int trueGOTO, int falseGOTO if (left_dcp_register != -1 && right_dcp_register != -1) { // Generate code to dynamically check for number content // if both operands are dcp - short stack = cfw.getStackTop(); + int stack = cfw.getStackTop(); int leftIsNotNumber = cfw.acquireLabel(); cfw.addALoad(left_dcp_register); cfw.add(ByteCode.GETSTATIC, "java/lang/Void", "TYPE", "Ljava/lang/Class;"); @@ -3789,7 +3789,7 @@ private void visitIfJumpRelOp(Node node, Node child, int trueGOTO, int falseGOTO private void visitIfJumpEqOp(Node node, Node child, int trueGOTO, int falseGOTO) { if (trueGOTO == -1 || falseGOTO == -1) throw Codegen.badTree(); - short stackInitial = cfw.getStackTop(); + int stackInitial = cfw.getStackTop(); int type = node.getType(); Node rChild = child.getNext(); @@ -3814,7 +3814,7 @@ private void visitIfJumpEqOp(Node node, Node child, int trueGOTO, int falseGOTO) cfw.add(ByteCode.DUP); int undefCheckLabel = cfw.acquireLabel(); cfw.add(ByteCode.IFNONNULL, undefCheckLabel); - short stack = cfw.getStackTop(); + int stack = cfw.getStackTop(); cfw.add(ByteCode.POP); cfw.add(ByteCode.GOTO, trueGOTO); cfw.markLabel(undefCheckLabel, stack); @@ -3932,7 +3932,7 @@ private void visitSetConst(Node node, Node child) { private void visitGetVar(Node node) { if (!hasVarsInRegs) Kit.codeBug(); int varIndex = fnCurrent.getVarIndex(node); - short reg = varRegisters[varIndex]; + int reg = varRegisters[varIndex]; if (varIsDirectCallParameter(varIndex)) { // Remember that here the isNumber flag means that we // want to use the incoming parameter in a Number @@ -3955,7 +3955,7 @@ private void visitSetVar(Node node, Node child, boolean needValue) { int varIndex = fnCurrent.getVarIndex(node); generateExpression(child.getNext(), node); boolean isNumber = (node.getIntProp(Node.ISNUMBER_PROP, -1) != -1); - short reg = varRegisters[varIndex]; + int reg = varRegisters[varIndex]; boolean[] constDeclarations = fnCurrent.fnode.getParamAndVarConst(); if (constDeclarations[varIndex]) { if (!needValue) { @@ -3970,7 +3970,7 @@ private void visitSetVar(Node node, Node child, boolean needValue) { int isNumberLabel = cfw.acquireLabel(); int beyond = cfw.acquireLabel(); cfw.add(ByteCode.IF_ACMPEQ, isNumberLabel); - short stack = cfw.getStackTop(); + int stack = cfw.getStackTop(); addDoubleWrap(); cfw.addAStore(reg); cfw.add(ByteCode.GOTO, beyond); @@ -4007,13 +4007,13 @@ private void visitSetConstVar(Node node, Node child, boolean needValue) { int varIndex = fnCurrent.getVarIndex(node); generateExpression(child.getNext(), node); boolean isNumber = (node.getIntProp(Node.ISNUMBER_PROP, -1) != -1); - short reg = varRegisters[varIndex]; + int reg = varRegisters[varIndex]; int beyond = cfw.acquireLabel(); int noAssign = cfw.acquireLabel(); if (isNumber) { cfw.addILoad(reg + 2); cfw.add(ByteCode.IFNE, noAssign); - short stack = cfw.getStackTop(); + int stack = cfw.getStackTop(); cfw.addPush(1); cfw.addIStore(reg + 2); cfw.addDStore(reg); @@ -4028,7 +4028,7 @@ private void visitSetConstVar(Node node, Node child, boolean needValue) { } else { cfw.addILoad(reg + 1); cfw.add(ByteCode.IFNE, noAssign); - short stack = cfw.getStackTop(); + int stack = cfw.getStackTop(); cfw.addPush(1); cfw.addIStore(reg + 1); cfw.addAStore(reg); @@ -4241,7 +4241,7 @@ private void dcpLoadAsNumber(int dcp_register) { cfw.add(ByteCode.GETSTATIC, "java/lang/Void", "TYPE", "Ljava/lang/Class;"); int isNumberLabel = cfw.acquireLabel(); cfw.add(ByteCode.IF_ACMPEQ, isNumberLabel); - short stack = cfw.getStackTop(); + int stack = cfw.getStackTop(); cfw.addALoad(dcp_register); addObjectToDouble(); int beyond = cfw.acquireLabel(); @@ -4256,7 +4256,7 @@ private void dcpLoadAsObject(int dcp_register) { cfw.add(ByteCode.GETSTATIC, "java/lang/Void", "TYPE", "Ljava/lang/Class;"); int isNumberLabel = cfw.acquireLabel(); cfw.add(ByteCode.IF_ACMPEQ, isNumberLabel); - short stack = cfw.getStackTop(); + int stack = cfw.getStackTop(); cfw.addALoad(dcp_register); int beyond = cfw.acquireLabel(); cfw.add(ByteCode.GOTO, beyond); @@ -4389,16 +4389,16 @@ private short getNewWordIntern(int count) { } // This is a valid call only for a local that is allocated by default. - private void incReferenceWordLocal(short local) { + private void incReferenceWordLocal(int local) { locals[local]++; } // This is a valid call only for a local that is allocated by default. - private void decReferenceWordLocal(short local) { + private void decReferenceWordLocal(int local) { locals[local]--; } - private void releaseWordLocal(short local) { + private void releaseWordLocal(int local) { if (local < firstFreeLocal) firstFreeLocal = local; locals[local] = 0; } @@ -4418,13 +4418,13 @@ private void releaseWordLocal(short local) { private static final int MAX_LOCALS = 1024; private int[] locals; - private short firstFreeLocal; - private short localsMax; + private int firstFreeLocal; + private int localsMax; private int itsLineNumber; private boolean hasVarsInRegs; - private short[] varRegisters; + private int[] varRegisters; private boolean inDirectCallFunction; private boolean itsForcedObjectParameters; private int enterAreaStartLabel; @@ -4433,16 +4433,16 @@ private void releaseWordLocal(short local) { // special known locals. If you add a new local here, be sure // to initialize it to -1 in initBodyGeneration - private short variableObjectLocal; - private short popvLocal; - private short contextLocal; - private short argsLocal; - private short operationLocal; - private short thisObjLocal; - private short funObjLocal; - private short itsZeroArgArray; - private short itsOneArgArray; - private short generatorStateLocal; + private int variableObjectLocal; + private int popvLocal; + private int contextLocal; + private int argsLocal; + private int operationLocal; + private int thisObjLocal; + private int funObjLocal; + private int itsZeroArgArray; + private int itsOneArgArray; + private int generatorStateLocal; private boolean isGenerator; private int generatorSwitch; @@ -4450,7 +4450,7 @@ private void releaseWordLocal(short local) { private int maxStack = 0; private Map finallys; - private List literals; + private ArrayList literals; static class FinallyReturnPoint { public List jsrPoints = new ArrayList<>(); diff --git a/rhino/src/main/java/org/mozilla/javascript/optimizer/Codegen.java b/rhino/src/main/java/org/mozilla/javascript/optimizer/Codegen.java index bddfb32778..02b51031e8 100644 --- a/rhino/src/main/java/org/mozilla/javascript/optimizer/Codegen.java +++ b/rhino/src/main/java/org/mozilla/javascript/optimizer/Codegen.java @@ -212,7 +212,7 @@ private void transform(ScriptNode tree) { ot.transform(tree, compilerEnv); if (optLevel > 0) { - (new Optimizer()).optimize(tree); + new Optimizer().optimize(tree); } } diff --git a/rhino/src/main/java/org/mozilla/javascript/regexp/NativeRegExp.java b/rhino/src/main/java/org/mozilla/javascript/regexp/NativeRegExp.java index 3177f68bbd..887b73ed99 100644 --- a/rhino/src/main/java/org/mozilla/javascript/regexp/NativeRegExp.java +++ b/rhino/src/main/java/org/mozilla/javascript/regexp/NativeRegExp.java @@ -813,7 +813,7 @@ private static boolean parseTerm(CompilerState state) { num = 8 * num + (c - '0'); } else break; } - c = (char) (num); + c = (char) num; doFlat(state, c); break; case '1': @@ -851,7 +851,7 @@ private static boolean parseTerm(CompilerState state) { num = 8 * num + (c - '0'); } else break; } - c = (char) (num); + c = (char) num; doFlat(state, c); break; } @@ -913,7 +913,7 @@ private static boolean parseTerm(CompilerState state) { break; } } - c = (char) (n); + c = (char) n; } doFlat(state, c); break; @@ -1150,7 +1150,7 @@ private static int addIndex(byte[] array, int pc, int index) { if (index < 0) throw Kit.codeBug(); if (index > 0xFFFF) throw Context.reportRuntimeError("Too complex regexp"); array[pc] = (byte) (index >> 8); - array[pc + 1] = (byte) (index); + array[pc + 1] = (byte) index; return pc + 2; } @@ -1219,7 +1219,7 @@ private static int emitREBytecode(CompilerState state, RECompiled re, int pc, RE if (t.chr < 256) { if ((state.flags & JSREG_FOLD) != 0) program[pc - 1] = REOP_FLAT1i; else program[pc - 1] = REOP_FLAT1; - program[pc++] = (byte) (t.chr); + program[pc++] = (byte) t.chr; } else { if ((state.flags & JSREG_FOLD) != 0) program[pc - 1] = REOP_UCFLAT1i; else program[pc - 1] = REOP_UCFLAT1; @@ -1252,11 +1252,11 @@ private static int emitREBytecode(CompilerState state, RECompiled re, int pc, RE break; case REOP_QUANT: if ((t.min == 0) && (t.max == -1)) - program[pc - 1] = (t.greedy) ? REOP_STAR : REOP_MINIMALSTAR; + program[pc - 1] = t.greedy ? REOP_STAR : REOP_MINIMALSTAR; else if ((t.min == 0) && (t.max == 1)) - program[pc - 1] = (t.greedy) ? REOP_OPT : REOP_MINIMALOPT; + program[pc - 1] = t.greedy ? REOP_OPT : REOP_MINIMALOPT; else if ((t.min == 1) && (t.max == -1)) - program[pc - 1] = (t.greedy) ? REOP_PLUS : REOP_MINIMALPLUS; + program[pc - 1] = t.greedy ? REOP_PLUS : REOP_MINIMALPLUS; else { if (!t.greedy) program[pc - 1] = REOP_MINIMALQUANT; pc = addIndex(program, pc, t.min); @@ -1408,7 +1408,7 @@ private static void addCharacterToCharSet(RECharSet cs, char c) { if (c >= cs.length) { throw ScriptRuntime.constructError("SyntaxError", "invalid range in character class"); } - cs.bits[byteIndex] |= 1 << (c & 0x7); + cs.bits[byteIndex] |= (byte) (1 << (c & 0x7)); } /* Add a character range, c1 to c2 (inclusive) to the RECharSet */ @@ -1422,15 +1422,15 @@ private static void addCharacterRangeToCharSet(RECharSet cs, char c1, char c2) { throw ScriptRuntime.constructError("SyntaxError", "invalid range in character class"); } - c1 &= 0x7; - c2 &= 0x7; + c1 = (char) (c1 & 0x7); + c2 = (char) (c2 & 0x7); if (byteIndex1 == byteIndex2) { - cs.bits[byteIndex1] |= ((0xFF) >> (7 - (c2 - c1))) << c1; + cs.bits[byteIndex1] |= (byte) ((0xFF >> (7 - (c2 - c1))) << c1); } else { - cs.bits[byteIndex1] |= 0xFF << c1; + cs.bits[byteIndex1] |= (byte) (0xFF << c1); for (i = byteIndex1 + 1; i < byteIndex2; i++) cs.bits[i] = (byte) 0xFF; - cs.bits[byteIndex2] |= (0xFF) >> (7 - c2); + cs.bits[byteIndex2] |= (byte) (0xFF >> (7 - c2)); } } @@ -1462,10 +1462,10 @@ private static void processCharSetImpl(REGlobalData gData, RECharSet charSet) { if (src == end) return; if (gData.regexp.source[src] == '^') { - assert (!charSet.sense); + assert !charSet.sense; ++src; } else { - assert (charSet.sense); + assert charSet.sense; } while (src != end) { @@ -1518,7 +1518,7 @@ private static void processCharSetImpl(REGlobalData gData, RECharSet charSet) { } n = (n << 4) | digit; } - thisCh = (char) (n); + thisCh = (char) n; break; case '0': case '1': @@ -1547,7 +1547,7 @@ private static void processCharSetImpl(REGlobalData gData, RECharSet charSet) { else src--; } } - thisCh = (char) (n); + thisCh = (char) n; break; case 'd': @@ -1572,7 +1572,7 @@ private static void processCharSetImpl(REGlobalData gData, RECharSet charSet) { inRange = false; } for (i = (charSet.length - 1); i >= 0; i--) - if (isREWhiteSpace(i)) addCharacterToCharSet(charSet, (char) (i)); + if (isREWhiteSpace(i)) addCharacterToCharSet(charSet, (char) i); continue; case 'S': if (inRange) { @@ -1580,7 +1580,7 @@ private static void processCharSetImpl(REGlobalData gData, RECharSet charSet) { inRange = false; } for (i = (charSet.length - 1); i >= 0; i--) - if (!isREWhiteSpace(i)) addCharacterToCharSet(charSet, (char) (i)); + if (!isREWhiteSpace(i)) addCharacterToCharSet(charSet, (char) i); continue; case 'w': if (inRange) { @@ -1588,7 +1588,7 @@ private static void processCharSetImpl(REGlobalData gData, RECharSet charSet) { inRange = false; } for (i = (charSet.length - 1); i >= 0; i--) - if (isWord((char) i)) addCharacterToCharSet(charSet, (char) (i)); + if (isWord((char) i)) addCharacterToCharSet(charSet, (char) i); continue; case 'W': if (inRange) { @@ -1596,7 +1596,7 @@ private static void processCharSetImpl(REGlobalData gData, RECharSet charSet) { inRange = false; } for (i = (charSet.length - 1); i >= 0; i--) - if (!isWord((char) i)) addCharacterToCharSet(charSet, (char) (i)); + if (!isWord((char) i)) addCharacterToCharSet(charSet, (char) i); continue; default: thisCh = c; @@ -2971,7 +2971,7 @@ class REGlobalData { /** Get start of parenthesis capture contents, -1 for empty. */ int parensIndex(int i) { - return (int) (parens[i]); + return (int) parens[i]; } /** Get length of parenthesis capture contents. */ diff --git a/rhino/src/main/java/org/mozilla/javascript/regexp/RegExpImpl.java b/rhino/src/main/java/org/mozilla/javascript/regexp/RegExpImpl.java index a2c388a1dd..f0910fd9ff 100644 --- a/rhino/src/main/java/org/mozilla/javascript/regexp/RegExpImpl.java +++ b/rhino/src/main/java/org/mozilla/javascript/regexp/RegExpImpl.java @@ -557,7 +557,7 @@ public Object js_split(Context cx, Scriptable scope, String target, Object[] arg return result; } if (limit > target.length()) { - limit = 1 + target.length(); + limit = 1L + target.length(); } } diff --git a/rhino/src/main/java/org/mozilla/javascript/typedarrays/NativeTypedArrayView.java b/rhino/src/main/java/org/mozilla/javascript/typedarrays/NativeTypedArrayView.java index f97116055e..3a559fe53a 100644 --- a/rhino/src/main/java/org/mozilla/javascript/typedarrays/NativeTypedArrayView.java +++ b/rhino/src/main/java/org/mozilla/javascript/typedarrays/NativeTypedArrayView.java @@ -683,20 +683,19 @@ public boolean equals(Object o) { if (o == null) { return false; } - try { - NativeTypedArrayView v = (NativeTypedArrayView) o; - if (length != v.length) { + if (!(o instanceof NativeTypedArrayView)) { + return false; + } + NativeTypedArrayView v = (NativeTypedArrayView) o; + if (length != v.length) { + return false; + } + for (int i = 0; i < length; i++) { + if (!js_get(i).equals(v.js_get(i))) { return false; } - for (int i = 0; i < length; i++) { - if (!js_get(i).equals(v.js_get(i))) { - return false; - } - } - return true; - } catch (ClassCastException cce) { - return false; } + return true; } @Override diff --git a/rhino/src/main/java/org/mozilla/javascript/v8dtoa/DiyFp.java b/rhino/src/main/java/org/mozilla/javascript/v8dtoa/DiyFp.java index 8629ce101b..be2eecdef7 100644 --- a/rhino/src/main/java/org/mozilla/javascript/v8dtoa/DiyFp.java +++ b/rhino/src/main/java/org/mozilla/javascript/v8dtoa/DiyFp.java @@ -128,12 +128,6 @@ void normalize() { this.e = e; } - static DiyFp normalize(DiyFp a) { - DiyFp result = new DiyFp(a.f, a.e); - result.normalize(); - return result; - } - long f() { return f; } diff --git a/rhino/src/main/java/org/mozilla/javascript/v8dtoa/DoubleHelper.java b/rhino/src/main/java/org/mozilla/javascript/v8dtoa/DoubleHelper.java index cfe94b7a7f..9a2e9dbd8e 100644 --- a/rhino/src/main/java/org/mozilla/javascript/v8dtoa/DoubleHelper.java +++ b/rhino/src/main/java/org/mozilla/javascript/v8dtoa/DoubleHelper.java @@ -39,7 +39,7 @@ public class DoubleHelper { static final long kHiddenBit = 0x0010000000000000L; static DiyFp asDiyFp(long d64) { - assert (!isSpecial(d64)); + assert !isSpecial(d64); return new DiyFp(significand(d64), exponent(d64)); } diff --git a/rhino/src/main/java/org/mozilla/javascript/v8dtoa/FastDtoa.java b/rhino/src/main/java/org/mozilla/javascript/v8dtoa/FastDtoa.java index b0da31ee5e..4db5985ca0 100644 --- a/rhino/src/main/java/org/mozilla/javascript/v8dtoa/FastDtoa.java +++ b/rhino/src/main/java/org/mozilla/javascript/v8dtoa/FastDtoa.java @@ -355,7 +355,7 @@ static boolean digitGen(DiyFp low, DiyFp w, DiyFp high, FastDtoaBuilder buffer, int integrals = (int) ((too_high.f() >>> -one.e()) & 0xffffffffL); // Modulo by one is an and. long fractionals = too_high.f() & (one.f() - 1); - long result = biggestPowerTen(integrals, DiyFp.kSignificandSize - (-one.e())); + long result = biggestPowerTen(integrals, DiyFp.kSignificandSize - -one.e()); int divider = (int) ((result >>> 32) & 0xffffffffL); int divider_exponent = (int) (result & 0xffffffffL); int kappa = divider_exponent + 1; @@ -487,8 +487,8 @@ static boolean grisu3(double v, FastDtoaBuilder buffer) { public static boolean dtoa(double v, FastDtoaBuilder buffer) { assert (v > 0); - assert (!Double.isNaN(v)); - assert (!Double.isInfinite(v)); + assert !Double.isNaN(v); + assert !Double.isInfinite(v); return grisu3(v, buffer); }