diff --git a/classpath/java/io/BufferedInputStream.java b/classpath/java/io/BufferedInputStream.java index 51a1423606..585542492a 100644 --- a/classpath/java/io/BufferedInputStream.java +++ b/classpath/java/io/BufferedInputStream.java @@ -38,7 +38,7 @@ public class BufferedInputStream extends InputStream { } } - return buffer[position++]; + return buffer[position++] & 0xFF; } public int read(byte[] b, int offset, int length) throws IOException { diff --git a/classpath/java/lang/Long.java b/classpath/java/lang/Long.java index 76366be3ac..e1445ec5d9 100644 --- a/classpath/java/lang/Long.java +++ b/classpath/java/lang/Long.java @@ -128,15 +128,19 @@ public final class Long extends Number implements Comparable { int i = 0; long number = 0; boolean negative = s.startsWith("-"); + int length = s.length(); if (negative) { i = 1; + -- length; } + long factor = pow(radix, length - 1); for (; i < s.length(); ++i) { char c = s.charAt(i); int digit = Character.digit(c, radix); if (digit >= 0) { - number += digit * pow(radix, (s.length() - i - 1)); + number += digit * factor; + factor /= radix; } else { throw new NumberFormatException("invalid character " + c + " code " + (int) c); diff --git a/classpath/java/util/HashSet.java b/classpath/java/util/HashSet.java index 690dc7cd3c..6e6e96dd5d 100644 --- a/classpath/java/util/HashSet.java +++ b/classpath/java/util/HashSet.java @@ -66,6 +66,10 @@ public class HashSet implements Set { return new MyIterator(map.iterator()); } + public String toString() { + return Collections.toString(this); + } + private static class MyIterator implements Iterator { private final Iterator> it; diff --git a/test/Misc.java b/test/Misc.java index 5be739c5d5..be83804e78 100644 --- a/test/Misc.java +++ b/test/Misc.java @@ -102,6 +102,10 @@ public class Misc { expect(foo > 0); } + expect(Long.parseLong("25214903884") == 25214903884L); + + expect(Long.parseLong("-9223372036854775808") == -9223372036854775808L); + expect(String.valueOf(25214903884L).equals("25214903884")); expect(String.valueOf(-9223372036854775808L).equals