diff --git a/classpath/java/io/PrintStream.java b/classpath/java/io/PrintStream.java index 1e21d86ed3..43cc6e3860 100644 --- a/classpath/java/io/PrintStream.java +++ b/classpath/java/io/PrintStream.java @@ -23,7 +23,7 @@ public class PrintStream extends OutputStream { } public void print(Object o) { - print(o.toString()); + print(String.valueOf(o)); } public void print(char c) { @@ -46,7 +46,7 @@ public class PrintStream extends OutputStream { } public void println(Object o) { - println(o.toString()); + println(String.valueOf(o)); } public void println(char c) { diff --git a/classpath/java/lang/String.java b/classpath/java/lang/String.java index 3c72ee92e3..283e4b7248 100644 --- a/classpath/java/lang/String.java +++ b/classpath/java/lang/String.java @@ -379,7 +379,7 @@ public final class String implements Comparable { public native String intern(); public static String valueOf(Object s) { - return s.toString(); + return s == null ? "null" : s.toString(); } public static String valueOf(boolean v) { diff --git a/classpath/java/util/ArrayList.java b/classpath/java/util/ArrayList.java index fa0813805c..abb5ea28cc 100644 --- a/classpath/java/util/ArrayList.java +++ b/classpath/java/util/ArrayList.java @@ -70,7 +70,7 @@ public class ArrayList implements List { public void add(int index, T element) { size = Math.max(size+1, index+1); grow(); - System.arraycopy(array, index, array, index+1, size-index); + System.arraycopy(array, index, array, index+1, size-index-1); array[index] = element; } diff --git a/classpath/java/util/logging/Logger.java b/classpath/java/util/logging/Logger.java index e0635ee520..927be42175 100644 --- a/classpath/java/util/logging/Logger.java +++ b/classpath/java/util/logging/Logger.java @@ -6,7 +6,11 @@ import java.util.List; public class Logger { private final String name; - private static final ArrayList handlers = new ArrayList(); + private static final ArrayList handlers; + static { + handlers = new ArrayList(); + handlers.add(new DefaultHandler()); + } public static Logger getLogger(String name) { return new Logger(name); @@ -17,7 +21,7 @@ public class Logger { } public List getHandlers() { - return handlers; + return new ArrayList(handlers); } public void addHandler(Handler handler) { @@ -64,4 +68,57 @@ public class Logger { public void setLevel(Level level) { // Currently ignored } + + private static class DefaultHandler extends Handler { + private static final int NAME_WIDTH = 14; + private static final int METHOD_WIDTH = 15; + private static final int LEVEL_WIDTH = 8; + + public Object clone() { return this; } + public void close() { } + public void flush() { } + + private void maybeLogThrown(StringBuilder sb, Throwable t) { + if (t != null) { + sb.append("\nCaused by: "); + sb.append(t.getClass().getName()); + sb.append(": "); + sb.append(t.getMessage()); + sb.append('\n'); + + for (StackTraceElement elt : t.getStackTrace()) { + sb.append('\t'); + sb.append(elt.getClassName()); + sb.append('.'); + sb.append(elt.getMethodName()); + sb.append("(line"); + sb.append(':'); + sb.append(elt.getLineNumber()); + sb.append(')'); + sb.append('\n'); + } + maybeLogThrown(sb, t.getCause()); + } + } + + private void indent(StringBuilder sb, int amount) { + do { + sb.append(' '); + } while (--amount > 0); + } + + public void publish(LogRecord r) { + StringBuilder sb = new StringBuilder(); + sb.append(r.getLoggerName()); + indent(sb, NAME_WIDTH - r.getLoggerName().length()); + sb.append(r.getSourceMethodName()); + indent(sb, METHOD_WIDTH - r.getSourceMethodName().length()); + sb.append(r.getLevel().getName()); + indent(sb, LEVEL_WIDTH - r.getLevel().getName().length()); + sb.append(r.getMessage()); + maybeLogThrown(sb, r.getThrown()); + System.out.println(sb.toString()); + } + } + } diff --git a/src/builtin.cpp b/src/builtin.cpp index 588b006c00..03889d38aa 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -448,7 +448,7 @@ Java_java_lang_System_arraycopy { uint8_t* sbody = &cast(s, 2 * BytesPerWord); uint8_t* dbody = &cast(d, 2 * BytesPerWord); - if (src == dst) { + if (s == d) { memmove(dbody + (dstOffset * elementSize), sbody + (srcOffset * elementSize), length * elementSize); diff --git a/test/Logging.java b/test/Logging.java index 6805e43f2b..c6b2073366 100644 --- a/test/Logging.java +++ b/test/Logging.java @@ -92,11 +92,15 @@ public class Logging { throw new Exception("Started here"); } + private static final boolean useCustomHandler = true; public static void main(String args[]) { - Logger root = Logger.getLogger(""); - root.addHandler(new MyHandler()); - for (Handler h : root.getHandlers()) root.removeHandler(h); - root.addHandler(new MyHandler()); + if (useCustomHandler) { + Logger root = Logger.getLogger(""); + root.addHandler(new MyHandler()); + for (Handler h : root.getHandlers()) root.removeHandler(h); + root.addHandler(new MyHandler()); + } + Logging me = new Logging(); me.run(); }