diff --git a/classlib/src/main/java/org/teavm/classlib/impl/IntegerUtil.java b/classlib/src/main/java/org/teavm/classlib/impl/IntegerUtil.java index 296c3b1c7..97ab6e6a3 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/IntegerUtil.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/IntegerUtil.java @@ -49,7 +49,7 @@ public final class IntegerUtil { int sz = (Long.SIZE - Long.numberOfLeadingZeros(value) + radixLog2 - 1) / radixLog2; char[] chars = new char[sz]; - long pos = (sz - 1) * radixLog2; + int pos = (sz - 1) * radixLog2; int target = 0; while (pos >= 0) { chars[target++] = Character.forDigit((int) (value >>> pos) & mask, radix); diff --git a/classlib/src/main/java/org/teavm/classlib/impl/currency/CountriesGenerator.java b/classlib/src/main/java/org/teavm/classlib/impl/currency/CountriesGenerator.java index 522c8cae1..03508ed88 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/currency/CountriesGenerator.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/currency/CountriesGenerator.java @@ -20,20 +20,22 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import org.teavm.model.MethodReference; -import org.teavm.platform.metadata.*; +import org.teavm.platform.metadata.MetadataGenerator; +import org.teavm.platform.metadata.MetadataGeneratorContext; +import org.teavm.platform.metadata.Resource; +import org.teavm.platform.metadata.ResourceMap; +import org.teavm.platform.metadata.StringResource; public class CountriesGenerator implements MetadataGenerator { @Override public Resource generateMetadata(MetadataGeneratorContext context, MethodReference method) { try (InputStream input = new BufferedInputStream(context.getClassLoader().getResourceAsStream( "org/teavm/classlib/impl/currency/iso3166.csv"))) { - if (input == null) { - throw new AssertionError("ISO 3166 table was not found"); - } - try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) { return readIso3166(context, reader); } } catch (IOException e) { @@ -77,7 +79,7 @@ public class CountriesGenerator implements MetadataGenerator { + ": closing quote not found"); } if (next + 1 == row.length() || row.charAt(next + 1) != '"') { - sb.append(row.substring(index, next)); + sb.append(row, index, next); index = next + 1; break; } @@ -100,6 +102,6 @@ public class CountriesGenerator implements MetadataGenerator { } } } - return values.toArray(new String[values.size()]); + return values.toArray(new String[0]); } } diff --git a/classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java b/classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java index c4b547de5..23d8208ad 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java @@ -105,6 +105,9 @@ public class CLDRReader { readLikelySubtags(input); } int objectIndex = entry.getName().lastIndexOf('/'); + if (objectIndex < 0) { + continue; + } String objectName = entry.getName().substring(objectIndex + 1); String localeName = entry.getName().substring(0, objectIndex); if (localeName.startsWith("/")) { diff --git a/classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeHelper.java b/classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeHelper.java index 0a4779f12..9ad874997 100644 --- a/classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeHelper.java +++ b/classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeHelper.java @@ -89,7 +89,7 @@ public final class UnicodeHelper { byte b = bytes[i]; if (i < bytes.length - 1 && b == bytes[i + 1]) { int count = 0; - while (count < 16384 && i < bytes.length && bytes[i + count] == b) { + while (count < 16384 && bytes[i + count] == b) { ++count; } i += count; diff --git a/classlib/src/main/java/org/teavm/classlib/java/io/TBufferedInputStream.java b/classlib/src/main/java/org/teavm/classlib/java/io/TBufferedInputStream.java index 9cf821988..dab700985 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/io/TBufferedInputStream.java +++ b/classlib/src/main/java/org/teavm/classlib/java/io/TBufferedInputStream.java @@ -187,7 +187,7 @@ public class TBufferedInputStream extends TFilterInputStream { } } - read = count - pos >= required ? required : count - pos; + read = Math.min(count - pos, required); System.arraycopy(localBuf, pos, buffer, offset, read); pos += read; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/io/TFile.java b/classlib/src/main/java/org/teavm/classlib/java/io/TFile.java index 31bba071a..1904bd578 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/io/TFile.java +++ b/classlib/src/main/java/org/teavm/classlib/java/io/TFile.java @@ -563,7 +563,6 @@ public class TFile implements Serializable, Comparable { } private static String fixSlashes(String origPath) { - int uncIndex = 0; int length = origPath.length(); int newLength = 0; @@ -579,7 +578,7 @@ public class TFile implements Serializable, Comparable { for (int i = 0; i < length; i++) { char pathChar = newPath[i]; if (pathChar == '/' || pathChar == separatorChar) { - if (!foundSlash || i == uncIndex) { + if (!foundSlash || i == 0) { newPath[newLength++] = separatorChar; foundSlash = true; } @@ -588,7 +587,7 @@ public class TFile implements Serializable, Comparable { foundSlash = false; } } - if (foundSlash && (newLength > uncIndex + 1 || newLength == 2 && newPath[0] != '/')) { + if (foundSlash && (newLength > 1 || newPath[0] != '/')) { newLength--; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java index 2bd030d25..acde33d55 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java @@ -229,7 +229,6 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ int intPart = 1; int sz = 1; // Decimal point always included if (negative) { - negative = true; ++sz; // including '-' sign of mantissa } @@ -246,7 +245,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ intPart = exp + 1; digits = Math.max(digits, intPart + 1); exp = 0; - } else if (exp < 0) { + } else { mantissa /= Constants.intPowersOfTen[-exp]; digits -= exp; exp = 0; @@ -373,7 +372,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ intPart = exp + 1; digits = Math.max(digits, intPart + 1); exp = 0; - } else if (exp < 0) { + } else { mantissa /= Constants.longPowersOfTen[-exp]; digits -= exp; exp = 0; diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java index e14c0973e..f69d22231 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java +++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java @@ -175,9 +175,7 @@ public class TObject { if (monitor.enteringThreads != null && !monitor.enteringThreads.isEmpty()) { PlatformQueue enteringThreads = monitor.enteringThreads; PlatformRunnable r = enteringThreads.remove(); - if (enteringThreads == null) { - monitor.enteringThreads = null; - } + monitor.enteringThreads = null; r.run(); } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/math/TBitLevel.java b/classlib/src/main/java/org/teavm/classlib/java/math/TBitLevel.java index b04b96db7..b2dd30fc4 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/math/TBitLevel.java +++ b/classlib/src/main/java/org/teavm/classlib/java/math/TBitLevel.java @@ -287,7 +287,6 @@ class TBitLevel { } if (count == 0) { System.arraycopy(source, intCount, result, 0, resultLen); - i = resultLen; } else { int leftShiftCount = 32 - count; @@ -336,7 +335,6 @@ class TBitLevel { for (i = intCount + 1; i < firstNonZeroDigit; i++) { resDigits[i] = -1; } - resDigits[i] = resDigits[i]--; } else { i = intCount; resDigits[i] = -((-resDigits[intCount]) ^ bitNumber); diff --git a/classlib/src/main/java/org/teavm/classlib/java/math/TLogical.java b/classlib/src/main/java/org/teavm/classlib/java/math/TLogical.java index 18374a618..f74c340bd 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/math/TLogical.java +++ b/classlib/src/main/java/org/teavm/classlib/java/math/TLogical.java @@ -496,7 +496,7 @@ class TLogical { int[] resDigits = new int[resLength]; int i = Math.min(longer.getFirstNonzeroDigit(), shorter.getFirstNonzeroDigit()); - for (i = 0; i < shorter.numberLength; i++) { + for (; i < shorter.numberLength; i++) { resDigits[i] = longer.digits[i] | shorter.digits[i]; } for (; i < resLength; i++) { diff --git a/classlib/src/main/java/org/teavm/classlib/java/net/TURLStreamHandler.java b/classlib/src/main/java/org/teavm/classlib/java/net/TURLStreamHandler.java index fffccada2..e1d211633 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/net/TURLStreamHandler.java +++ b/classlib/src/main/java/org/teavm/classlib/java/net/TURLStreamHandler.java @@ -98,9 +98,7 @@ public abstract class TURLStreamHandler { } else { host = parseString.substring(hostIdx, portIdx); String portString = parseString.substring(portIdx + 1, hostEnd); - if (portString.length() == 0) { - port = -1; - } else { + if (!portString.isEmpty()) { port = Integer.parseInt(portString); } } @@ -189,7 +187,7 @@ public abstract class TURLStreamHandler { if (dirIndex != 0) { path = path.substring(0, path.lastIndexOf('/', dirIndex - 1)) + path.substring(dirIndex + 3); } else { - path = path.substring(dirIndex + 3); + path = path.substring(3); } } diff --git a/classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCharset.java b/classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCharset.java index fee92a1b8..c64d1a184 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCharset.java +++ b/classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCharset.java @@ -60,7 +60,7 @@ public abstract class TCharset implements Comparable { } private static boolean isValidCharsetStart(char c) { - return c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' || c <= 'Z'; + return c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'; } public static TCharset forName(String charsetName) { diff --git a/classlib/src/main/java/org/teavm/classlib/java/text/TMessageFormat.java b/classlib/src/main/java/org/teavm/classlib/java/text/TMessageFormat.java index 357cbfbef..0762fa6de 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/text/TMessageFormat.java +++ b/classlib/src/main/java/org/teavm/classlib/java/text/TMessageFormat.java @@ -63,7 +63,7 @@ public class TMessageFormat extends TFormat { if (ch == '}' || ch == ',') { break; } - if (ch < '0' && ch > '9') { + if (ch < '0' || ch > '9') { throw new IllegalArgumentException("Invalid argument number"); } arg = arg * 10 + (ch - '0'); diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TEnumMap.java b/classlib/src/main/java/org/teavm/classlib/java/util/TEnumMap.java index 7bad40903..ae81f39f1 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TEnumMap.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TEnumMap.java @@ -216,7 +216,7 @@ public class TEnumMap, V> extends AbstractMap implements } int index = ((Enum) o).ordinal(); if (provided[index]) { - provided[index] = true; + provided[index] = false; data[index] = null; size--; return true; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TFormatter.java b/classlib/src/main/java/org/teavm/classlib/java/util/TFormatter.java index 01fb15661..6db23c5ca 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TFormatter.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TFormatter.java @@ -297,7 +297,7 @@ public final class TFormatter implements Closeable, Flushable { formatGivenString(upperCase, "null"); return; } else { - throw new IllegalFormatConversionException(specifier, arg != null ? arg.getClass() : null); + throw new IllegalFormatConversionException(specifier, arg.getClass()); } formatGivenString(upperCase, new String(Character.toChars(c))); diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TGregorianCalendar.java b/classlib/src/main/java/org/teavm/classlib/java/util/TGregorianCalendar.java index 0766641d1..73afe7bb5 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TGregorianCalendar.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TGregorianCalendar.java @@ -917,7 +917,6 @@ public class TGregorianCalendar extends TCalendar { lastYearSkew = 0; currentYearSkew = julianSkew; } - isCached = false; } @Override diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TProperties.java b/classlib/src/main/java/org/teavm/classlib/java/util/TProperties.java index d1bde48a0..d028b67e9 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TProperties.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TProperties.java @@ -291,7 +291,7 @@ public class TProperties extends THashtable { } break; } - if (nextChar < 256 && Character.isWhitespace(nextChar)) { + if (Character.isWhitespace(nextChar)) { if (mode == CONTINUE) { mode = IGNORE; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TTimeZone.java b/classlib/src/main/java/org/teavm/classlib/java/util/TTimeZone.java index ca8eff4db..5647b4b10 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TTimeZone.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TTimeZone.java @@ -329,8 +329,8 @@ public abstract class TTimeZone implements Serializable, Cloneable { return (TTimeZone) GMT.clone(); } raw += minute * 60000; - } else if (hour >= 30 || index > 6) { - raw = (hour / 100 * 3600000) + (hour % 100 * 60000); + } else if (index > 6) { + raw = hour * 60000; } if (sign == '-') { raw = -raw; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TTimer.java b/classlib/src/main/java/org/teavm/classlib/java/util/TTimer.java index bb066f7a6..9991ae122 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TTimer.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TTimer.java @@ -23,7 +23,7 @@ import org.teavm.jso.browser.Window; public class TTimer extends TObject { TSet tasks = new THashSet<>(); - private boolean cancelled; + private volatile boolean cancelled; public TTimer() { } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TVector.java b/classlib/src/main/java/org/teavm/classlib/java/util/TVector.java index 6c1ac8e91..acf3dfbbf 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TVector.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TVector.java @@ -39,7 +39,7 @@ public class TVector extends TAbstractList implements TList, TRandomAcc if (capacity < 0) { throw new IllegalArgumentException(); } - elementData = newElementArray(capacity); + elementData = new Object[capacity]; elementCount = 0; this.capacityIncrement = capacityIncrement; } @@ -52,11 +52,6 @@ public class TVector extends TAbstractList implements TList, TRandomAcc } } - @SuppressWarnings("unchecked") - private E[] newElementArray(int size) { - return (E[]) new Object[size]; - } - @Override public void add(int location, E object) { insertElementAt(object, location); @@ -179,7 +174,7 @@ public class TVector extends TAbstractList implements TList, TRandomAcc public synchronized void ensureCapacity(int minimumCapacity) { if (elementData.length < minimumCapacity) { int next = (capacityIncrement <= 0 ? elementData.length : capacityIncrement) + elementData.length; - grow(minimumCapacity > next ? minimumCapacity : next); + grow(Math.max(minimumCapacity, next)); } } @@ -222,7 +217,7 @@ public class TVector extends TAbstractList implements TList, TRandomAcc } private void grow(int newCapacity) { - E[] newData = newElementArray(newCapacity); + Object[] newData = new Object[newCapacity]; // Assumes elementCount is <= newCapacity assert elementCount <= newCapacity; System.arraycopy(elementData, 0, newData, 0, elementCount); @@ -243,20 +238,20 @@ public class TVector extends TAbstractList implements TList, TRandomAcc adding = capacityIncrement; } - E[] newData = newElementArray(elementData.length + adding); + Object[] newData = new Object[elementData.length + adding]; System.arraycopy(elementData, 0, newData, 0, elementCount); elementData = newData; } private void growBy(int required) { - int adding = 0; + int adding; if (capacityIncrement <= 0) { adding = elementData.length; if (adding == 0) { adding = required; } while (adding < required) { - adding += adding; + adding *= 2; } } else { adding = (required / capacityIncrement) * capacityIncrement; @@ -264,7 +259,7 @@ public class TVector extends TAbstractList implements TList, TRandomAcc adding += capacityIncrement; } } - E[] newData = newElementArray(elementData.length + adding); + Object[] newData = new Object[elementData.length + adding]; System.arraycopy(elementData, 0, newData, 0, elementCount); elementData = newData; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/TArrayBlockingQueue.java b/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/TArrayBlockingQueue.java index 80ceb11e7..f3abf38db 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/TArrayBlockingQueue.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/TArrayBlockingQueue.java @@ -414,17 +414,15 @@ public class TArrayBlockingQueue extends TAbstractQueue implements TBlocki if (waitHandlers == null) { return; } - if (waitHandlers != null) { - while (!waitHandlers.isEmpty()) { - WaitHandler handler = waitHandlers.remove(); - if (PlatformDetector.isLowLevel()) { - EventQueue.offer(handler::changed); - } else { - Platform.postpone(handler::changed); - } + while (!waitHandlers.isEmpty()) { + WaitHandler handler = waitHandlers.remove(); + if (PlatformDetector.isLowLevel()) { + EventQueue.offer(handler::changed); + } else { + Platform.postpone(handler::changed); } - waitHandlers = null; } + waitHandlers = null; } @Async diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/atomic/TAtomicInteger.java b/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/atomic/TAtomicInteger.java index 6a3690119..1ca9d08b8 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/atomic/TAtomicInteger.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/atomic/TAtomicInteger.java @@ -19,9 +19,10 @@ import java.io.Serializable; import java.util.function.IntBinaryOperator; import java.util.function.IntUnaryOperator; +@SuppressWarnings("NonAtomicOperationOnVolatileField") public class TAtomicInteger extends Number implements Serializable { private int value; - private int version; + private volatile int version; public TAtomicInteger() { } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/atomic/TAtomicLong.java b/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/atomic/TAtomicLong.java index f0834c3a8..b1ce364ff 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/atomic/TAtomicLong.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/concurrent/atomic/TAtomicLong.java @@ -19,9 +19,10 @@ import java.io.Serializable; import java.util.function.LongBinaryOperator; import java.util.function.LongUnaryOperator; +@SuppressWarnings("NonAtomicOperationOnVolatileField") public class TAtomicLong extends Number implements Serializable { private long value; - private int version; + private volatile int version; public TAtomicLong() { } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/jar/TInitManifest.java b/classlib/src/main/java/org/teavm/classlib/java/util/jar/TInitManifest.java index bf57e7727..6e1540da4 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/jar/TInitManifest.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/jar/TInitManifest.java @@ -120,7 +120,6 @@ class TInitManifest { } private void readName() throws IOException { - int i = 0; int mark = pos; while (pos < buf.length) { @@ -142,9 +141,6 @@ class TInitManifest { throw new IOException(); } } - if (i > 0) { - throw new IOException(); - } } private void readValue() throws IOException { diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/logging/TLogger.java b/classlib/src/main/java/org/teavm/classlib/java/util/logging/TLogger.java index 69e71028b..cffa2e0d9 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/logging/TLogger.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/logging/TLogger.java @@ -95,7 +95,7 @@ public class TLogger { break; } if (message.charAt(next) != '}') { - sb.append(message.substring(index, next)); + sb.append(message, index, next); index = next; continue; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotQuantifierSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotQuantifierSet.java index c36166314..1e193c612 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotQuantifierSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TDotQuantifierSet.java @@ -92,7 +92,7 @@ class TDotQuantifierSet extends TQuantifierSet { nextSearch = strLength; } nextSearch = next.findBack(res, nextSearch, testString, matchResult); - res = (res < nextSearch) ? nextSearch : res; + res = Math.max(res, nextSearch); } else { return -1; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSupplRangeSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSupplRangeSet.java index 3c7d81dd6..de2b856e1 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSupplRangeSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSupplRangeSet.java @@ -123,13 +123,12 @@ class TSupplRangeSet extends TJointSet { @Override public int matches(int stringIndex, CharSequence testString, TMatchResultImpl matchResult) { int strLength = matchResult.getRightBound(); - int offset = -1; if (stringIndex < strLength) { char high = testString.charAt(stringIndex++); if (contains(high)) { - offset = next.matches(stringIndex, testString, matchResult); + int offset = next.matches(stringIndex, testString, matchResult); if (offset > 0) { return offset; } diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/zip/TInflaterInputStream.java b/classlib/src/main/java/org/teavm/classlib/java/util/zip/TInflaterInputStream.java index 38d489fb9..2fc48a122 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/zip/TInflaterInputStream.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/zip/TInflaterInputStream.java @@ -81,7 +81,7 @@ public class TInflaterInputStream extends FilterInputStream { } // avoid int overflow, check null buffer - if (off > buffer.length || nbytes < 0 || off < 0 || buffer.length - off < nbytes) { + if (off > buffer.length || buffer.length - off < nbytes) { throw new ArrayIndexOutOfBoundsException(); } diff --git a/core/src/main/java/org/teavm/ast/decompilation/StatementGenerator.java b/core/src/main/java/org/teavm/ast/decompilation/StatementGenerator.java index e682b8b3a..6bd14b708 100644 --- a/core/src/main/java/org/teavm/ast/decompilation/StatementGenerator.java +++ b/core/src/main/java/org/teavm/ast/decompilation/StatementGenerator.java @@ -342,10 +342,7 @@ class StatementGenerator implements InstructionVisitor { conditions[i] = conditionList.get(i); } clause.setConditions(conditions); - Statement jumpStmt = generateJumpStatement(stmt, target); - if (jumpStmt != null) { - clause.getBody().add(jumpStmt); - } + clause.getBody().add(generateJumpStatement(stmt, target)); stmt.getClauses().add(clause); } Statement breakStmt = generateJumpStatement(insn.getDefaultTarget()); diff --git a/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java b/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java index 4d683e6ab..fa303637b 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java +++ b/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java @@ -741,20 +741,22 @@ public class ClassGenerator { break; } - simpleName = cls.getSimpleName(); + if (cls != null) { + simpleName = cls.getSimpleName(); - if (cls.getDeclaringClassName() != null - && context.getDependencies().getClass(cls.getDeclaringClassName()) != null) { - declaringClass = "(TeaVM_Class*) &" + context.getNames().forClassInstance( - ValueType.object(cls.getDeclaringClassName())); - includes.includeClass(cls.getDeclaringClassName()); - } + if (cls.getDeclaringClassName() != null + && context.getDependencies().getClass(cls.getDeclaringClassName()) != null) { + declaringClass = "(TeaVM_Class*) &" + context.getNames().forClassInstance( + ValueType.object(cls.getDeclaringClassName())); + includes.includeClass(cls.getDeclaringClassName()); + } - if (cls.getOwnerName() != null - && context.getDependencies().getClass(cls.getOwnerName()) != null) { - enclosingClass = "(TeaVM_Class*) &" + context.getNames().forClassInstance( - ValueType.object(cls.getOwnerName())); - includes.includeClass(cls.getOwnerName()); + if (cls.getOwnerName() != null + && context.getDependencies().getClass(cls.getOwnerName()) != null) { + enclosingClass = "(TeaVM_Class*) &" + context.getNames().forClassInstance( + ValueType.object(cls.getOwnerName())); + includes.includeClass(cls.getOwnerName()); + } } } else if (type instanceof ValueType.Array) { diff --git a/core/src/main/java/org/teavm/backend/c/generate/CodeGenerator.java b/core/src/main/java/org/teavm/backend/c/generate/CodeGenerator.java index d1b60cf7c..0ecadc19e 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/CodeGenerator.java +++ b/core/src/main/java/org/teavm/backend/c/generate/CodeGenerator.java @@ -42,7 +42,6 @@ public class CodeGenerator { this.writer = writer; this.names = context.getNames(); this.includes = includes; - this.classContext = classContext; } public ClassGenerationContext getClassContext() { diff --git a/core/src/main/java/org/teavm/backend/c/intrinsic/AddressIntrinsic.java b/core/src/main/java/org/teavm/backend/c/intrinsic/AddressIntrinsic.java index 8e8557e5d..1d6cffe48 100644 --- a/core/src/main/java/org/teavm/backend/c/intrinsic/AddressIntrinsic.java +++ b/core/src/main/java/org/teavm/backend/c/intrinsic/AddressIntrinsic.java @@ -178,7 +178,7 @@ public class AddressIntrinsic implements Intrinsic { context.writer().print(" * sizeof("); if (className != null) { - ClassReader cls = className != null ? context.classes().get(className) : null; + ClassReader cls = context.classes().get(className); CodeGeneratorUtil.printClassReference(context.writer(), context.includes(), context.names(), cls, className); } else { diff --git a/core/src/main/java/org/teavm/backend/javascript/codegen/DefaultNamingStrategy.java b/core/src/main/java/org/teavm/backend/javascript/codegen/DefaultNamingStrategy.java index d33307469..fa71227a7 100644 --- a/core/src/main/java/org/teavm/backend/javascript/codegen/DefaultNamingStrategy.java +++ b/core/src/main/java/org/teavm/backend/javascript/codegen/DefaultNamingStrategy.java @@ -156,11 +156,9 @@ public class DefaultNamingStrategy implements NamingStrategy { if (clsReader == null) { break; } - if (clsReader != null) { - FieldReader fieldReader = clsReader.getField(fieldRef.getFieldName()); - if (fieldReader != null) { - return fieldReader.getReference(); - } + FieldReader fieldReader = clsReader.getField(fieldRef.getFieldName()); + if (fieldReader != null) { + return fieldReader.getReference(); } cls = clsReader.getParent(); } diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java index e74416b9b..a777f9943 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java @@ -984,16 +984,14 @@ public class Renderer implements RenderingManager { } variableNames.add(context.pointerName()); variableNames.add(context.tempVarName()); - if (!variableNames.isEmpty()) { - writer.append("var "); - for (int i = 0; i < variableNames.size(); ++i) { - if (i > 0) { - writer.append(",").ws(); - } - writer.append(variableNames.get(i)); + writer.append("var "); + for (int i = 0; i < variableNames.size(); ++i) { + if (i > 0) { + writer.append(",").ws(); } - writer.append(";").softNewLine(); + writer.append(variableNames.get(i)); } + writer.append(";").softNewLine(); int firstToSave = 0; if (methodNode.getModifiers().contains(ElementModifier.STATIC)) { diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/StringConstantElimination.java b/core/src/main/java/org/teavm/backend/javascript/rendering/StringConstantElimination.java index 3e556b245..26324f179 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/StringConstantElimination.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/StringConstantElimination.java @@ -17,7 +17,6 @@ package org.teavm.backend.javascript.rendering; import org.mozilla.javascript.Node; import org.mozilla.javascript.ast.AstNode; -import org.mozilla.javascript.ast.AstRoot; import org.mozilla.javascript.ast.Block; import org.mozilla.javascript.ast.ExpressionStatement; import org.mozilla.javascript.ast.NodeVisitor; @@ -27,7 +26,7 @@ import org.mozilla.javascript.ast.StringLiteral; public class StringConstantElimination implements NodeVisitor { @Override public boolean visit(AstNode astNode) { - if (astNode instanceof Block || astNode instanceof Scope || astNode instanceof AstRoot) { + if (astNode instanceof Block || astNode instanceof Scope) { handle(astNode); } return true; diff --git a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java index 11ae20626..81f2aa0be 100644 --- a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java +++ b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java @@ -803,9 +803,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost { block.getBody().add(new WasmStoreInt32(4, new WasmInt32Constant(index), initFlag, WasmInt32Subtype.INT32)); - if (method != null) { - block.getBody().add(new WasmCall(classGenerator.names.forMethod(method.getReference()))); - } + block.getBody().add(new WasmCall(classGenerator.names.forMethod(method.getReference()))); if (controller.wasCancelled()) { break; diff --git a/core/src/main/java/org/teavm/common/DisjointSet.java b/core/src/main/java/org/teavm/common/DisjointSet.java index 84fd16ee7..36ebd03a1 100644 --- a/core/src/main/java/org/teavm/common/DisjointSet.java +++ b/core/src/main/java/org/teavm/common/DisjointSet.java @@ -84,7 +84,7 @@ public class DisjointSet { parent[b] = a; setSize[a] += setSize[b]; return a; - } else if (rank[b] < rank[a]) { + } else if (rank[b] > rank[a]) { parent[a] = b; setSize[b] += setSize[a]; return b; diff --git a/core/src/main/java/org/teavm/common/GraphIndexer.java b/core/src/main/java/org/teavm/common/GraphIndexer.java index 7273a7093..d11c94d4b 100644 --- a/core/src/main/java/org/teavm/common/GraphIndexer.java +++ b/core/src/main/java/org/teavm/common/GraphIndexer.java @@ -80,7 +80,7 @@ public class GraphIndexer { case VISITING: state[node] = VISITED; for (int succ : graph.outgoingEdges(node)) { - if (state[node] == VISITED) { + if (state[succ] == VISITED) { weights[node] += weights[succ]; } } diff --git a/core/src/main/java/org/teavm/common/Promise.java b/core/src/main/java/org/teavm/common/Promise.java index c86cf6dbb..3900dca13 100644 --- a/core/src/main/java/org/teavm/common/Promise.java +++ b/core/src/main/java/org/teavm/common/Promise.java @@ -26,7 +26,6 @@ public class Promise { public static final Promise VOID = Promise.of(null); private T value; - private Promise promise; private Throwable error; private State state = State.PENDING; private List> thenList; @@ -81,7 +80,6 @@ public class Promise { boolean error; AllVoidFunction(int count) { - this.result = result; this.count = count; } @@ -109,7 +107,6 @@ public class Promise { boolean error; AllFunction(int count) { - this.result = result; this.count = count; list.addAll(Collections.nCopies(count, null)); } @@ -124,7 +121,7 @@ public class Promise { } return null; }; - }; + } Function catchF = e -> { if (!error) { diff --git a/core/src/main/java/org/teavm/debugging/Debugger.java b/core/src/main/java/org/teavm/debugging/Debugger.java index 59876b807..ee77157ac 100644 --- a/core/src/main/java/org/teavm/debugging/Debugger.java +++ b/core/src/main/java/org/teavm/debugging/Debugger.java @@ -324,8 +324,10 @@ public class Debugger { loc = null; } boolean empty = loc == null || (loc.getFileName() == null && loc.getLine() < 0); - MethodReference method = !empty ? debugInformation.getMethodAt(jsFrame.getLocation().getLine(), - jsFrame.getLocation().getColumn()) : null; + MethodReference method = !empty && debugInformation != null + ? debugInformation.getMethodAt(jsFrame.getLocation().getLine(), + jsFrame.getLocation().getColumn()) + : null; if (!empty || !wasEmpty) { frames.add(new CallFrame(this, jsFrame, loc, method, debugInformation)); } diff --git a/core/src/main/java/org/teavm/debugging/Value.java b/core/src/main/java/org/teavm/debugging/Value.java index f40afbdd6..516fcdd7b 100644 --- a/core/src/main/java/org/teavm/debugging/Value.java +++ b/core/src/main/java/org/teavm/debugging/Value.java @@ -119,18 +119,12 @@ public class Value { return vars; } - public boolean hasInnerStructure() { - if (getType().equals("long")) { - return false; - } - return jsValue.hasInnerStructure(); + public Promise hasInnerStructure() { + return getType().then(value -> !value.equals("long") && jsValue.hasInnerStructure()); } - public String getInstanceId() { - if (getType().equals("long")) { - return null; - } - return jsValue.getInstanceId(); + public Promise getInstanceId() { + return getType().then(value -> value.equals("long") ? null : jsValue.getInstanceId()); } public JavaScriptValue getOriginalValue() { diff --git a/core/src/main/java/org/teavm/dependency/DefaultCallGraphNode.java b/core/src/main/java/org/teavm/dependency/DefaultCallGraphNode.java index 209c70bc2..89e5c71ab 100644 --- a/core/src/main/java/org/teavm/dependency/DefaultCallGraphNode.java +++ b/core/src/main/java/org/teavm/dependency/DefaultCallGraphNode.java @@ -94,10 +94,8 @@ class DefaultCallGraphNode implements CallGraphNode { callee.addCaller(singleCallSite); return singleCallSite; } - if (singleCallSite != null) { - if (singleCallSite.singleCalledMethod.getMethod().equals(method)) { - return singleCallSite; - } + if (singleCallSite.singleCalledMethod.getMethod().equals(method)) { + return singleCallSite; } callSiteMap = new LinkedHashMap<>(); callSites = new ArrayList<>(); diff --git a/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java b/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java index 0cb0b09ee..d1a46a42c 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java +++ b/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java @@ -287,7 +287,9 @@ class DependencyGraphBuilder { } MethodDependency cloneDep = getAnalyzer().linkMethod(CLONE_METHOD); cloneDep.addLocation(getCallLocation()); - arrayNode.connect(cloneDep.getVariable(0)); + if (arrayNode != null) { + arrayNode.connect(cloneDep.getVariable(0)); + } cloneDep.use(); } diff --git a/core/src/main/java/org/teavm/model/BasicBlock.java b/core/src/main/java/org/teavm/model/BasicBlock.java index f570d93bc..4716fbf07 100644 --- a/core/src/main/java/org/teavm/model/BasicBlock.java +++ b/core/src/main/java/org/teavm/model/BasicBlock.java @@ -384,7 +384,7 @@ public class BasicBlock implements BasicBlockReader, Iterable { @Override public TryCatchBlock set(int index, TryCatchBlock element) { - TryCatchBlock oldTryCatch = tryCatchBlocks.get(index); + TryCatchBlock oldTryCatch = tryCatchBlocks != null ? tryCatchBlocks.get(index) : null; if (oldTryCatch == element) { return oldTryCatch; } diff --git a/core/src/main/java/org/teavm/model/MethodDescriptor.java b/core/src/main/java/org/teavm/model/MethodDescriptor.java index 5beef6647..bfc439b52 100644 --- a/core/src/main/java/org/teavm/model/MethodDescriptor.java +++ b/core/src/main/java/org/teavm/model/MethodDescriptor.java @@ -119,14 +119,14 @@ public class MethodDescriptor implements Serializable { return null; } int index = text.indexOf(')', 1); - if (index < 0) { + if (index <= 0) { return null; } ValueType[] params = ValueType.parseManyIfPossible(text.substring(1, index)); if (params == null) { return null; } - ValueType result = ValueType.parse(text.substring(index + 1)); + ValueType result = ValueType.parseIfPossible(text.substring(index + 1)); if (result == null) { return null; } diff --git a/core/src/main/java/org/teavm/model/ValueType.java b/core/src/main/java/org/teavm/model/ValueType.java index e19a6540c..253ef4d1e 100644 --- a/core/src/main/java/org/teavm/model/ValueType.java +++ b/core/src/main/java/org/teavm/model/ValueType.java @@ -270,7 +270,7 @@ public abstract class ValueType implements Serializable { int index = 0; while (index < text.length()) { int nextIndex = cut(text, index); - ValueType type = parse(text.substring(index, nextIndex)); + ValueType type = parseIfPossible(text.substring(index, nextIndex)); if (type == null) { return null; } diff --git a/core/src/main/java/org/teavm/model/analysis/ClassInference.java b/core/src/main/java/org/teavm/model/analysis/ClassInference.java index 6f02869b2..dc7050af2 100644 --- a/core/src/main/java/org/teavm/model/analysis/ClassInference.java +++ b/core/src/main/java/org/teavm/model/analysis/ClassInference.java @@ -398,8 +398,6 @@ public class ClassInference { if (!outerChanged) { break; } - - changed = false; } } @@ -684,13 +682,7 @@ public class ClassInference { String expectedType = tryCatch.getExceptionType(); List thrownTypes = subclassListProvider.getSubclasses(expectedType, false); - if (thrownTypes == null) { - if (!overflowTypes[exceptionNode]) { - overflowTypes[exceptionNode] = true; - changed = true; - nodeChanged[exceptionNode] = true; - } - } else { + if (thrownTypes != null) { IntHashSet nodeTypes = getNodeTypes(exceptionNode); for (String thrownTypeName : thrownTypes) { int thrownType = getTypeByName(thrownTypeName); @@ -953,7 +945,7 @@ public class ClassInference { overflowType(variable, degree); } else { String[] types = dep.getTypes(); - for (String type : dep.getTypes()) { + for (String type : types) { if (addType(variable, degree, type)) { break; } diff --git a/core/src/main/java/org/teavm/model/lowlevel/CallSiteLocation.java b/core/src/main/java/org/teavm/model/lowlevel/CallSiteLocation.java index 7f5b7ac81..329648ea4 100644 --- a/core/src/main/java/org/teavm/model/lowlevel/CallSiteLocation.java +++ b/core/src/main/java/org/teavm/model/lowlevel/CallSiteLocation.java @@ -55,10 +55,10 @@ public class CallSiteLocation { List result = new ArrayList<>(); InliningInfo inlining = location.getInlining(); result.add(new CallSiteLocation( - convertFileName(location != null ? location.getFileName() : null), + convertFileName(location.getFileName()), inlining.getMethod().getClassName(), inlining.getMethod().getName(), - location != null ? location.getLine() : 0)); + location.getLine())); while (inlining != null) { MethodReference method = inlining.getParent() != null ? inlining.getParent().getMethod() diff --git a/core/src/main/java/org/teavm/model/lowlevel/Characteristics.java b/core/src/main/java/org/teavm/model/lowlevel/Characteristics.java index 21fd39844..002e0d5fe 100644 --- a/core/src/main/java/org/teavm/model/lowlevel/Characteristics.java +++ b/core/src/main/java/org/teavm/model/lowlevel/Characteristics.java @@ -107,6 +107,6 @@ public class Characteristics { if (cls.getAnnotations().get(Unmanaged.class.getName()) != null) { return false; } - return method == null || method.getAnnotations().get(Unmanaged.class.getName()) == null; + return method.getAnnotations().get(Unmanaged.class.getName()) == null; } } diff --git a/core/src/main/java/org/teavm/model/lowlevel/ExportDependencyListener.java b/core/src/main/java/org/teavm/model/lowlevel/ExportDependencyListener.java index 0033f5dfb..e21b6c196 100644 --- a/core/src/main/java/org/teavm/model/lowlevel/ExportDependencyListener.java +++ b/core/src/main/java/org/teavm/model/lowlevel/ExportDependencyListener.java @@ -249,7 +249,7 @@ public class ExportDependencyListener extends AbstractDependencyListener { return true; } - class FunctionGetFinder extends AbstractInstructionReader { + static class FunctionGetFinder extends AbstractInstructionReader { DisjointSet variableClasses = new DisjointSet(); String[] stringConstants; ValueType[] classConstants; diff --git a/core/src/main/java/org/teavm/model/text/ListingLexer.java b/core/src/main/java/org/teavm/model/text/ListingLexer.java index d67f7c667..d7d4b78bf 100644 --- a/core/src/main/java/org/teavm/model/text/ListingLexer.java +++ b/core/src/main/java/org/teavm/model/text/ListingLexer.java @@ -154,7 +154,7 @@ class ListingLexer { break; case '*': nextChar(); - token = ListingToken.SUBTRACT; + token = ListingToken.MULTIPLY; break; case '/': nextChar(); diff --git a/core/src/main/java/org/teavm/model/transformation/BoundCheckInsertion.java b/core/src/main/java/org/teavm/model/transformation/BoundCheckInsertion.java index 37f176df4..bfc089105 100644 --- a/core/src/main/java/org/teavm/model/transformation/BoundCheckInsertion.java +++ b/core/src/main/java/org/teavm/model/transformation/BoundCheckInsertion.java @@ -375,10 +375,8 @@ public class BoundCheckInsertion { } } - if (lower) { - if ((isConstant[index] && constantValue[index] >= 0) || nonNegative[index]) { - lower = false; - } + if ((isConstant[index] && constantValue[index] >= 0) || nonNegative[index]) { + lower = false; } if (upper) { diff --git a/core/src/main/java/org/teavm/parsing/ProgramParser.java b/core/src/main/java/org/teavm/parsing/ProgramParser.java index 85da08443..6349e35e7 100644 --- a/core/src/main/java/org/teavm/parsing/ProgramParser.java +++ b/core/src/main/java/org/teavm/parsing/ProgramParser.java @@ -878,13 +878,7 @@ public class ProgramParser { @Override public void visitIntInsn(int opcode, int operand) { switch (opcode) { - case Opcodes.BIPUSH: { - IntegerConstantInstruction insn = new IntegerConstantInstruction(); - insn.setConstant(operand); - insn.setReceiver(getVariable(pushSingle())); - addInstruction(insn); - break; - } + case Opcodes.BIPUSH: case Opcodes.SIPUSH: { IntegerConstantInstruction insn = new IntegerConstantInstruction(); insn.setConstant(operand); diff --git a/core/src/main/java/org/teavm/runtime/ExceptionHandling.java b/core/src/main/java/org/teavm/runtime/ExceptionHandling.java index cadba5430..9832660fe 100644 --- a/core/src/main/java/org/teavm/runtime/ExceptionHandling.java +++ b/core/src/main/java/org/teavm/runtime/ExceptionHandling.java @@ -53,7 +53,7 @@ public final class ExceptionHandling { CallSite callSite = findCallSiteById(callSiteId, stackFrame); CallSiteLocation location = callSite.location; while (location != null) { - MethodLocation methodLocation = location != null ? location.method : null; + MethodLocation methodLocation = location.method; Console.printString(" at "); if (methodLocation.className == null || methodLocation.methodName == null) { @@ -184,7 +184,7 @@ public final class ExceptionHandling { if (isObfuscated()) { target[index++] = new StackTraceElement("Obfuscated", "obfuscated", "Obfuscated.java", callSiteId); } else if (location == null) { - target[index++] = new StackTraceElement("", "", null, location.lineNumber); + target[index++] = new StackTraceElement("", "", null, -1); } else { while (location != null) { MethodLocation methodLocation = location.method; diff --git a/html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java b/html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java index e3306960e..1ae6c6e26 100644 --- a/html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java +++ b/html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java @@ -157,6 +157,7 @@ public class JavaScriptBodyDependency extends AbstractDependencyListener { if (reader == null) { agent.getDiagnostics().error(new CallLocation(caller.getReference()), "Can't resolve method {{m0}}", methodRef); + return; } methodRef = reader.getReference(); diff --git a/html4j/src/main/java/org/teavm/html4j/JavaScriptResourceInterceptor.java b/html4j/src/main/java/org/teavm/html4j/JavaScriptResourceInterceptor.java index 65b4661c2..165e024ed 100644 --- a/html4j/src/main/java/org/teavm/html4j/JavaScriptResourceInterceptor.java +++ b/html4j/src/main/java/org/teavm/html4j/JavaScriptResourceInterceptor.java @@ -38,8 +38,9 @@ public class JavaScriptResourceInterceptor extends AbstractRendererListener { continue; } String path = annot.getValue("value").getString(); - String packageName = className.substring(0, className.lastIndexOf('.')); - String resourceName = packageName.replace('.', '/') + "/" + path; + int packageIndex = className.lastIndexOf('.'); + String packageName = packageIndex >= 0 ? className.substring(0, packageIndex) : ""; + String resourceName = packageName.isEmpty() ? path : packageName.replace('.', '/') + "/" + path; try (InputStream input = manager.getClassLoader().getResourceAsStream(resourceName)) { if (input == null) { throw new RenderingException("Error processing JavaScriptResource annotation on class " diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java index be89a2651..104fb999c 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java @@ -786,7 +786,7 @@ class JSClassProcessor { private boolean isProperSetIndexer(MethodDescriptor desc) { return desc.parameterCount() == 2 && typeHelper.isSupportedType(desc.parameterType(0)) - && typeHelper.isSupportedType(desc.parameterType(0)) && desc.getResultType() == ValueType.VOID; + && typeHelper.isSupportedType(desc.parameterType(1)) && desc.getResultType() == ValueType.VOID; } private static String cutPrefix(String name, int prefixLength) { diff --git a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/MetaprogrammingImpl.java b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/MetaprogrammingImpl.java index 181b61806..a9b25e558 100644 --- a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/MetaprogrammingImpl.java +++ b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/MetaprogrammingImpl.java @@ -207,8 +207,7 @@ public final class MetaprogrammingImpl { return null; } ReflectMethod method = new ReflectMethodImpl(cls, methodReader); - return new SourceLocation(method, location != null ? location.getFileName() : null, - location != null ? location.getLine() : null); + return new SourceLocation(method, location.getFileName(), location.getLine()); } @SuppressWarnings("WeakerAccess") diff --git a/tests/src/test/java/org/teavm/classlib/java/util/CalendarTest.java b/tests/src/test/java/org/teavm/classlib/java/util/CalendarTest.java index b8d485d59..061a947a9 100644 --- a/tests/src/test/java/org/teavm/classlib/java/util/CalendarTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/util/CalendarTest.java @@ -603,9 +603,6 @@ public class CalendarTest { } } - /** - * @tests java.util.Calendar#isSet(int) - */ @Test public void test_isSet() { Calendar calendar = Calendar.getInstance(); @@ -615,10 +612,6 @@ public class CalendarTest { } } - /** - * @tests java.util.Calendar#getInstance(Locale) - * @tests java.util.Calendar#getInstance(TimeZone, Locale) - */ @Test public void test_getInstance() { // test getInstance(Locale) @@ -640,9 +633,6 @@ public class CalendarTest { .getID(), estCalendar.getTimeZone().getID()); } - /** - * @tests java.util.Calendar#internalGet(int) - */ @Test public void test_internalGet() { MockGregorianCalendar c = new MockGregorianCalendar(); @@ -650,18 +640,12 @@ public class CalendarTest { assertEquals(0, c.internal_get(Calendar.YEAR)); } - /** - * @tests java.util.Calendar#hashCode() - */ @Test public void test_hashcode() { Calendar calendar = Calendar.getInstance(Locale.JAPAN); assertTrue(calendar.hashCode() == calendar.hashCode()); } - /** - * @tests java.util.Calendar#roll(int, int) - */ @Test public void test_roll() { Calendar calendar = Calendar.getInstance(); diff --git a/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPRunner.java b/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPRunner.java index a7b025b04..317aef323 100644 --- a/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPRunner.java +++ b/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPRunner.java @@ -234,7 +234,7 @@ public final class ChromeRDPRunner { private Command resumeCommand = args -> debugger.resume(); private Command breakpointCommand = args -> { - if (args.length != 3 && args.length != 3) { + if (args.length < 2 || args.length > 4) { System.out.println("Expected 2 arguments"); return Promise.VOID; } diff --git a/tools/cli/src/main/java/org/teavm/cli/TeaVMCBuilderRunner.java b/tools/cli/src/main/java/org/teavm/cli/TeaVMCBuilderRunner.java index 06ae2129d..0b04e00fa 100644 --- a/tools/cli/src/main/java/org/teavm/cli/TeaVMCBuilderRunner.java +++ b/tools/cli/src/main/java/org/teavm/cli/TeaVMCBuilderRunner.java @@ -135,7 +135,7 @@ public class TeaVMCBuilderRunner { if (args.length != 1) { System.err.println("Unexpected arguments"); printUsage(); - } else if (args.length == 1) { + } else { builder.setMainClass(args[0]); } } diff --git a/tools/cli/src/main/java/org/teavm/cli/TeaVMDevServerRunner.java b/tools/cli/src/main/java/org/teavm/cli/TeaVMDevServerRunner.java index 5f89b524f..ec5a749dc 100644 --- a/tools/cli/src/main/java/org/teavm/cli/TeaVMDevServerRunner.java +++ b/tools/cli/src/main/java/org/teavm/cli/TeaVMDevServerRunner.java @@ -35,7 +35,7 @@ public final class TeaVMDevServerRunner { setupOptions(); } - @SuppressWarnings("static-access") + @SuppressWarnings("AccessStaticViaInstance") private static void setupOptions() { options.addOption(OptionBuilder .withArgName("directory") @@ -150,7 +150,7 @@ public final class TeaVMDevServerRunner { if (args.length != 1) { System.err.println("Unexpected arguments"); printUsage(); - } else if (args.length == 1) { + } else { devServer.setMainClass(args[0]); } } diff --git a/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java b/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java index 6e9cdc3ca..e5a35aedb 100644 --- a/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java +++ b/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java @@ -366,7 +366,7 @@ public class TeaVMTool { fileTable, variableTable, classSource, innerClassSource); programCache = new DiskProgramCache(cacheDirectory, referenceCache, symbolTable, fileTable, variableTable); - if (incremental && targetType == TeaVMTargetType.JAVASCRIPT) { + if (targetType == TeaVMTargetType.JAVASCRIPT) { astCache = new DiskMethodNodeCache(cacheDirectory, referenceCache, symbolTable, fileTable, variableTable); javaScriptTarget.setAstCache(astCache); diff --git a/tools/devserver/src/main/java/org/teavm/devserver/deobfuscate/Deobfuscator.java b/tools/devserver/src/main/java/org/teavm/devserver/deobfuscate/Deobfuscator.java index 86462efc6..1bbe44924 100644 --- a/tools/devserver/src/main/java/org/teavm/devserver/deobfuscate/Deobfuscator.java +++ b/tools/devserver/src/main/java/org/teavm/devserver/deobfuscate/Deobfuscator.java @@ -118,6 +118,7 @@ public final class Deobfuscator { if (location != null) { frame.setLineNumber(location.getLine()); } + result.add(frame); } if (result.isEmpty()) { diff --git a/tools/junit/src/main/java/org/teavm/junit/TeaVMTestRunner.java b/tools/junit/src/main/java/org/teavm/junit/TeaVMTestRunner.java index babb0dcdf..0527e0c70 100644 --- a/tools/junit/src/main/java/org/teavm/junit/TeaVMTestRunner.java +++ b/tools/junit/src/main/java/org/teavm/junit/TeaVMTestRunner.java @@ -130,7 +130,6 @@ public class TeaVMTestRunner extends Runner implements Filterable { static { for (RunKind kind : RunKind.values()) { runners.put(kind, new RunnerKindInfo()); - runners.put(kind, new RunnerKindInfo()); } Runtime.getRuntime().addShutdownHook(new Thread(() -> { synchronized (TeaVMTestRunner.class) {