diff options
Diffstat (limited to 'libjava/classpath/java/lang')
20 files changed, 343 insertions, 24 deletions
diff --git a/libjava/classpath/java/lang/AssertionError.java b/libjava/classpath/java/lang/AssertionError.java index 778eb583051..cf953f4498b 100644 --- a/libjava/classpath/java/lang/AssertionError.java +++ b/libjava/classpath/java/lang/AssertionError.java @@ -1,5 +1,5 @@ /* AssertionError.java -- indication of a failed assertion - Copyright (C) 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -145,4 +145,16 @@ public class AssertionError extends Error { super(Double.toString(msg)); } + + /** + * Construct an AssertionError with detail message and cause. + * + * @param msg Detail message. + * @param cause The cause of this exception, may be null + * @since 1.7 + */ + public AssertionError(String msg, Throwable cause) + { + super(msg, cause); + } } diff --git a/libjava/classpath/java/lang/AutoCloseable.java b/libjava/classpath/java/lang/AutoCloseable.java new file mode 100644 index 00000000000..4c1ddaa3204 --- /dev/null +++ b/libjava/classpath/java/lang/AutoCloseable.java @@ -0,0 +1,50 @@ +/* AutoCloseable.java -- Resource that must be closed after it is no longer + used. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang; + +/** + * Resource that must be closed after it is no longer used. + * + * @since 1.7 + */ +public interface AutoCloseable +{ + void close() throws Exception; +} diff --git a/libjava/classpath/java/lang/Boolean.java b/libjava/classpath/java/lang/Boolean.java index f2eaf412592..0e4afa813bf 100644 --- a/libjava/classpath/java/lang/Boolean.java +++ b/libjava/classpath/java/lang/Boolean.java @@ -237,6 +237,21 @@ public final class Boolean implements Serializable, Comparable<Boolean> } /** + * Compares two unboxed boolean values. + * + * @param x First value to compare. + * @param y Second value to compare. + * @return 0 if both Booleans represent the same value, a positive number + * if this Boolean represents true and the other false, and a negative + * number otherwise. + * @since 1.7 + */ + public static int compare(boolean x, boolean y) + { + return Boolean.valueOf(x).compareTo(Boolean.valueOf(y)); + } + + /** * If the String argument is "true", ignoring case, return true. * Otherwise, return false. * diff --git a/libjava/classpath/java/lang/Byte.java b/libjava/classpath/java/lang/Byte.java index a1536e1be1b..01e0e03d2f6 100644 --- a/libjava/classpath/java/lang/Byte.java +++ b/libjava/classpath/java/lang/Byte.java @@ -370,4 +370,21 @@ public final class Byte extends Number implements Comparable<Byte> return value - b.value; } + /** + * Compares two unboxed byte values. + * The result is positive if the first is greater, negative if the second + * is greater, and 0 if the two are equal. + * + * @param x First value to compare. + * @param y Second value to compare. + * + * @return positive int if the first value is greater, negative if the second + * is greater, and 0 if the two are equal. + * @since 1.7 + */ + public static int compare(byte x, byte y) + { + return Byte.valueOf(x).compareTo(Byte.valueOf(y)); + } + } diff --git a/libjava/classpath/java/lang/Character.java b/libjava/classpath/java/lang/Character.java index 05e641c3a48..f87cde62c1e 100644 --- a/libjava/classpath/java/lang/Character.java +++ b/libjava/classpath/java/lang/Character.java @@ -4200,6 +4200,23 @@ public final class Character implements Serializable, Comparable<Character> } /** + * Compares two unboxed char values. + * The result is positive if the first is greater, negative if the second + * is greater, and 0 if the two are equal. + * + * @param x First value to compare. + * @param y Second value to compare. + * + * @return positive int if the first value is greater, negative if the second + * is greater, and 0 if the two are equal. + * @since 1.7 + */ + public static int compare(char x, char y) + { + return Character.valueOf(x).compareTo(Character.valueOf(y)); + } + + /** * Returns an <code>Character</code> object wrapping the value. * In contrast to the <code>Character</code> constructor, this method * will cache some values. It is used by boxing conversion. diff --git a/libjava/classpath/java/lang/ClassNotFoundException.java b/libjava/classpath/java/lang/ClassNotFoundException.java index 142bc5d0306..fe1424dc2b1 100644 --- a/libjava/classpath/java/lang/ClassNotFoundException.java +++ b/libjava/classpath/java/lang/ClassNotFoundException.java @@ -1,5 +1,5 @@ /* ClassNotFoundException.java -- thrown when class definition cannot be found - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -47,9 +47,9 @@ package java.lang; * @see Class#forName(String) * @see ClassLoader#findSystemClass(String) * @see ClassLoader#loadClass(String, boolean) - * @status updated to 1.4 + * @status updated to 1.7 */ -public class ClassNotFoundException extends Exception +public class ClassNotFoundException extends ReflectiveOperationException { /** * Compatible with JDK 1.0+. diff --git a/libjava/classpath/java/lang/IllegalAccessException.java b/libjava/classpath/java/lang/IllegalAccessException.java index a352c8b1b31..2574f66047c 100644 --- a/libjava/classpath/java/lang/IllegalAccessException.java +++ b/libjava/classpath/java/lang/IllegalAccessException.java @@ -1,6 +1,6 @@ /* IllegalAccessException.java -- thrown on attempt to reflect on inaccessible data - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -71,9 +71,9 @@ import java.lang.reflect.Method; * @see Field#getDouble(Object) * @see Method#invoke(Object, Object[]) * @see Constructor#newInstance(Object[]) - * @status updated to 1.4 + * @status updated to 1.7 */ -public class IllegalAccessException extends Exception +public class IllegalAccessException extends ReflectiveOperationException { /** * Compatible with JDK 1.0+. diff --git a/libjava/classpath/java/lang/InstantiationException.java b/libjava/classpath/java/lang/InstantiationException.java index 367b14bd278..cb2cad15432 100644 --- a/libjava/classpath/java/lang/InstantiationException.java +++ b/libjava/classpath/java/lang/InstantiationException.java @@ -1,6 +1,6 @@ /* InstantiationException.java -- thrown when reflection cannot create an instance - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -46,9 +46,9 @@ package java.lang; * @author Brian Jones * @author Warren Levy (warrenl@cygnus.com) * @see Class#newInstance() - * @status updated to 1.4 + * @status updated to 1.7 */ -public class InstantiationException extends Exception +public class InstantiationException extends ReflectiveOperationException { /** * Compatible with JDK 1.0+. diff --git a/libjava/classpath/java/lang/Integer.java b/libjava/classpath/java/lang/Integer.java index f379795ea3d..25eb5d5265d 100644 --- a/libjava/classpath/java/lang/Integer.java +++ b/libjava/classpath/java/lang/Integer.java @@ -586,6 +586,23 @@ public final class Integer extends Number implements Comparable<Integer> } /** + * Compares two unboxed int values. + * The result is positive if the first is greater, negative if the second + * is greater, and 0 if the two are equal. + * + * @param x First value to compare. + * @param y Second value to compare. + * + * @return positive int if the first value is greater, negative if the second + * is greater, and 0 if the two are equal. + * @since 1.7 + */ + public static int compare(int x, int y) + { + return Integer.valueOf(x).compareTo(Integer.valueOf(y)); + } + + /** * Return the number of bits set in x. * @param x value to examine * @since 1.5 diff --git a/libjava/classpath/java/lang/LinkageError.java b/libjava/classpath/java/lang/LinkageError.java index 028702081ba..34b072572cf 100644 --- a/libjava/classpath/java/lang/LinkageError.java +++ b/libjava/classpath/java/lang/LinkageError.java @@ -1,6 +1,6 @@ /* LinkageError.java -- thrown when classes valid at separate compile times cannot be linked to each other - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -46,7 +46,7 @@ package java.lang; * * @author Brian Jones * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 + * @status updated to 1.7 */ public class LinkageError extends Error { @@ -71,4 +71,17 @@ public class LinkageError extends Error { super(s); } + + /** + * Construct an LinkageError with detail message and cause. + * + * @param msg Detail message. + * @param cause The cause of this exception, may be null + * @since 1.7 + */ + public LinkageError(String msg, Throwable cause) + { + super(msg, cause); + } + } diff --git a/libjava/classpath/java/lang/Long.java b/libjava/classpath/java/lang/Long.java index e7579d86556..6f31dfa9953 100644 --- a/libjava/classpath/java/lang/Long.java +++ b/libjava/classpath/java/lang/Long.java @@ -585,6 +585,23 @@ public final class Long extends Number implements Comparable<Long> } /** + * Compares two unboxed long values. + * The result is positive if the first is greater, negative if the second + * is greater, and 0 if the two are equal. + * + * @param x First value to compare. + * @param y Second value to compare. + * + * @return positive int if the first value is greater, negative if the second + * is greater, and 0 if the two are equal. + * @since 1.7 + */ + public static int compare(long x, long y) + { + return Long.valueOf(x).compareTo(Long.valueOf(y)); + } + + /** * Return the number of bits set in x. * @param x value to examine * @since 1.5 diff --git a/libjava/classpath/java/lang/NoSuchFieldException.java b/libjava/classpath/java/lang/NoSuchFieldException.java index 74d52d137c4..b43b53206ad 100644 --- a/libjava/classpath/java/lang/NoSuchFieldException.java +++ b/libjava/classpath/java/lang/NoSuchFieldException.java @@ -1,5 +1,5 @@ /* NoSuchFieldException.java -- thrown when reflecting a non-existant field - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,9 +45,9 @@ package java.lang; * @author Brian Jones * @author Warren Levy (warrenl@cygnus.com) * @since 1.1 - * @status updated to 1.4 + * @status updated to 1.7 */ -public class NoSuchFieldException extends Exception +public class NoSuchFieldException extends ReflectiveOperationException { /** * Compatible with JDK 1.1+. diff --git a/libjava/classpath/java/lang/NoSuchMethodException.java b/libjava/classpath/java/lang/NoSuchMethodException.java index e423efb79f6..116238220be 100644 --- a/libjava/classpath/java/lang/NoSuchMethodException.java +++ b/libjava/classpath/java/lang/NoSuchMethodException.java @@ -1,5 +1,5 @@ /* NoSuchMethodException.java -- thrown when reflecting a non-existant method - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,9 +44,9 @@ package java.lang; * * @author Brian Jones * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 + * @status updated to 1.7 */ -public class NoSuchMethodException extends Exception +public class NoSuchMethodException extends ReflectiveOperationException { /** * Compatible with JDK 1.0+. diff --git a/libjava/classpath/java/lang/ReflectiveOperationException.java b/libjava/classpath/java/lang/ReflectiveOperationException.java new file mode 100644 index 00000000000..8b84c0e290f --- /dev/null +++ b/libjava/classpath/java/lang/ReflectiveOperationException.java @@ -0,0 +1,88 @@ +/* ReflectiveOperationException.java -- thrown when reflective operation fails + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang; + +/** + * This exception is thrown when reflective operations fail. + * + * @since 1.7 + */ +public class ReflectiveOperationException extends Exception +{ + private static final long serialVersionUID = 123456789L; + + /** + * Create an exception without a message. + */ + public ReflectiveOperationException() + { + } + + /** + * Create an exception with a message. + * + * @param s the message + */ + public ReflectiveOperationException(String s) + { + super(s); + } + + /** + * Create an exception with a message and a cause. + * + * @param s the message + * @param cause the cause, may be null + */ + public ReflectiveOperationException(String message, Throwable cause) + { + super(message, cause); + } + + /** + * Create an exception with a cause. + * + * @param cause the cause, may be null + */ + public ReflectiveOperationException(Throwable cause) + { + super(cause); + } + +} diff --git a/libjava/classpath/java/lang/Short.java b/libjava/classpath/java/lang/Short.java index ec87f933e93..fae9fe7635b 100644 --- a/libjava/classpath/java/lang/Short.java +++ b/libjava/classpath/java/lang/Short.java @@ -373,6 +373,23 @@ public final class Short extends Number implements Comparable<Short> } /** + * Compares two unboxed short values. + * The result is positive if the first is greater, negative if the second + * is greater, and 0 if the two are equal. + * + * @param x First value to compare. + * @param y Second value to compare. + * + * @return positive int if the first value is greater, negative if the second + * is greater, and 0 if the two are equal. + * @since 1.7 + */ + public static int compare(short x, short y) + { + return Short.valueOf(x).compareTo(Short.valueOf(y)); + } + + /** * Reverse the bytes in val. * @since 1.5 */ diff --git a/libjava/classpath/java/lang/String.java b/libjava/classpath/java/lang/String.java index 45c0daff673..27294cdd4eb 100644 --- a/libjava/classpath/java/lang/String.java +++ b/libjava/classpath/java/lang/String.java @@ -705,6 +705,8 @@ public final class String */ public synchronized int codePointAt(int index) { + if (index < 0 || index >= count) + throw new StringIndexOutOfBoundsException(index); // Use the CharSequence overload as we get better range checking // this way. return Character.codePointAt(this, index); @@ -716,12 +718,14 @@ public final class String * <code>index-2</code> to see if they form a supplementary code point. * @param index the index just past the codepoint to get, starting at 0 * @return the codepoint at the specified index - * @throws IndexOutOfBoundsException if index is negative or >= length() + * @throws IndexOutOfBoundsException if index is less than 1 or > length() * (while unspecified, this is a StringIndexOutOfBoundsException) * @since 1.5 */ public synchronized int codePointBefore(int index) { + if (index < 1 || index > count) + throw new StringIndexOutOfBoundsException(index); // Use the CharSequence overload as we get better range checking // this way. return Character.codePointBefore(this, index); diff --git a/libjava/classpath/java/lang/System.java b/libjava/classpath/java/lang/System.java index 51b3259fa8b..9d869918300 100644 --- a/libjava/classpath/java/lang/System.java +++ b/libjava/classpath/java/lang/System.java @@ -97,6 +97,8 @@ public final class System */ public static final PrintStream out = VMSystem.makeStandardOutputStream(); + private static final String LINE_SEPARATOR = SystemProperties.getProperty("line.separator"); + /** * The standard output PrintStream. This is assigned at startup and * starts its life perfectly valid. Although it is marked final, you can @@ -713,6 +715,16 @@ public final class System } /** + * Returns the system-dependent line separator. + * + * @return the system-dependent line separator. + */ + public static String lineSeparator() + { + return LINE_SEPARATOR; + } + + /** * This is a specialised <code>Collection</code>, providing * the necessary provisions for the collections used by the * environment variable map. Namely, it prevents diff --git a/libjava/classpath/java/lang/reflect/InvocationTargetException.java b/libjava/classpath/java/lang/reflect/InvocationTargetException.java index af79d3a199d..4480fc6d006 100644 --- a/libjava/classpath/java/lang/reflect/InvocationTargetException.java +++ b/libjava/classpath/java/lang/reflect/InvocationTargetException.java @@ -1,5 +1,5 @@ /* InvocationTargetException.java -- Wrapper exception for reflection - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -50,9 +50,9 @@ package java.lang.reflect; * @see Method#invoke(Object,Object[]) * @see Constructor#newInstance(Object[]) * @since 1.1 - * @status updated to 1.4 + * @status updated to 1.7 */ -public class InvocationTargetException extends Exception +public class InvocationTargetException extends ReflectiveOperationException { /** * Compatible with JDK 1.1+. diff --git a/libjava/classpath/java/lang/reflect/Member.java b/libjava/classpath/java/lang/reflect/Member.java index fed962cf913..945fbf69663 100644 --- a/libjava/classpath/java/lang/reflect/Member.java +++ b/libjava/classpath/java/lang/reflect/Member.java @@ -79,7 +79,7 @@ public interface Member * * @return the class that declared this member */ - Class getDeclaringClass(); + Class<?> getDeclaringClass(); /** * Gets the simple name of this member. This will be a valid Java diff --git a/libjava/classpath/java/lang/reflect/Modifier.java b/libjava/classpath/java/lang/reflect/Modifier.java index 15bad05e738..c75f7b81823 100644 --- a/libjava/classpath/java/lang/reflect/Modifier.java +++ b/libjava/classpath/java/lang/reflect/Modifier.java @@ -1,5 +1,5 @@ /* java.lang.reflect.Modifier - Copyright (C) 1998, 1999, 2001, 2002, 2005, 2008 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005, 2008, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -300,6 +300,46 @@ public class Modifier } /** + * @since 1.7 + */ + public static int classModifiers() + { + return PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT | FINAL | STRICT; + } + + /** + * @since 1.7 + */ + public static int interfaceModifiers() + { + return PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT | STRICT; + } + + /** + * @since 1.7 + */ + public static int constructorModifiers() + { + return PUBLIC | PROTECTED | PRIVATE; + } + + /** + * @since 1.7 + */ + public static int methodModifiers() + { + return PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT | FINAL | STRICT | SYNCHRONIZED | NATIVE; + } + + /** + * @since 1.7 + */ + public static int fieldModifiers() + { + return PUBLIC | PROTECTED | PRIVATE | STATIC | FINAL | TRANSIENT | VOLATILE; + } + + /** * Get a string representation of all the modifiers represented by the * given int. The keywords are printed in this order: * <code><public|protected|private> abstract static final transient |