OpenJDK / jdk / hs
changeset 42719:c13f9bb1fe4a
Merge
author | prr |
---|---|
date | Tue, 22 Nov 2016 11:46:06 -0800 |
parents | 96221842d2f1 5c88c0c3d165 |
children | 9690e3d8af61 |
files | jdk/test/java/util/Locale/LocaleTestFmwk.java jdk/test/javax/net/ssl/templates/SSLSocketSample.java jdk/test/javax/net/ssl/templates/SSLTest.java jdk/test/sun/tools/jps/JpsBase.java jdk/test/sun/tools/jps/TestJpsClass.java jdk/test/sun/tools/jps/TestJpsJar.java jdk/test/sun/tools/jps/TestJpsJarRelative.java langtools/test/jdk/javadoc/doclet/testOrdering/order/MethodOrder.java |
diffstat | 244 files changed, 9212 insertions(+), 5458 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Mon Nov 21 15:04:37 2016 -0800 +++ b/.hgtags Tue Nov 22 11:46:06 2016 -0800 @@ -386,3 +386,4 @@ 9aadd2163b568d76f8969ad2fb404a63733da359 jdk-9+141 df0e03e3ca0ed1307793017dfc1a054c8726131c jdk-9+142 d62173b931bf5b6bffc6e80a9060bb2e8b8efc75 jdk-9+143 +31f5023200d42185b70c4c00ba5672391e4642d0 jdk-9+144
--- a/.hgtags-top-repo Mon Nov 21 15:04:37 2016 -0800 +++ b/.hgtags-top-repo Tue Nov 22 11:46:06 2016 -0800 @@ -386,3 +386,4 @@ f64afae7f1a5608e438585bbf0bc23785e69cba0 jdk-9+141 2b3e5caafe3594ea507c37675c4d3086f415dc64 jdk-9+142 1fc62b1c629fb80fdaa639d3b59452a184f0d705 jdk-9+143 +8d337fd6333e28c48aa87880144b840aad82baaf jdk-9+144
--- a/common/autoconf/flags.m4 Mon Nov 21 15:04:37 2016 -0800 +++ b/common/autoconf/flags.m4 Tue Nov 22 11:46:06 2016 -0800 @@ -942,7 +942,7 @@ # Little endian machine uses ELFv2 ABI. $2JVM_CFLAGS="[$]$2JVM_CFLAGS -DABI_ELFv2" # Use Power8, this is the first CPU to support PPC64 LE with ELFv2 ABI. - $2JVM_CFLAGS="[$]$2JVM_CFLAGS -mcpu=power7 -mtune=power8" + $2JVM_CFLAGS="[$]$2JVM_CFLAGS -mcpu=power8 -mtune=power8" fi elif test "x$OPENJDK_$1_CPU" = xs390x; then if test "x$OPENJDK_$1_OS" = xlinux; then
--- a/common/autoconf/generated-configure.sh Mon Nov 21 15:04:37 2016 -0800 +++ b/common/autoconf/generated-configure.sh Tue Nov 22 11:46:06 2016 -0800 @@ -5093,7 +5093,7 @@ #CUSTOM_AUTOCONF_INCLUDE # Do not change or remove the following line, it is needed for consistency checks: -DATE_WHEN_GENERATED=1478524503 +DATE_WHEN_GENERATED=1479120453 ############################################################################### # @@ -50124,7 +50124,7 @@ # Little endian machine uses ELFv2 ABI. JVM_CFLAGS="$JVM_CFLAGS -DABI_ELFv2" # Use Power8, this is the first CPU to support PPC64 LE with ELFv2 ABI. - JVM_CFLAGS="$JVM_CFLAGS -mcpu=power7 -mtune=power8" + JVM_CFLAGS="$JVM_CFLAGS -mcpu=power8 -mtune=power8" fi elif test "x$OPENJDK_TARGET_CPU" = xs390x; then if test "x$OPENJDK_TARGET_OS" = xlinux; then @@ -50948,7 +50948,7 @@ # Little endian machine uses ELFv2 ABI. OPENJDK_BUILD_JVM_CFLAGS="$OPENJDK_BUILD_JVM_CFLAGS -DABI_ELFv2" # Use Power8, this is the first CPU to support PPC64 LE with ELFv2 ABI. - OPENJDK_BUILD_JVM_CFLAGS="$OPENJDK_BUILD_JVM_CFLAGS -mcpu=power7 -mtune=power8" + OPENJDK_BUILD_JVM_CFLAGS="$OPENJDK_BUILD_JVM_CFLAGS -mcpu=power8 -mtune=power8" fi elif test "x$OPENJDK_BUILD_CPU" = xs390x; then if test "x$OPENJDK_BUILD_OS" = xlinux; then
--- a/common/bin/compare.sh Mon Nov 21 15:04:37 2016 -0800 +++ b/common/bin/compare.sh Tue Nov 22 11:46:06 2016 -0800 @@ -372,7 +372,7 @@ $CAT $OTHER_DIR/$f | eval "$HTML_FILTER" > $OTHER_FILE & $CAT $THIS_DIR/$f | eval "$HTML_FILTER" > $THIS_FILE & wait - elif [ "$f" = "./lib/classlist" ]; then + elif [[ "$f" = *"/lib/classlist" ]]; then # The classlist files may have some lines in random order OTHER_FILE=$WORK_DIR/$f.other THIS_FILE=$WORK_DIR/$f.this @@ -642,69 +642,18 @@ if [ "$OPENJDK_TARGET_OS" = "windows" ]; then unset _NT_SYMBOL_PATH - # On windows we need to unzip the debug symbols, if present - OTHER_FILE_BASE=${OTHER_FILE/.dll/} - OTHER_FILE_BASE=${OTHER_FILE_BASE/.exe/} - OTHER_FILE_BASE=${OTHER_FILE_BASE/.cpl/} - DIZ_NAME=$(basename $OTHER_FILE_BASE).diz - # Some .exe files have the same name as a .dll file. Make sure the exe - # files get the right debug symbols. - if [ "$NAME" = "java.exe" ] \ - && [ -f "$OTHER/support/native/java.base/java_objs/java.diz" ]; then - OTHER_DIZ_FILE="$OTHER/support/native/java.base/java_objs/java.diz" - elif [ "$NAME" = "jimage.exe" ] \ - && [ -f "$OTHER/support/native/jdk.jlink/jimage_objs/jimage.diz" ]; then - OTHER_DIZ_FILE="$OTHER/support/modules_cmds/jdk.jlink/jimage.diz" - elif [ "$NAME" = "javacpl.exe" ] \ - && [ -f "$OTHER/support/native/jdk.plugin/javacpl/javacpl.diz" ]; then - OTHER_DIZ_FILE="$OTHER/support/modules_cmds/jdk.deploy.controlpanel/javacpl.diz" - elif [ -f "${OTHER_FILE_BASE}.diz" ]; then - OTHER_DIZ_FILE=${OTHER_FILE_BASE}.diz - else - # Some files, jli.dll, appears twice in the image but only one of - # them has a diz file next to it. - OTHER_DIZ_FILE="$($FIND $OTHER_DIR -name $DIZ_NAME | $SED 1q)" - if [ ! -f "$OTHER_DIZ_FILE" ]; then - # As a last resort, look for diz file in the whole build output - # dir. - OTHER_DIZ_FILE="$($FIND $OTHER -name $DIZ_NAME | $SED 1q)" - fi + if [ "$(uname -o)" = "Cygwin" ]; then + THIS=$(cygpath -msa $THIS) + OTHER=$(cygpath -msa $OTHER) fi - if [ -n "$OTHER_DIZ_FILE" ]; then - $MKDIR -p $FILE_WORK_DIR/other - (cd $FILE_WORK_DIR/other ; $UNARCHIVE -o $OTHER_DIZ_FILE) - export _NT_SYMBOL_PATH="$FILE_WORK_DIR/other" - fi - - THIS_FILE_BASE=${THIS_FILE/.dll/} - THIS_FILE_BASE=${THIS_FILE_BASE/.exe/} - THIS_FILE_BASE=${THIS_FILE_BASE/.cpl/} - # Some .exe files have the same name as a .dll file. Make sure the exe - # files get the right debug symbols. - if [ "$NAME" = "java.exe" ] \ - && [ -f "$THIS/support/native/java.base/java_objs/java.diz" ]; then - THIS_DIZ_FILE="$THIS/support/native/java.base/java_objs/java.diz" - elif [ "$NAME" = "jimage.exe" ] \ - && [ -f "$THIS/support/native/jdk.jlink/jimage_objs/jimage.diz" ]; then - THIS_DIZ_FILE="$THIS/support/modules_cmds/jdk.jlink/jimage.diz" - elif [ "$NAME" = "javacpl.exe" ] \ - && [ -f "$THIS/support/native/jdk.plugin/javacpl/javacpl.diz" ]; then - THIS_DIZ_FILE="$THIS/support/modules_cmds/jdk.deploy.controlpanel/javacpl.diz" - elif [ -f "${THIS_FILE_BASE}.diz" ]; then - THIS_DIZ_FILE=${THIS_FILE/.dll/}.diz - else - THIS_DIZ_FILE="$($FIND $THIS_DIR -name $DIZ_NAME | $SED 1q)" - if [ ! -f "$THIS_DIZ_FILE" ]; then - # As a last resort, look for diz file in the whole build output - # dir. - THIS_DIZ_FILE="$($FIND $THIS -name $DIZ_NAME | $SED 1q)" - fi - fi - if [ -n "$THIS_DIZ_FILE" ]; then - $MKDIR -p $FILE_WORK_DIR/this - (cd $FILE_WORK_DIR/this ; $UNARCHIVE -o $THIS_DIZ_FILE) - export _NT_SYMBOL_PATH="$_NT_SYMBOL_PATH;$FILE_WORK_DIR/this" - fi + # Build an _NT_SYMBOL_PATH that contains all known locations for + # pdb files. + PDB_DIRS="$(ls -d \ + {$OTHER,$THIS}/support/modules_{cmds,libs}/{*,*/*} \ + {$OTHER,$THIS}/support/demos/image/jvmti/*/lib \ + {$OTHER,$THIS}/support/native/java.base/java_objs \ + )" + export _NT_SYMBOL_PATH="$(echo $PDB_DIRS | tr ' ' ';')" fi if [ -z "$SKIP_BIN_DIFF" ]; then
--- a/common/bin/compare_exceptions.sh.incl Mon Nov 21 15:04:37 2016 -0800 +++ b/common/bin/compare_exceptions.sh.incl Tue Nov 22 11:46:06 2016 -0800 @@ -431,6 +431,8 @@ ACCEPTED_JARZIP_CONTENTS=" /modules_libs/java.security.jgss/w2k_lsa_auth.diz + /modules_libs/java.security.jgss/w2k_lsa_auth.pdb + /modules_libs/java.security.jgss/w2k_lsa_auth.map /modules_libs/java.security.jgss/w2k_lsa_auth.dll "
--- a/corba/.hgtags Mon Nov 21 15:04:37 2016 -0800 +++ b/corba/.hgtags Tue Nov 22 11:46:06 2016 -0800 @@ -386,3 +386,4 @@ b32f998da32b488ec7c4e9dbb3c750841b48e74d jdk-9+141 408c9c621938ca028e20bced0459f815de47eba8 jdk-9+142 6211236ef15ec796806357608b1dd1b70c258ece jdk-9+143 +d4f1dae174098e799c48948e866054c52e11a186 jdk-9+144
--- a/hotspot/.hgtags Mon Nov 21 15:04:37 2016 -0800 +++ b/hotspot/.hgtags Tue Nov 22 11:46:06 2016 -0800 @@ -546,3 +546,4 @@ 160a00bc6ed0af1fdf8418fc65e6bddbbc0c536d jdk-9+141 7b48d63dfd6b8e2657288de3d7b1f153dee02d7e jdk-9+142 d87d5d430c42342f0320ca7f5cbe0cbd1f9d62ba jdk-9+143 +6187b582d02aee38341dc8ce4011906e9b364e9f jdk-9+144
--- a/jaxp/.hgtags Mon Nov 21 15:04:37 2016 -0800 +++ b/jaxp/.hgtags Tue Nov 22 11:46:06 2016 -0800 @@ -386,3 +386,4 @@ 037c095ba0c345edbeaaab52fda913a76c3930c0 jdk-9+141 bdafa0cc34a97a2f8db4847a4efd34b407943591 jdk-9+142 ce81d03ad7320dca3d673374c1a33bc0efd9136a jdk-9+143 +99be33734ff62b75116b1202d49a4d4e1bda4226 jdk-9+144
--- a/jaxws/.hgtags Mon Nov 21 15:04:37 2016 -0800 +++ b/jaxws/.hgtags Tue Nov 22 11:46:06 2016 -0800 @@ -389,3 +389,4 @@ b2c18f755228d1d19a86cd7d5fa1abb6b1495dfb jdk-9+141 59101416d90160cfcb4f45dfbccaec15e2c27a29 jdk-9+142 1c988e708a06257119d54d8a57e99e3b0f37ff18 jdk-9+143 +92523c51d6a48b0a83912ba3cc43bc57b8159c2a jdk-9+144
--- a/jdk/.hgtags Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/.hgtags Tue Nov 22 11:46:06 2016 -0800 @@ -387,3 +387,4 @@ 6ce43dd8e954b452f330dd7a412df5107f7e1923 jdk-9+142 8dbc8594f9d5149bf1c22221272284609408227a jdk-9+143 efa71dc820eb8bd5a6c9f2f66f39c383ac3ee99d jdk-9+144 +99b7853cfbd8227c4441de4b6119c10742556840 jdk-9+145
--- a/jdk/src/java.base/linux/classes/sun/nio/ch/EPollArrayWrapper.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/linux/classes/sun/nio/ch/EPollArrayWrapper.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -118,7 +118,7 @@ // file descriptors higher than MAX_UPDATE_ARRAY_SIZE (unlimited case at // least) then the update is stored in a map. private final byte[] eventsLow = new byte[MAX_UPDATE_ARRAY_SIZE]; - private Map<Integer,Byte> eventsHigh; + private final Map<Integer,Byte> eventsHigh = new HashMap<>(); // Used by release and updateRegistrations to track whether a file // descriptor is registered with epoll. @@ -133,10 +133,6 @@ int allocationSize = NUM_EPOLLEVENTS * SIZE_EPOLLEVENT; pollArray = new AllocatedNativeObject(allocationSize, true); pollArrayAddress = pollArray.address(); - - // eventHigh needed when using file descriptors > 64k - if (OPEN_MAX > MAX_UPDATE_ARRAY_SIZE) - eventsHigh = new HashMap<>(); } void initInterrupt(int fd0, int fd1) {
--- a/jdk/src/java.base/share/classes/java/lang/Class.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/lang/Class.java Tue Nov 22 11:46:06 2016 -0800 @@ -2704,9 +2704,6 @@ * Reflection support. */ - // Caches for certain reflective results - private static boolean useCaches = true; - // reflection data that might get invalidated when JVM TI RedefineClasses() is called private static class ReflectionData<T> { volatile Field[] declaredFields; @@ -2739,8 +2736,7 @@ SoftReference<ReflectionData<T>> reflectionData = this.reflectionData; int classRedefinedCount = this.classRedefinedCount; ReflectionData<T> rd; - if (useCaches && - reflectionData != null && + if (reflectionData != null && (rd = reflectionData.get()) != null && rd.redefinedCount == classRedefinedCount) { return rd; @@ -2752,8 +2748,6 @@ private ReflectionData<T> newReflectionData(SoftReference<ReflectionData<T>> oldReflectionData, int classRedefinedCount) { - if (!useCaches) return null; - while (true) { ReflectionData<T> rd = new ReflectionData<>(classRedefinedCount); // try to CAS it... @@ -2819,7 +2813,6 @@ // be propagated to the outside world, but must instead be copied // via ReflectionFactory.copyField. private Field[] privateGetDeclaredFields(boolean publicOnly) { - checkInitted(); Field[] res; ReflectionData<T> rd = reflectionData(); if (rd != null) { @@ -2842,7 +2835,6 @@ // be propagated to the outside world, but must instead be copied // via ReflectionFactory.copyField. private Field[] privateGetPublicFields(Set<Class<?>> traversedInterfaces) { - checkInitted(); Field[] res; ReflectionData<T> rd = reflectionData(); if (rd != null) { @@ -2902,7 +2894,6 @@ // objects must NOT be propagated to the outside world, but must // instead be copied via ReflectionFactory.copyConstructor. private Constructor<T>[] privateGetDeclaredConstructors(boolean publicOnly) { - checkInitted(); Constructor<T>[] res; ReflectionData<T> rd = reflectionData(); if (rd != null) { @@ -2937,7 +2928,6 @@ // be propagated to the outside world, but must instead be copied // via ReflectionFactory.copyMethod. private Method[] privateGetDeclaredMethods(boolean publicOnly) { - checkInitted(); Method[] res; ReflectionData<T> rd = reflectionData(); if (rd != null) { @@ -3134,7 +3124,6 @@ // be propagated to the outside world, but must instead be copied // via ReflectionFactory.copyMethod. private Method[] privateGetPublicMethods() { - checkInitted(); Method[] res; ReflectionData<T> rd = reflectionData(); if (rd != null) { @@ -3445,7 +3434,7 @@ * @since 1.4 */ public boolean desiredAssertionStatus() { - ClassLoader loader = getClassLoader(); + ClassLoader loader = getClassLoader0(); // If the loader is null this is a system class, so ask the VM if (loader == null) return desiredAssertionStatus0(this); @@ -3490,39 +3479,6 @@ } private static ReflectionFactory reflectionFactory; - // To be able to query system properties as soon as they're available - private static boolean initted = false; - private static void checkInitted() { - if (initted) return; - AccessController.doPrivileged(new PrivilegedAction<>() { - public Void run() { - // Tests to ensure the system properties table is fully - // initialized. This is needed because reflection code is - // called very early in the initialization process (before - // command-line arguments have been parsed and therefore - // these user-settable properties installed.) We assume that - // if System.out is non-null then the System class has been - // fully initialized and that the bulk of the startup code - // has been run. - - if (System.out == null) { - // java.lang.System not yet fully initialized - return null; - } - - // Doesn't use Boolean.getBoolean to avoid class init. - String val = - System.getProperty("sun.reflect.noCaches"); - if (val != null && val.equals("true")) { - useCaches = false; - } - - initted = true; - return null; - } - }); - } - /** * Returns the elements of this enum class or null if this * Class object does not represent an enum type.
--- a/jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/BoundMethodHandle.java Tue Nov 22 11:46:06 2016 -0800 @@ -80,7 +80,7 @@ default : throw newInternalError("unexpected xtype: " + xtype); } } catch (Throwable t) { - throw newInternalError(t); + throw uncaughtException(t); } } @@ -188,7 +188,7 @@ case D_TYPE: return (double) speciesData().getters[i].invokeBasic(this); } } catch (Throwable ex) { - throw newInternalError(ex); + throw uncaughtException(ex); } throw new InternalError("unexpected type: " + speciesData().typeChars+"."+i); } @@ -408,18 +408,14 @@ */ static boolean speciesDataCachePopulated() { Class<BoundMethodHandle> rootCls = BoundMethodHandle.class; - try { - for (Class<?> c : rootCls.getDeclaredClasses()) { - if (rootCls.isAssignableFrom(c)) { - final Class<? extends BoundMethodHandle> cbmh = c.asSubclass(BoundMethodHandle.class); - SpeciesData d = Factory.getSpeciesDataFromConcreteBMHClass(cbmh); - assert(d != null) : cbmh.getName(); - assert(d.clazz == cbmh); - assert(CACHE.get(d.typeChars) == d); - } + for (Class<?> c : rootCls.getDeclaredClasses()) { + if (rootCls.isAssignableFrom(c)) { + final Class<? extends BoundMethodHandle> cbmh = c.asSubclass(BoundMethodHandle.class); + SpeciesData d = Factory.getSpeciesDataFromConcreteBMHClass(cbmh); + assert(d != null) : cbmh.getName(); + assert(d.clazz == cbmh); + assert(CACHE.get(d.typeChars) == d); } - } catch (Throwable e) { - throw newInternalError(e); } return true; }
--- a/jdk/src/java.base/share/classes/java/lang/invoke/CallSite.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/CallSite.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -272,7 +272,7 @@ MethodHandleNatives.setCallSiteTargetVolatile(this, newTarget); } - // this implements the upcall from the JVM, MethodHandleNatives.makeDynamicCallSite: + // this implements the upcall from the JVM, MethodHandleNatives.linkCallSite: static CallSite makeSite(MethodHandle bootstrapMethod, // Callee information: String name, MethodType type, @@ -293,59 +293,72 @@ Object[] argv = (Object[]) info; maybeReBoxElements(argv); switch (argv.length) { - case 0: - binding = bootstrapMethod.invoke(caller, name, type); - break; - case 1: - binding = bootstrapMethod.invoke(caller, name, type, - argv[0]); - break; - case 2: - binding = bootstrapMethod.invoke(caller, name, type, - argv[0], argv[1]); - break; - case 3: - binding = bootstrapMethod.invoke(caller, name, type, - argv[0], argv[1], argv[2]); - break; - case 4: - binding = bootstrapMethod.invoke(caller, name, type, - argv[0], argv[1], argv[2], argv[3]); - break; - case 5: - binding = bootstrapMethod.invoke(caller, name, type, - argv[0], argv[1], argv[2], argv[3], argv[4]); - break; - case 6: - binding = bootstrapMethod.invoke(caller, name, type, - argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); - break; - default: - final int NON_SPREAD_ARG_COUNT = 3; // (caller, name, type) - if (NON_SPREAD_ARG_COUNT + argv.length > MethodType.MAX_MH_ARITY) - throw new BootstrapMethodError("too many bootstrap method arguments"); - MethodType bsmType = bootstrapMethod.type(); - MethodType invocationType = MethodType.genericMethodType(NON_SPREAD_ARG_COUNT + argv.length); - MethodHandle typedBSM = bootstrapMethod.asType(invocationType); - MethodHandle spreader = invocationType.invokers().spreadInvoker(NON_SPREAD_ARG_COUNT); - binding = spreader.invokeExact(typedBSM, (Object)caller, (Object)name, (Object)type, argv); + case 0: + binding = bootstrapMethod.invoke(caller, name, type); + break; + case 1: + binding = bootstrapMethod.invoke(caller, name, type, + argv[0]); + break; + case 2: + binding = bootstrapMethod.invoke(caller, name, type, + argv[0], argv[1]); + break; + case 3: + binding = bootstrapMethod.invoke(caller, name, type, + argv[0], argv[1], argv[2]); + break; + case 4: + binding = bootstrapMethod.invoke(caller, name, type, + argv[0], argv[1], argv[2], argv[3]); + break; + case 5: + binding = bootstrapMethod.invoke(caller, name, type, + argv[0], argv[1], argv[2], argv[3], argv[4]); + break; + case 6: + binding = bootstrapMethod.invoke(caller, name, type, + argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); + break; + default: + final int NON_SPREAD_ARG_COUNT = 3; // (caller, name, type) + if (NON_SPREAD_ARG_COUNT + argv.length > MethodType.MAX_MH_ARITY) + throw new BootstrapMethodError("too many bootstrap method arguments"); + MethodType bsmType = bootstrapMethod.type(); + MethodType invocationType = MethodType.genericMethodType(NON_SPREAD_ARG_COUNT + argv.length); + MethodHandle typedBSM = bootstrapMethod.asType(invocationType); + MethodHandle spreader = invocationType.invokers().spreadInvoker(NON_SPREAD_ARG_COUNT); + binding = spreader.invokeExact(typedBSM, (Object) caller, (Object) name, (Object) type, argv); } } - //System.out.println("BSM for "+name+type+" => "+binding); if (binding instanceof CallSite) { site = (CallSite) binding; - } else { + } else { + // See the "Linking Exceptions" section for the invokedynamic + // instruction in JVMS 6.5. + // Throws a runtime exception defining the cause that is then + // in the "catch (Throwable ex)" a few lines below wrapped in + // BootstrapMethodError throw new ClassCastException("bootstrap method failed to produce a CallSite"); } - if (!site.getTarget().type().equals(type)) + if (!site.getTarget().type().equals(type)) { + // See the "Linking Exceptions" section for the invokedynamic + // instruction in JVMS 6.5. + // Throws a runtime exception defining the cause that is then + // in the "catch (Throwable ex)" a few lines below wrapped in + // BootstrapMethodError throw wrongTargetType(site.getTarget(), type); + } + } catch (Error e) { + // Pass through an Error, including BootstrapMethodError, any other + // form of linkage error, such as IllegalAccessError if the bootstrap + // method is inaccessible, or say ThreadDeath/OutOfMemoryError + // See the "Linking Exceptions" section for the invokedynamic + // instruction in JVMS 6.5. + throw e; } catch (Throwable ex) { - BootstrapMethodError bex; - if (ex instanceof BootstrapMethodError) - bex = (BootstrapMethodError) ex; - else - bex = new BootstrapMethodError("call site initialization exception", ex); - throw bex; + // Wrap anything else in BootstrapMethodError + throw new BootstrapMethodError("call site initialization exception", ex); } return site; }
--- a/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java Tue Nov 22 11:46:06 2016 -0800 @@ -1021,7 +1021,7 @@ try { emptyArray = name.function.resolvedHandle().invoke(); } catch (Throwable ex) { - throw newInternalError(ex); + throw uncaughtException(ex); } assert(java.lang.reflect.Array.getLength(emptyArray) == 0); assert(emptyArray.getClass() == rtype); // exact typing
--- a/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/LambdaForm.java Tue Nov 22 11:46:06 2016 -0800 @@ -855,7 +855,11 @@ System.out.println("LambdaForm compilation failed: " + this); bge.printStackTrace(System.out); } - } catch (Error | Exception e) { + } catch (Error e) { + // Pass through any error + throw e; + } catch (Exception e) { + // Wrap any exception throw newInternalError(this.toString(), e); } }
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java Tue Nov 22 11:46:06 2016 -0800 @@ -957,7 +957,7 @@ if (!fail) return needType; // elicit an error: this.asType(needType); - throw newInternalError("should not return", null); + throw newInternalError("should not return"); } private void spreadArrayChecks(Class<?> arrayType, int arrayLength) {
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java Tue Nov 22 11:46:06 2016 -0800 @@ -379,11 +379,13 @@ name, fixMethodType(callerClass, type), appendixResult); } } + } catch (Error e) { + // Pass through an Error, including say StackOverflowError or + // OutOfMemoryError + throw e; } catch (Throwable ex) { - if (ex instanceof LinkageError) - throw (LinkageError) ex; - else - throw new LinkageError(ex.getMessage(), ex); + // Wrap anything else in LinkageError + throw new LinkageError(ex.getMessage(), ex); } throw new LinkageError("no such method "+defc.getName()+"."+name+type); }
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java Tue Nov 22 11:46:06 2016 -0800 @@ -107,10 +107,10 @@ /*non-public*/ static InternalError newInternalError(String message) { return new InternalError(message); } - /*non-public*/ static InternalError newInternalError(String message, Throwable cause) { + /*non-public*/ static InternalError newInternalError(String message, Exception cause) { return new InternalError(message, cause); } - /*non-public*/ static InternalError newInternalError(Throwable cause) { + /*non-public*/ static InternalError newInternalError(Exception cause) { return new InternalError(cause); } /*non-public*/ static RuntimeException newIllegalStateException(String message) { @@ -132,7 +132,7 @@ /*non-public*/ static Error uncaughtException(Throwable ex) { if (ex instanceof Error) throw (Error) ex; if (ex instanceof RuntimeException) throw (RuntimeException) ex; - throw newInternalError("uncaught exception", ex); + throw new InternalError("uncaught exception", ex); } private static String message(String message, Object obj) { if (obj != null) message = message + ": " + obj;
--- a/jdk/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java Tue Nov 22 11:46:06 2016 -0800 @@ -723,6 +723,9 @@ default: throw new StringConcatException("Concatenation strategy " + STRATEGY + " is not implemented"); } + } catch (Error | StringConcatException e) { + // Pass through any error or existing StringConcatException + throw e; } catch (Throwable t) { throw new StringConcatException("Generator failed", t); } @@ -1092,9 +1095,9 @@ UNSAFE.ensureClassInitialized(innerClass); dumpIfEnabled(innerClass.getName(), classBytes); return Lookup.IMPL_LOOKUP.findStatic(innerClass, METHOD_NAME, args); - } catch (Throwable e) { + } catch (Exception e) { dumpIfEnabled(className + "$$FAILED", classBytes); - throw new StringConcatException("Error while spinning the class", e); + throw new StringConcatException("Exception while spinning the class", e); } }
--- a/jdk/src/java.base/share/classes/java/lang/invoke/package-info.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/package-info.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -84,20 +84,21 @@ * </ul> * Invocation is as if by * {@link java.lang.invoke.MethodHandle#invoke MethodHandle.invoke}. - * The returned result must be a {@link java.lang.invoke.CallSite CallSite} (or a subclass). + * The returned result must be a {@link java.lang.invoke.CallSite CallSite} + * (or a subclass), otherwise a + * {@link java.lang.BootstrapMethodError BootstrapMethodError} is thrown. * The type of the call site's target must be exactly equal to the type * derived from the dynamic call site's type descriptor and passed to - * the bootstrap method. - * The call site then becomes permanently linked to the dynamic call site. + * the bootstrap method, otherwise a {@code BootstrapMethodError} is thrown. + * On success the call site then becomes permanently linked to the dynamic call + * site. * <p> - * As documented in the JVM specification, all failures arising from - * the linkage of a dynamic call site are reported - * by a {@link java.lang.BootstrapMethodError BootstrapMethodError}, - * which is thrown as the abnormal termination of the dynamic call - * site execution. - * If this happens, the same error will the thrown for all subsequent - * attempts to execute the dynamic call site. - * + * If an exception, {@code E} say, occurs when linking the call site then the + * linkage fails and terminates abnormally. {@code E} is rethrown if the type of + * {@code E} is {@code Error} or a subclass, otherwise a + * {@code BootstrapMethodError} that wraps {@code E} is thrown. + * If this happens, the same {@code Error} or subclass will the thrown for all + * subsequent attempts to execute the dynamic call site. * <h2>timing of linkage</h2> * A dynamic call site is linked just before its first execution. * The bootstrap method call implementing the linkage occurs within
--- a/jdk/src/java.base/share/classes/java/net/Authenticator.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/net/Authenticator.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -131,6 +131,35 @@ } /** + * Gets the default authenticator. + * First, if there is a security manager, its {@code checkPermission} + * method is called with a + * {@code NetPermission("requestPasswordAuthentication")} permission. + * This may result in a java.lang.SecurityException. + * Then the default authenticator, if set, is returned. + * Otherwise, {@code null} is returned. + * + * @return The default authenticator, if set, {@code null} otherwise. + * + * @throws SecurityException + * if a security manager exists and its + * {@code checkPermission} method doesn't allow + * requesting password authentication. + * @since 9 + * @see SecurityManager#checkPermission + * @see java.net.NetPermission + */ + public static Authenticator getDefault() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + NetPermission requestPermission + = new NetPermission("requestPasswordAuthentication"); + sm.checkPermission(requestPermission); + } + return theAuthenticator; + } + + /** * Ask the authenticator that has been registered with the system * for a password. * <p>
--- a/jdk/src/java.base/share/classes/java/security/ProtectionDomain.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/security/ProtectionDomain.java Tue Nov 22 11:46:06 2016 -0800 @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.List; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import jdk.internal.misc.JavaSecurityAccess; import jdk.internal.misc.JavaSecurityProtectionDomainAccess; @@ -524,7 +525,7 @@ // have some side effects so this manual // comparison is sufficient. if (pdpName.equals(pp.getName()) && - pdpActions.equals(pp.getActions())) { + Objects.equals(pdpActions, pp.getActions())) { plVector.remove(i); break; }
--- a/jdk/src/java.base/share/classes/java/security/SecureRandom.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/security/SecureRandom.java Tue Nov 22 11:46:06 2016 -0800 @@ -120,6 +120,24 @@ * gathered, for example, if the entropy source is /dev/random on various * Unix-like operating systems. * + * <h2> Thread safety </h2> + * {@code SecureRandom} objects are safe for use by multiple concurrent threads. + * + * @implSpec + * A {@code SecureRandom} service provider can advertise that it is thread-safe + * by setting the <a href= + * "{@docRoot}/../technotes/guides/security/StandardNames.html#Service">service + * provider attribute</a> "ThreadSafe" to "true" when registering the provider. + * Otherwise, this class will instead synchronize access to the following + * methods of the {@code SecureRandomSpi} implementation: + * <ul> + * <li>{@link SecureRandomSpi#engineSetSeed(byte[])} + * <li>{@link SecureRandomSpi#engineNextBytes(byte[])} + * <li>{@link SecureRandomSpi#engineNextBytes(byte[], SecureRandomParameters)} + * <li>{@link SecureRandomSpi#engineGenerateSeed(int)} + * <li>{@link SecureRandomSpi#engineReseed(SecureRandomParameters)} + * </ul> + * * @see java.security.SecureRandomSpi * @see java.util.Random * @@ -150,6 +168,14 @@ */ private SecureRandomSpi secureRandomSpi = null; + /** + * Thread safety. + * + * @serial + * @since 9 + */ + private final boolean threadSafe; + /* * The algorithm name of null if unknown. * @@ -189,6 +215,16 @@ */ super(0); getDefaultPRNG(false, null); + this.threadSafe = getThreadSafe(); + } + + private boolean getThreadSafe() { + if (provider == null || algorithm == null) { + return false; + } else { + return Boolean.parseBoolean(provider.getProperty( + "SecureRandom." + algorithm + " ThreadSafe", "false")); + } } /** @@ -217,6 +253,7 @@ public SecureRandom(byte[] seed) { super(0); getDefaultPRNG(true, seed); + this.threadSafe = getThreadSafe(); } private void getDefaultPRNG(boolean setSeed, byte[] seed) { @@ -269,6 +306,7 @@ this.secureRandomSpi = secureRandomSpi; this.provider = provider; this.algorithm = algorithm; + this.threadSafe = getThreadSafe(); if (!skipDebug && pdebug != null) { pdebug.println("SecureRandom." + algorithm + @@ -653,8 +691,14 @@ * * @see #getSeed */ - public synchronized void setSeed(byte[] seed) { - secureRandomSpi.engineSetSeed(seed); + public void setSeed(byte[] seed) { + if (threadSafe) { + secureRandomSpi.engineSetSeed(seed); + } else { + synchronized (this) { + secureRandomSpi.engineSetSeed(seed); + } + } } /** @@ -679,7 +723,7 @@ * yet been initialized at that point. */ if (seed != 0) { - this.secureRandomSpi.engineSetSeed(longToByteArray(seed)); + setSeed(longToByteArray(seed)); } } @@ -690,7 +734,13 @@ */ @Override public void nextBytes(byte[] bytes) { - secureRandomSpi.engineNextBytes(bytes); + if (threadSafe) { + secureRandomSpi.engineNextBytes(bytes); + } else { + synchronized (this) { + secureRandomSpi.engineNextBytes(bytes); + } + } } /** @@ -707,12 +757,19 @@ * * @since 9 */ - public synchronized void nextBytes( - byte[] bytes, SecureRandomParameters params) { + public void nextBytes(byte[] bytes, SecureRandomParameters params) { if (params == null) { throw new IllegalArgumentException("params cannot be null"); } - secureRandomSpi.engineNextBytes(Objects.requireNonNull(bytes), params); + if (threadSafe) { + secureRandomSpi.engineNextBytes( + Objects.requireNonNull(bytes), params); + } else { + synchronized (this) { + secureRandomSpi.engineNextBytes( + Objects.requireNonNull(bytes), params); + } + } } /** @@ -756,6 +813,7 @@ * * @param numBytes the number of seed bytes to generate. * + * @throws IllegalArgumentException if {@code numBytes} is negative * @return the seed bytes. * * @see #setSeed @@ -782,7 +840,13 @@ if (numBytes < 0) { throw new IllegalArgumentException("numBytes cannot be negative"); } - return secureRandomSpi.engineGenerateSeed(numBytes); + if (threadSafe) { + return secureRandomSpi.engineGenerateSeed(numBytes); + } else { + synchronized (this) { + return secureRandomSpi.engineGenerateSeed(numBytes); + } + } } /** @@ -917,8 +981,14 @@ * * @since 9 */ - public synchronized void reseed() { - secureRandomSpi.engineReseed(null); + public void reseed() { + if (threadSafe) { + secureRandomSpi.engineReseed(null); + } else { + synchronized (this) { + secureRandomSpi.engineReseed(null); + } + } } /** @@ -937,11 +1007,17 @@ * * @since 9 */ - public synchronized void reseed(SecureRandomParameters params) { + public void reseed(SecureRandomParameters params) { if (params == null) { throw new IllegalArgumentException("params cannot be null"); } - secureRandomSpi.engineReseed(params); + if (threadSafe) { + secureRandomSpi.engineReseed(params); + } else { + synchronized (this) { + secureRandomSpi.engineReseed(params); + } + } } // Declare serialVersionUID to be compatible with JDK1.1
--- a/jdk/src/java.base/share/classes/java/security/SecureRandomSpi.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/security/SecureRandomSpi.java Tue Nov 22 11:46:06 2016 -0800 @@ -58,6 +58,26 @@ * a {@code SecureRandomParameters} argument will never * return an instance of this implementation. The * {@link #engineGetParameters()} method must return {@code null}. + * <p> + * See {@link SecureRandom} for additional details on thread safety. By + * default, a {@code SecureRandomSpi} implementation is considered to be + * not safe for use by multiple concurrent threads and {@code SecureRandom} + * will synchronize access to each of the applicable engine methods + * (see {@link SecureRandom} for the list of methods). However, if a + * {@code SecureRandomSpi} implementation is thread-safe, the <a href= + * "{@docRoot}/../technotes/guides/security/StandardNames.html#Service"> + * service provider attribute</a> "ThreadSafe" should be set to "true" during + * its registration, as follows: + * <blockquote><pre> + * put("SecureRandom.AlgName ThreadSafe", "true");</pre> + * </blockquote> + * or + * <blockquote><pre> + * putService(new Service(this, "SecureRandom", "AlgName", className, + * null, Map.of("ThreadSafe", "true")));</pre> + * </blockquote> + * {@code SecureRandom} will call the applicable engine methods + * without any synchronization. * * @since 1.2 */
--- a/jdk/src/java.base/share/classes/java/time/ZoneId.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/time/ZoneId.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -76,6 +76,7 @@ import java.time.zone.ZoneRules; import java.time.zone.ZoneRulesException; import java.time.zone.ZoneRulesProvider; +import java.util.HashSet; import java.util.Locale; import java.util.Map; import java.util.Objects; @@ -284,7 +285,7 @@ * @return a modifiable copy of the set of zone IDs, not null */ public static Set<String> getAvailableZoneIds() { - return ZoneRulesProvider.getAvailableZoneIds(); + return new HashSet<String>(ZoneRulesProvider.getAvailableZoneIds()); } //-----------------------------------------------------------------------
--- a/jdk/src/java.base/share/classes/java/time/format/DateTimePrintContext.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/time/format/DateTimePrintContext.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -302,14 +302,10 @@ * @throws DateTimeException if the field is not available and the section is not optional */ Long getValue(TemporalField field) { - try { - return temporal.getLong(field); - } catch (DateTimeException ex) { - if (optional > 0) { - return null; - } - throw ex; + if (optional > 0 && !temporal.isSupported(field)) { + return null; } + return temporal.getLong(field); } //-----------------------------------------------------------------------
--- a/jdk/src/java.base/share/classes/java/time/zone/ZoneRulesProvider.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/time/zone/ZoneRulesProvider.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -77,6 +77,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.Collections; /** * Provider of time-zone rules to the system. @@ -137,6 +138,11 @@ */ private static final ConcurrentMap<String, ZoneRulesProvider> ZONES = new ConcurrentHashMap<>(512, 0.75f, 2); + /** + * The zone ID data + */ + private static volatile Set<String> ZONE_IDS; + static { // if the property java.time.zone.DefaultZoneRulesProvider is // set then its value is the class name of the default provider @@ -194,10 +200,10 @@ * <p> * These IDs are the string form of a {@link ZoneId}. * - * @return a modifiable copy of the set of zone IDs, not null + * @return the unmodifiable set of zone IDs, not null */ public static Set<String> getAvailableZoneIds() { - return new HashSet<>(ZONES.keySet()); + return ZONE_IDS; } /** @@ -303,7 +309,7 @@ * @param provider the provider to register, not null * @throws ZoneRulesException if unable to complete the registration */ - private static void registerProvider0(ZoneRulesProvider provider) { + private static synchronized void registerProvider0(ZoneRulesProvider provider) { for (String zoneId : provider.provideZoneIds()) { Objects.requireNonNull(zoneId, "zoneId"); ZoneRulesProvider old = ZONES.putIfAbsent(zoneId, provider); @@ -313,6 +319,8 @@ ", currently loading from provider: " + provider); } } + Set<String> combinedSet = new HashSet<String>(ZONES.keySet()); + ZONE_IDS = Collections.unmodifiableSet(combinedSet); } /**
--- a/jdk/src/java.base/share/classes/java/util/BitSet.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/util/BitSet.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.LongBuffer; +import java.util.function.IntConsumer; import java.util.stream.IntStream; import java.util.stream.StreamSupport; @@ -1217,32 +1218,156 @@ * @since 1.8 */ public IntStream stream() { - class BitSetIterator implements PrimitiveIterator.OfInt { - int next = nextSetBit(0); + class BitSetSpliterator implements Spliterator.OfInt { + private int index; // current bit index for a set bit + private int fence; // -1 until used; then one past last bit index + private int est; // size estimate + private boolean root; // true if root and not split + // root == true then size estimate is accurate + // index == -1 or index >= fence if fully traversed + // Special case when the max bit set is Integer.MAX_VALUE + + BitSetSpliterator(int origin, int fence, int est, boolean root) { + this.index = origin; + this.fence = fence; + this.est = est; + this.root = root; + } + + private int getFence() { + int hi; + if ((hi = fence) < 0) { + // Round up fence to maximum cardinality for allocated words + // This is sufficient and cheap for sequential access + // When splitting this value is lowered + hi = fence = (wordsInUse >= wordIndex(Integer.MAX_VALUE)) + ? Integer.MAX_VALUE + : wordsInUse << ADDRESS_BITS_PER_WORD; + est = cardinality(); + index = nextSetBit(0); + } + return hi; + } @Override - public boolean hasNext() { - return next != -1; + public boolean tryAdvance(IntConsumer action) { + Objects.requireNonNull(action); + + int hi = getFence(); + int i = index; + if (i < 0 || i >= hi) { + // Check if there is a final bit set for Integer.MAX_VALUE + if (i == Integer.MAX_VALUE && hi == Integer.MAX_VALUE) { + index = -1; + action.accept(Integer.MAX_VALUE); + return true; + } + return false; + } + + index = nextSetBit(i + 1, wordIndex(hi - 1)); + action.accept(i); + return true; + } + + @Override + public void forEachRemaining(IntConsumer action) { + Objects.requireNonNull(action); + + int hi = getFence(); + int i = index; + int v = wordIndex(hi - 1); + index = -1; + while (i >= 0 && i < hi) { + action.accept(i); + i = nextSetBit(i + 1, v); + } + // Check if there is a final bit set for Integer.MAX_VALUE + if (i == Integer.MAX_VALUE && hi == Integer.MAX_VALUE) { + action.accept(Integer.MAX_VALUE); + } } @Override - public int nextInt() { - if (next != -1) { - int ret = next; - next = (next == Integer.MAX_VALUE) ? -1 : nextSetBit(next+1); - return ret; - } else { - throw new NoSuchElementException(); + public OfInt trySplit() { + int hi = getFence(); + int lo = index; + if (lo < 0) { + return null; + } + + // Lower the fence to be the upper bound of last bit set + // The index is the first bit set, thus this spliterator + // covers one bit and cannot be split, or two or more + // bits + hi = fence = (hi < Integer.MAX_VALUE || !get(Integer.MAX_VALUE)) + ? previousSetBit(hi - 1) + 1 + : Integer.MAX_VALUE; + + // Find the mid point + int mid = (lo + hi) >>> 1; + if (lo >= mid) { + return null; } + + // Raise the index of this spliterator to be the next set bit + // from the mid point + index = nextSetBit(mid, wordIndex(hi - 1)); + root = false; + + // Don't lower the fence (mid point) of the returned spliterator, + // traversal or further splitting will do that work + return new BitSetSpliterator(lo, mid, est >>>= 1, false); + } + + @Override + public long estimateSize() { + getFence(); // force init + return est; + } + + @Override + public int characteristics() { + // Only sized when root and not split + return (root ? Spliterator.SIZED : 0) | + Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED; + } + + @Override + public Comparator<? super Integer> getComparator() { + return null; } } + return StreamSupport.intStream(new BitSetSpliterator(0, -1, 0, true), false); + } - return StreamSupport.intStream( - () -> Spliterators.spliterator( - new BitSetIterator(), cardinality(), - Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED), - Spliterator.SIZED | Spliterator.SUBSIZED | - Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED, - false); + /** + * Returns the index of the first bit that is set to {@code true} + * that occurs on or after the specified starting index and up to and + * including the specified word index + * If no such bit exists then {@code -1} is returned. + * + * @param fromIndex the index to start checking from (inclusive) + * @param toWordIndex the last word index to check (inclusive) + * @return the index of the next set bit, or {@code -1} if there + * is no such bit + */ + private int nextSetBit(int fromIndex, int toWordIndex) { + int u = wordIndex(fromIndex); + // Check if out of bounds + if (u > toWordIndex) + return -1; + + long word = words[u] & (WORD_MASK << fromIndex); + + while (true) { + if (word != 0) + return (u * BITS_PER_WORD) + Long.numberOfTrailingZeros(word); + // Check if out of bounds + if (++u > toWordIndex) + return -1; + word = words[u]; + } } + }
--- a/jdk/src/java.base/share/classes/java/util/stream/Stream.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/util/stream/Stream.java Tue Nov 22 11:46:06 2016 -0800 @@ -1327,7 +1327,7 @@ * @param s the {@code Supplier} of generated elements * @return a new infinite sequential unordered {@code Stream} */ - public static<T> Stream<T> generate(Supplier<T> s) { + public static<T> Stream<T> generate(Supplier<? extends T> s) { Objects.requireNonNull(s); return StreamSupport.stream( new StreamSpliterators.InfiniteSupplyingSpliterator.OfRef<>(Long.MAX_VALUE, s), false);
--- a/jdk/src/java.base/share/classes/java/util/stream/StreamSpliterators.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/java/util/stream/StreamSpliterators.java Tue Nov 22 11:46:06 2016 -0800 @@ -1346,9 +1346,9 @@ } static final class OfRef<T> extends InfiniteSupplyingSpliterator<T> { - final Supplier<T> s; + final Supplier<? extends T> s; - OfRef(long size, Supplier<T> s) { + OfRef(long size, Supplier<? extends T> s) { super(size); this.s = s; }
--- a/jdk/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java Tue Nov 22 11:46:06 2016 -0800 @@ -72,13 +72,13 @@ // If neither is specified then default to -cp <working directory> // If -cp is not specified and -m is specified, the value of // java.class.path is an empty string, then no class path. - URLClassPath ucp = null; + URLClassPath ucp = new URLClassPath(new URL[0]); String mainMid = System.getProperty("jdk.module.main"); String cp = System.getProperty("java.class.path"); if (cp == null) cp = ""; if (mainMid == null || cp.length() > 0) - ucp = toURLClassPath(cp); + addClassPathToUCP(cp, ucp); // create the class loaders BOOT_LOADER = new BootClassLoader(bcp);
--- a/jdk/src/java.base/share/classes/sun/launcher/LauncherHelper.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/sun/launcher/LauncherHelper.java Tue Nov 22 11:46:06 2016 -0800 @@ -462,6 +462,8 @@ * This method: * 1. Loads the main class from the module or class path * 2. Checks the public static void main method. + * 3. If the main class extends FX Application then call on FXHelper to + * perform the launch. * * @param printToStderr if set, all output will be routed to stderr * @param mode LaunchMode as determined by the arguments passed on the @@ -479,11 +481,23 @@ Class<?> mainClass = (mode == LM_MODULE) ? loadModuleMainClass(what) : loadMainClass(mode, what); - validateMainClass(mainClass); + // record the real main class for UI purposes + // neither method above can return null, they will abort() + appClass = mainClass; - // record main class if not already set - if (appClass == null) - appClass = mainClass; + /* + * Check if FXHelper can launch it using the FX launcher. In an FX app, + * the main class may or may not have a main method, so do this before + * validating the main class. + */ + if (JAVAFX_FXHELPER_CLASS_NAME_SUFFIX.equals(mainClass.getName()) || + doesExtendFXApplication(mainClass)) { + // Will abort() if there are problems with FX runtime + FXHelper.setFXLaunchParameters(what, mode); + mainClass = FXHelper.class; + } + + validateMainClass(mainClass); return mainClass; } @@ -530,7 +544,6 @@ String cn = Normalizer.normalize(mainClass, Normalizer.Form.NFC); c = Class.forName(m, cn); - } if (c == null) { abort(null, "java.launcher.module.error2", mainClass, mainModule); @@ -542,8 +555,6 @@ /** * Loads the main class from the class path (LM_CLASS or LM_JAR). - * If the main class extends FX Application then call on FXHelper to - * determine the main class to launch. */ private static Class<?> loadMainClass(int mode, String what) { // get the class name @@ -570,7 +581,7 @@ if (System.getProperty("os.name", "").contains("OS X") && Normalizer.isNormalized(cn, Normalizer.Form.NFD)) { try { - // On Mac OS X since all names with diacretic symbols are + // On Mac OS X since all names with diacritical marks are // given as decomposed it is possible that main class name // comes incorrectly from the command line and we have // to re-compose it @@ -583,21 +594,6 @@ abort(cnfe, "java.launcher.cls.error1", cn); } } - - // record the main class - appClass = mainClass; - - /* - * Check if FXHelper can launch it using the FX launcher. In an FX app, - * the main class may or may not have a main method, so do this before - * validating the main class. - */ - if (JAVAFX_FXHELPER_CLASS_NAME_SUFFIX.equals(mainClass.getName()) || - doesExtendFXApplication(mainClass)) { - // Will abort() if there are problems with FX runtime - FXHelper.setFXLaunchParameters(what, mode); - return FXHelper.class; - } return mainClass; } @@ -773,9 +769,15 @@ * java -cp somedir FXClass N/A LM_CLASS "LM_CLASS" * java -jar fxapp.jar Present LM_JAR "LM_JAR" * java -jar fxapp.jar Not Present LM_JAR "LM_JAR" + * java -m module/class [1] N/A LM_MODULE "LM_MODULE" + * java -m module N/A LM_MODULE "LM_MODULE" + * + * [1] - JavaFX-Application-Class is ignored when modular args are used, even + * if present in a modular jar */ private static final String JAVAFX_LAUNCH_MODE_CLASS = "LM_CLASS"; private static final String JAVAFX_LAUNCH_MODE_JAR = "LM_JAR"; + private static final String JAVAFX_LAUNCH_MODE_MODULE = "LM_MODULE"; /* * FX application launcher and launch method, so we can launch @@ -835,6 +837,9 @@ case LM_JAR: fxLaunchMode = JAVAFX_LAUNCH_MODE_JAR; break; + case LM_MODULE: + fxLaunchMode = JAVAFX_LAUNCH_MODE_MODULE; + break; default: // should not have gotten this far... throw new InternalError(mode + ": Unknown launch mode");
--- a/jdk/src/java.base/share/classes/sun/security/provider/SunEntries.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/sun/security/provider/SunEntries.java Tue Nov 22 11:46:06 2016 -0800 @@ -96,25 +96,32 @@ if (nativeAvailable && useNativePRNG) { map.put("SecureRandom.NativePRNG", "sun.security.provider.NativePRNG"); + map.put("SecureRandom.NativePRNG ThreadSafe", "true"); } map.put("SecureRandom.DRBG", "sun.security.provider.DRBG"); + map.put("SecureRandom.DRBG ThreadSafe", "true"); map.put("SecureRandom.SHA1PRNG", "sun.security.provider.SecureRandom"); + + map.put("SecureRandom.SHA1PRNG ThreadSafe", "true"); if (nativeAvailable && !useNativePRNG) { map.put("SecureRandom.NativePRNG", "sun.security.provider.NativePRNG"); + map.put("SecureRandom.NativePRNG ThreadSafe", "true"); } if (NativePRNG.Blocking.isAvailable()) { map.put("SecureRandom.NativePRNGBlocking", "sun.security.provider.NativePRNG$Blocking"); + map.put("SecureRandom.NativePRNGBlocking ThreadSafe", "true"); } if (NativePRNG.NonBlocking.isAvailable()) { map.put("SecureRandom.NativePRNGNonBlocking", "sun.security.provider.NativePRNG$NonBlocking"); + map.put("SecureRandom.NativePRNGNonBlocking ThreadSafe", "true"); } /* @@ -329,6 +336,7 @@ map.put("AlgorithmParameters.DSA ImplementedIn", "Software"); map.put("KeyFactory.DSA ImplementedIn", "Software"); map.put("SecureRandom.SHA1PRNG ImplementedIn", "Software"); + map.put("SecureRandom.DRBG ImplementedIn", "Software"); map.put("CertificateFactory.X.509 ImplementedIn", "Software"); map.put("KeyStore.JKS ImplementedIn", "Software"); map.put("CertPathValidator.PKIX ImplementedIn", "Software");
--- a/jdk/src/java.base/share/classes/sun/security/provider/certpath/RevocationChecker.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/sun/security/provider/certpath/RevocationChecker.java Tue Nov 22 11:46:06 2016 -0800 @@ -740,7 +740,7 @@ } response = OCSP.check(Collections.singletonList(certId), - responderURI, issuerInfo, responderCert, params.date(), + responderURI, issuerInfo, responderCert, null, ocspExtensions); } } catch (IOException e) {
--- a/jdk/src/java.base/share/classes/sun/security/util/AnchorCertificates.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/classes/sun/security/util/AnchorCertificates.java Tue Nov 22 11:46:06 2016 -0800 @@ -58,7 +58,7 @@ try { cacerts = KeyStore.getInstance("JKS"); try (FileInputStream fis = new FileInputStream(f)) { - cacerts.load(fis, "changeit".toCharArray()); + cacerts.load(fis, null); certs = new HashSet<>(); Enumeration<String> list = cacerts.aliases(); String alias;
--- a/jdk/src/java.base/share/lib/security/default.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.base/share/lib/security/default.policy Tue Nov 22 11:46:06 2016 -0800 @@ -155,7 +155,6 @@ grant codeBase "jrt:/jdk.localedata" { permission java.lang.RuntimePermission "accessClassInPackage.sun.text.*"; permission java.lang.RuntimePermission "accessClassInPackage.sun.util.*"; - permission java.util.PropertyPermission "*", "read"; }; grant codeBase "jrt:/jdk.naming.dns" {
--- a/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaUtils.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaUtils.java Tue Nov 22 11:46:06 2016 -0800 @@ -176,10 +176,11 @@ } @Override + @SuppressWarnings("deprecation") T getInstance() { try { ReflectUtil.checkPackageAccess(clazz); - return clazz.getDeclaredConstructor().newInstance(); + return clazz.newInstance(); } catch (ReflectiveOperationException ignored) { } return null;
--- a/jdk/src/java.desktop/share/classes/com/sun/beans/decoder/DocumentHandler.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.desktop/share/classes/com/sun/beans/decoder/DocumentHandler.java Tue Nov 22 11:46:06 2016 -0800 @@ -277,11 +277,12 @@ * @param attributes the attributes attached to the element */ @Override + @SuppressWarnings("deprecation") public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { ElementHandler parent = this.handler; try { this.handler = - getElementHandler(qName).getDeclaredConstructor().newInstance(); + getElementHandler(qName).newInstance(); this.handler.setOwner(this); this.handler.setParent(parent); }
--- a/jdk/src/java.desktop/share/classes/com/sun/beans/finder/InstanceFinder.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.desktop/share/classes/com/sun/beans/finder/InstanceFinder.java Tue Nov 22 11:46:06 2016 -0800 @@ -86,6 +86,7 @@ return null; } + @SuppressWarnings("deprecation") protected T instantiate(Class<?> type, String name) { if (type != null) { try { @@ -94,7 +95,7 @@ } if (this.type.isAssignableFrom(type)) { @SuppressWarnings("unchecked") - T tmp = (T) type.getDeclaredConstructor().newInstance(); + T tmp = (T) type.newInstance(); return tmp; } }
--- a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java Tue Nov 22 11:46:06 2016 -0800 @@ -1125,13 +1125,14 @@ this.methodName = methodName; } + @SuppressWarnings("deprecation") public Object createValue(UIDefaults table) { try { Class<?> c = Class.forName(className, true,Thread.currentThread(). getContextClassLoader()); if (methodName == null) { - return c.getDeclaredConstructor().newInstance(); + return c.newInstance(); } Method m = c.getMethod(methodName, (Class<?>[])null);
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/JARSoundbankReader.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/JARSoundbankReader.java Tue Nov 22 11:46:06 2016 -0800 @@ -70,6 +70,7 @@ } @Override + @SuppressWarnings("deprecation") public Soundbank getSoundbank(URL url) throws InvalidMidiDataException, IOException { if (!isZIP(url)) @@ -90,7 +91,7 @@ Class<?> c = Class.forName(line.trim(), false, ucl); if (Soundbank.class.isAssignableFrom(c)) { ReflectUtil.checkPackageAccess(c); - Object o = c.getDeclaredConstructor().newInstance(); + Object o = c.newInstance(); soundbanks.add((Soundbank) o); } } catch (ReflectiveOperationException ignored) {
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/ModelAbstractOscillator.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/ModelAbstractOscillator.java Tue Nov 22 11:46:06 2016 -0800 @@ -134,10 +134,11 @@ } @Override + @SuppressWarnings("deprecation") public ModelOscillatorStream open(float samplerate) { ModelAbstractOscillator oscs; try { - oscs = this.getClass().getDeclaredConstructor().newInstance(); + oscs = this.getClass().newInstance(); } catch (ReflectiveOperationException e) { throw new IllegalArgumentException(e); }
--- a/jdk/src/java.desktop/share/classes/java/beans/Introspector.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.desktop/share/classes/java/beans/Introspector.java Tue Nov 22 11:46:06 2016 -0800 @@ -1279,6 +1279,7 @@ * First try the classloader of "sibling", then try the system * classloader then the class loader of the current Thread. */ + @SuppressWarnings("deprecation") static Object instantiate(Class<?> sibling, String className) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, @@ -1286,7 +1287,7 @@ // First check with sibling's classloader (if any). ClassLoader cl = sibling.getClassLoader(); Class<?> cls = ClassFinder.findClass(className, cl); - return cls.getDeclaredConstructor().newInstance(); + return cls.newInstance(); } } // end class Introspector
--- a/jdk/src/java.desktop/share/classes/java/beans/MetaData.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.desktop/share/classes/java/beans/MetaData.java Tue Nov 22 11:46:06 2016 -0800 @@ -1219,7 +1219,7 @@ internalPersistenceDelegates.put("java.sql.Time", new java_util_Date_PersistenceDelegate()); } - @SuppressWarnings("rawtypes") + @SuppressWarnings({"rawtypes", "deprecation"}) public static synchronized PersistenceDelegate getPersistenceDelegate(Class type) { if (type == null) { return nullPersistenceDelegate; @@ -1263,7 +1263,7 @@ String name = type.getName(); Class<?> c = Class.forName("java.beans.MetaData$" + name.replace('.', '_') + "_PersistenceDelegate"); - pd = (PersistenceDelegate)c.getDeclaredConstructor().newInstance(); + pd = (PersistenceDelegate)c.newInstance(); internalPersistenceDelegates.put(typeName, pd); } catch (ClassNotFoundException e) {
--- a/jdk/src/java.desktop/share/classes/java/beans/PropertyDescriptor.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.desktop/share/classes/java/beans/PropertyDescriptor.java Tue Nov 22 11:46:06 2016 -0800 @@ -461,6 +461,7 @@ * not been defined or cannot be created * @since 1.5 */ + @SuppressWarnings("deprecation") public PropertyEditor createPropertyEditor(Object bean) { Object editor = null; @@ -470,14 +471,14 @@ Constructor<?> ctor = null; if (bean != null) { try { - ctor = cls.getDeclaredConstructor(new Class<?>[] { Object.class }); + ctor = cls.getConstructor(new Class<?>[] { Object.class }); } catch (Exception ex) { // Fall through } } try { if (ctor == null) { - editor = cls.getDeclaredConstructor().newInstance(); + editor = cls.newInstance(); } else { editor = ctor.newInstance(new Object[] { bean }); }
--- a/jdk/src/java.desktop/share/classes/javax/swing/JEditorPane.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.desktop/share/classes/javax/swing/JEditorPane.java Tue Nov 22 11:46:06 2016 -0800 @@ -1180,6 +1180,7 @@ * @return the editor kit, or <code>null</code> if there is nothing * registered for the given type */ + @SuppressWarnings("deprecation") public static EditorKit createEditorKitForContentType(String type) { Hashtable<String, EditorKit> kitRegistry = getKitRegisty(); EditorKit k = kitRegistry.get(type); @@ -1197,7 +1198,7 @@ // registerEditorKitForContentType(type, class, null). c = SwingUtilities.loadSystemClass(classname); } - k = (EditorKit) c.getDeclaredConstructor().newInstance(); + k = (EditorKit) c.newInstance(); kitRegistry.put(type, k); } catch (Throwable e) { k = null;
--- a/jdk/src/java.desktop/share/classes/javax/swing/UIManager.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.desktop/share/classes/javax/swing/UIManager.java Tue Nov 22 11:46:06 2016 -0800 @@ -513,6 +513,7 @@ * * @since 9 */ + @SuppressWarnings("deprecation") public static LookAndFeel createLookAndFeel(String name) throws UnsupportedLookAndFeelException { Objects.requireNonNull(name); @@ -527,7 +528,7 @@ Class<?> cls = Class.forName(UIManager.class.getModule(), info.getClassName()); LookAndFeel laf = - (LookAndFeel) cls.getDeclaredConstructor().newInstance(); + (LookAndFeel) cls.newInstance(); if (!laf.isSupportedLookAndFeel()) { break; } @@ -615,6 +616,7 @@ * @throws ClassCastException if {@code className} does not identify * a class that extends {@code LookAndFeel} */ + @SuppressWarnings("deprecation") public static void setLookAndFeel(String className) throws ClassNotFoundException, InstantiationException, @@ -629,7 +631,7 @@ Class<?> lnfClass = SwingUtilities.loadSystemClass(className); try { LookAndFeel laf = - (LookAndFeel)lnfClass.getDeclaredConstructor().newInstance(); + (LookAndFeel)lnfClass.newInstance(); setLookAndFeel(laf); } catch (ReflectiveOperationException | IllegalArgumentException e) { InstantiationException ex = @@ -1097,6 +1099,7 @@ /** * Finds the Multiplexing <code>LookAndFeel</code>. */ + @SuppressWarnings("deprecation") private static LookAndFeel getMultiLookAndFeel() { LookAndFeel multiLookAndFeel = getLAFState().multiLookAndFeel; if (multiLookAndFeel == null) { @@ -1105,7 +1108,7 @@ try { Class<?> lnfClass = SwingUtilities.loadSystemClass(className); multiLookAndFeel = - (LookAndFeel)lnfClass.getDeclaredConstructor().newInstance(); + (LookAndFeel)lnfClass.newInstance(); } catch (Exception exc) { System.err.println("UIManager: failed loading " + className); } @@ -1420,6 +1423,7 @@ } + @SuppressWarnings("deprecation") private static void initializeAuxiliaryLAFs(Properties swingProps) { String auxLookAndFeelNames = swingProps.getProperty(auxiliaryLAFsKey); @@ -1440,7 +1444,7 @@ try { Class<?> lnfClass = SwingUtilities.loadSystemClass(className); LookAndFeel newLAF = - (LookAndFeel)lnfClass.getDeclaredConstructor().newInstance(); + (LookAndFeel)lnfClass.newInstance(); newLAF.initialize(); auxLookAndFeels.addElement(newLAF); }
--- a/jdk/src/java.desktop/share/classes/javax/swing/text/html/ObjectView.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.desktop/share/classes/javax/swing/text/html/ObjectView.java Tue Nov 22 11:46:06 2016 -0800 @@ -46,7 +46,7 @@ * <p> * If the class can successfully be loaded, an attempt will * be made to create an instance of it by calling - * <code>Class.getDeclaredConstructor().newInstance</code>. An attempt will be made + * <code>Class.newInstance</code>. An attempt will be made * to narrow the instance to type <code>java.awt.Component</code> * to display the object. * <p> @@ -85,6 +85,7 @@ * as a specification of the classname, which * we try to load. */ + @SuppressWarnings("deprecation") protected Component createComponent() { AttributeSet attr = getElement().getAttributes(); String classname = (String) attr.getAttribute(HTML.Attribute.CLASSID); @@ -92,7 +93,7 @@ ReflectUtil.checkPackageAccess(classname); Class<?> c = Class.forName(classname, true,Thread.currentThread(). getContextClassLoader()); - Object o = c.getDeclaredConstructor().newInstance(); + Object o = c.newInstance(); if (o instanceof Component) { Component comp = (Component) o; setParameters(comp, attr);
--- a/jdk/src/java.management/share/classes/java/lang/management/ThreadInfo.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.management/share/classes/java/lang/management/ThreadInfo.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -554,7 +554,7 @@ * @return an array of {@code StackTraceElement} objects of the thread. */ public StackTraceElement[] getStackTrace() { - return stackTrace; + return stackTrace.clone(); } /** @@ -868,7 +868,7 @@ * @since 1.6 */ public MonitorInfo[] getLockedMonitors() { - return lockedMonitors; + return lockedMonitors.clone(); } /** @@ -885,7 +885,7 @@ * @since 1.6 */ public LockInfo[] getLockedSynchronizers() { - return lockedSynchronizers; + return lockedSynchronizers.clone(); } private static final StackTraceElement[] NO_STACK_TRACE =
--- a/jdk/src/java.management/share/classes/javax/management/MXBean.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.management/share/classes/javax/management/MXBean.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -916,14 +916,14 @@ <li><p>Otherwise, <em>J</em> is not reconstructible.</p></li> </ol> - <p>When only {@code @java.beans.ConstructorProperties} is present then - rule 2 is not applicable to subset Profiles of Java SE that do not include - the {@code java.beans} package. When targeting a runtime that does - not include the {@code java.beans} package, and where there is a mismatch - between the compile-time and runtime environment whereby <em>J</em> is - compiled with a public constructor and the {@code ConstructorProperties} - annotation, then <em>J</em> is not reconstructible unless another rule - applies.</p> + <p>Rule 2 is not applicable when {@code java.beans.ConstructorProperties} + is not visible (e.g. when the java.desktop module is not readable or when + the runtime image does not contain the java.desktop module). When + targeting a runtime that does not include the {@code java.beans} package, + and where there is a mismatch between the compile-time and runtime + environment whereby <em>J</em> is compiled with a public constructor + and the {@code ConstructorProperties} annotation, then <em>J</em> is + not reconstructible unless another rule applies.</p> <p>Here are examples showing different ways to code a type {@code NamedNumber} that consists of an {@code int} and a {@code
--- a/jdk/src/java.management/share/classes/sun/management/VMManagementImpl.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.management/share/classes/sun/management/VMManagementImpl.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -102,7 +102,13 @@ } public boolean isGcNotificationSupported() { - return gcNotificationSupport; + boolean isSupported = true; + try { + Class.forName("com.sun.management.GarbageCollectorMXBean"); + } catch (ClassNotFoundException x) { + isSupported = false; + } + return isSupported; } public boolean isRemoteDiagnosticCommandsSupported() {
--- a/jdk/src/java.management/share/native/libmanagement/VMManagementImpl.c Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/java.management/share/native/libmanagement/VMManagementImpl.c Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -96,13 +96,6 @@ value = mos.isRemoteDiagnosticCommandsSupported; setStaticBooleanField(env, cls, "remoteDiagnosticCommandsSupport", value); - - if ((jmm_version > JMM_VERSION_1_2) || - (jmm_version == JMM_VERSION_1_2 && ((jmm_version&0xFF) >= 1))) { - setStaticBooleanField(env, cls, "gcNotificationSupport", JNI_TRUE); - } else { - setStaticBooleanField(env, cls, "gcNotificationSupport", JNI_FALSE); - } } JNIEXPORT jobjectArray JNICALL
--- a/jdk/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/SunMSCAPI.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/SunMSCAPI.java Tue Nov 22 11:46:06 2016 -0800 @@ -33,6 +33,8 @@ import java.security.ProviderException; import java.util.HashMap; import java.util.Arrays; +import java.util.Map; + import static sun.security.util.SecurityConstants.PROVIDER_VER; /** @@ -133,8 +135,11 @@ /* * Secure random */ + HashMap<String, String> srattrs = new HashMap<>(1); + srattrs.put("ThreadSafe", "true"); putService(new ProviderService(p, "SecureRandom", - "Windows-PRNG", "sun.security.mscapi.PRNG")); + "Windows-PRNG", "sun.security.mscapi.PRNG", + null, srattrs)); /* * Key store
--- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/SunPKCS11.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/SunPKCS11.java Tue Nov 22 11:46:06 2016 -0800 @@ -987,7 +987,8 @@ P11Service(Token token, String type, String algorithm, String className, String[] al, long mechanism) { - super(token.provider, type, algorithm, className, toList(al), null); + super(token.provider, type, algorithm, className, toList(al), + type.equals(SR) ? Map.of("ThreadSafe", "true") : null); this.token = token; this.mechanism = mechanism & 0xFFFFFFFFL; }
--- a/jdk/src/jdk.jdi/share/native/libdt_shmem/SharedMemoryConnection.c Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/jdk.jdi/share/native/libdt_shmem/SharedMemoryConnection.c Tue Nov 22 11:46:06 2016 -0800 @@ -174,9 +174,20 @@ * Get the packet header */ (*env)->GetByteArrayRegion(env, b, 0, sizeof(pktHeader), pktHeader); + if ((*env)->ExceptionOccurred(env)) { + /* b shorter than sizeof(pktHeader) */ + return; + } total_length = (int)pktHeader[3] | ((int)pktHeader[2] << 8) | ((int)pktHeader[1] << 16) | ((int)pktHeader[0] << 24); + + if (total_length < sizeof(pktHeader)) { + throwException(env, "java/lang/IllegalArgumentException", + "JDWP header is incorrect"); + return; + } + /* * The id field is in big endian (also errorCode field in the case * of reply packets). @@ -195,9 +206,9 @@ } /* - * The length of the JDWP packet is 11 + data + * The length of the JDWP packet is sizeof(pktHeader) + data */ - data_length = total_length - 11; + data_length = total_length - sizeof(pktHeader); if (data_length == 0) { data = NULL; @@ -209,7 +220,7 @@ return; } - (*env)->GetByteArrayRegion(env, b, 11, /*sizeof(CmdPacket)+4*/ data_length, data); + (*env)->GetByteArrayRegion(env, b, sizeof(pktHeader), /*sizeof(CmdPacket)+4*/ data_length, data); if ((*env)->ExceptionOccurred(env)) { free(data); return;
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/JImageTask.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/JImageTask.java Tue Nov 22 11:46:06 2016 -0800 @@ -32,6 +32,7 @@ import java.nio.file.Files; import java.nio.file.PathMatcher; import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.MissingResourceException; @@ -190,19 +191,12 @@ if (options.help) { if (unhandled.isEmpty()) { log.println(TASK_HELPER.getMessage("main.usage", PROGNAME)); - - for (Option<?> o : RECOGNIZED_OPTIONS) { - String name = o.aliases()[0]; - - if (name.startsWith("--")) { - name = name.substring(2); - } else if (name.startsWith("-")) { - name = name.substring(1); - } - - log.println(TASK_HELPER.getMessage("main.opt." + name)); - } - + Arrays.asList(RECOGNIZED_OPTIONS).stream() + .filter(option -> !option.isHidden()) + .sorted() + .forEach(option -> { + log.println(TASK_HELPER.getMessage(option.resourceName())); + }); log.println(TASK_HELPER.getMessage("main.opt.footer")); } else { try {
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/resources/jimage.properties Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jimage/resources/jimage.properties Tue Nov 22 11:46:06 2016 -0800 @@ -60,36 +60,36 @@ warn.prefix=Warning: main.opt.dir=\ -\ --dir Target directory for extract directive +\ --dir Target directory for extract directive main.opt.include=\ -\ --include <pattern-list> Pattern list for filtering entries. - -main.opt.footer=\ -\n\ -\For options requiring a <pattern-list>, the value will be a comma\ -\ separated list of elements each using one the following forms:\n\ -\ <glob-pattern>\n\ -\ glob:<glob-pattern>\n\ -\ regex:<regex-pattern>\n\ -\ @<filename> where filename is the name of a file containing patterns to be\ -\ used, one pattern per line\n\ - +\ --include <pattern-list> Pattern list for filtering entries. main.opt.full-version=\ -\ --full-version Print full version information +\ --full-version Print full version information main.opt.help=\ \ -h, --help Print usage message main.opt.verbose=\ -\ --verbose Listing prints entry size and offset attributes +\ --verbose Listing prints entry size and offset\n\ +\ attributes main.opt.version=\ -\ --version Print version information +\ --version Print version information main.command.files=\ -\ @<filename> Read options from file +\ @<filename> Read options from file + +main.opt.footer=\ +\n\ +\For options requiring a <pattern-list>, the value will be a comma separated\n\ +\list of elements each using one the following forms:\n\ +\ <glob-pattern>\n\ +\ glob:<glob-pattern>\n\ +\ regex:<regex-pattern> + + err.not.a.task=task must be one of <extract | info | list | verify>: {0} err.missing.arg=no value given for {0}
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/Jlink.java Tue Nov 22 11:46:06 2016 -0800 @@ -27,6 +27,7 @@ import java.lang.reflect.Layer; import java.nio.ByteOrder; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -278,6 +279,13 @@ */ public void build(JlinkConfiguration config, PluginsConfiguration pluginsConfig) { Objects.requireNonNull(config); + if (pluginsConfig == null) { + pluginsConfig = new PluginsConfiguration(); + } + + // add all auto-enabled plugins from boot layer + pluginsConfig = addAutoEnabledPlugins(pluginsConfig); + try { JlinkTask.createImage(config, pluginsConfig); } catch (Exception ex) { @@ -285,6 +293,19 @@ } } + private PluginsConfiguration addAutoEnabledPlugins(PluginsConfiguration pluginsConfig) { + List<Plugin> plugins = new ArrayList<>(pluginsConfig.getPlugins()); + List<Plugin> bootPlugins = PluginRepository.getPlugins(Layer.boot()); + for (Plugin bp : bootPlugins) { + if (Utils.isAutoEnabled(bp)) { + bp.configure(Collections.emptyMap()); + plugins.add(bp); + } + } + return new PluginsConfiguration(plugins, pluginsConfig.getImageBuilder(), + pluginsConfig.getLastSorterPluginName()); + } + /** * Post process the image with a plugin configuration. *
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java Tue Nov 22 11:46:06 2016 -0800 @@ -134,7 +134,7 @@ }, true, "--full-version"), new Option<JlinkTask>(false, (task, opt, arg) -> { task.options.ignoreSigning = true; - }, true, "--ignore-signing-information"),}; + }, "--ignore-signing-information"),}; private static final String PROGNAME = "jlink"; private final OptionsValues options = new OptionsValues();
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java Tue Nov 22 11:46:06 2016 -0800 @@ -46,8 +46,8 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Set; +import java.util.stream.Stream; -import jdk.tools.jlink.internal.plugins.ExcludeFilesPlugin; import jdk.tools.jlink.internal.plugins.ExcludeJmodSectionPlugin; import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.Plugin.Category; @@ -90,8 +90,7 @@ public boolean showUsage; } - public static class Option<T> { - + public static class Option<T> implements Comparable<T> { public interface Processing<T> { void process(T task, String opt, String arg) throws BadArgs; @@ -100,17 +99,34 @@ final boolean hasArg; final Processing<T> processing; final boolean hidden; - final String[] aliases; + final String name; + final String shortname; - public Option(boolean hasArg, Processing<T> processing, boolean hidden, String... aliases) { + public Option(boolean hasArg, Processing<T> processing, boolean hidden, String name, String shortname) { + if (!name.startsWith("--")) { + throw new RuntimeException("option name missing --, " + name); + } + if (!shortname.isEmpty() && !shortname.startsWith("-")) { + throw new RuntimeException("short name missing -, " + shortname); + } + this.hasArg = hasArg; this.processing = processing; - this.aliases = aliases; this.hidden = hidden; + this.name = name; + this.shortname = shortname; } - public Option(boolean hasArg, Processing<T> processing, String... aliases) { - this(hasArg, processing, false, aliases); + public Option(boolean hasArg, Processing<T> processing, String name, String shortname) { + this(hasArg, processing, false, name, shortname); + } + + public Option(boolean hasArg, Processing<T> processing, boolean hidden, String name) { + this(hasArg, processing, hidden, name, ""); + } + + public Option(boolean hasArg, Processing<T> processing, String name) { + this(hasArg, processing, false, name, ""); } public boolean isHidden() { @@ -118,16 +134,10 @@ } public boolean matches(String opt) { - for (String a : aliases) { - if (a.equals(opt)) { - return true; - } else if (opt.startsWith("--") - && (hasArg && opt.startsWith(a + "="))) { - return true; - } - } - return false; - } + return opt.equals(name) || + opt.equals(shortname) || + hasArg && opt.startsWith("--") && opt.startsWith(name + "="); + } public boolean ignoreRest() { return false; @@ -137,28 +147,54 @@ processing.process(task, opt, arg); } - public String[] aliases() { - return aliases; + public String getName() { + return name; + } + + public String resourceName() { + return resourcePrefix() + name.substring(2); + } + + public String getShortname() { + return shortname; + } + + public String resourcePrefix() { + return "main.opt."; + } + + @Override + public int compareTo(Object object) { + if (!(object instanceof Option<?>)) { + throw new RuntimeException("comparing non-Option"); + } + + Option<?> option = (Option<?>)object; + + return name.compareTo(option.name); + } + + } + + private static class PluginOption extends Option<PluginsHelper> { + public PluginOption(boolean hasArg, + Processing<PluginsHelper> processing, boolean hidden, String name, String shortname) { + super(hasArg, processing, hidden, name, shortname); + } + + public PluginOption(boolean hasArg, + Processing<PluginsHelper> processing, boolean hidden, String name) { + super(hasArg, processing, hidden, name, ""); + } + + public String resourcePrefix() { + return "plugin.opt."; } } - private static class PlugOption extends Option<PluginsOptions> { - - public PlugOption(boolean hasArg, - Processing<PluginsOptions> processing, boolean hidden, String... aliases) { - super(hasArg, processing, hidden, aliases); - } - - public PlugOption(boolean hasArg, - Processing<PluginsOptions> processing, String... aliases) { - super(hasArg, processing, aliases); - } - } - - private final class PluginsOptions { + private final class PluginsHelper { private static final String PLUGINS_PATH = "--plugin-module-path"; - private static final String POST_PROCESS = "--post-process-path"; private Layer pluginsLayer = Layer.boot(); private final List<Plugin> plugins; @@ -170,10 +206,10 @@ // Each such occurrence results in a Map of arguments. So, there could be multiple // args maps per plugin instance. private final Map<Plugin, List<Map<String, String>>> pluginToMaps = new HashMap<>(); - private final List<PlugOption> pluginsOptions = new ArrayList<>(); - private final List<PlugOption> mainOptions = new ArrayList<>(); + private final List<PluginOption> pluginsOptions = new ArrayList<>(); + private final List<PluginOption> mainOptions = new ArrayList<>(); - private PluginsOptions(String pp) throws BadArgs { + private PluginsHelper(String pp) throws BadArgs { if (pp != null) { String[] dirs = pp.split(File.pathSeparator); @@ -193,13 +229,13 @@ addOrderedPluginOptions(plugin, optionsSeen); } } - mainOptions.add(new PlugOption(false, + mainOptions.add(new PluginOption(false, (task, opt, arg) -> { // This option is handled prior // to have the options parsed. }, - "--plugin-module-path")); - mainOptions.add(new PlugOption(true, (task, opt, arg) -> { + false, "--plugin-module-path")); + mainOptions.add(new PluginOption(true, (task, opt, arg) -> { for (Plugin plugin : plugins) { if (plugin.getName().equals(arg)) { pluginToMaps.remove(plugin); @@ -208,24 +244,24 @@ } throw newBadArgs("err.no.such.plugin", arg); }, - "--disable-plugin")); - mainOptions.add(new PlugOption(true, (task, opt, arg) -> { + false, "--disable-plugin")); + mainOptions.add(new PluginOption(true, (task, opt, arg) -> { Path path = Paths.get(arg); if (!Files.exists(path) || !Files.isDirectory(path)) { throw newBadArgs("err.image.must.exist", path); } existingImage = path.toAbsolutePath(); - }, true, POST_PROCESS)); - mainOptions.add(new PlugOption(true, + }, true, "--post-process-path")); + mainOptions.add(new PluginOption(true, (task, opt, arg) -> { lastSorter = arg; }, true, "--resources-last-sorter")); - mainOptions.add(new PlugOption(false, + mainOptions.add(new PluginOption(false, (task, opt, arg) -> { listPlugins = true; }, - "--list-plugins")); + false, "--list-plugins")); } private List<Map<String, String>> argListFor(Plugin plugin) { @@ -261,8 +297,8 @@ } optionsSeen.add(option); - PlugOption plugOption - = new PlugOption(plugin.hasArguments(), + PluginOption plugOption + = new PluginOption(plugin.hasArguments(), (task, opt, arg) -> { if (!Utils.isFunctional(plugin)) { throw newBadArgs("err.provider.not.functional", @@ -312,7 +348,7 @@ } } }, - "--" + option); + false, "--" + option); pluginsOptions.add(plugOption); if (Utils.isFunctional(plugin)) { @@ -322,44 +358,44 @@ if (plugin instanceof DefaultCompressPlugin) { plugOption - = new PlugOption(false, + = new PluginOption(false, (task, opt, arg) -> { Map<String, String> m = addArgumentMap(plugin); m.put(DefaultCompressPlugin.NAME, DefaultCompressPlugin.LEVEL_2); - }, "-c"); + }, false, "--compress", "-c"); mainOptions.add(plugOption); } else if (plugin instanceof StripDebugPlugin) { plugOption - = new PlugOption(false, + = new PluginOption(false, (task, opt, arg) -> { addArgumentMap(plugin); - }, "-G"); + }, false, "--strip-debug", "-G"); mainOptions.add(plugOption); } else if (plugin instanceof ExcludeJmodSectionPlugin) { - plugOption = new PlugOption(false, (task, opt, arg) -> { + plugOption = new PluginOption(false, (task, opt, arg) -> { Map<String, String> m = addArgumentMap(plugin); m.put(ExcludeJmodSectionPlugin.NAME, ExcludeJmodSectionPlugin.MAN_PAGES); - }, "--no-man-pages"); + }, false, "--no-man-pages"); mainOptions.add(plugOption); - plugOption = new PlugOption(false, (task, opt, arg) -> { + plugOption = new PluginOption(false, (task, opt, arg) -> { Map<String, String> m = addArgumentMap(plugin); m.put(ExcludeJmodSectionPlugin.NAME, ExcludeJmodSectionPlugin.INCLUDE_HEADER_FILES); - }, "--no-header-files"); + }, false, "--no-header-files"); mainOptions.add(plugOption); } } } - private PlugOption getOption(String name) throws BadArgs { - for (PlugOption o : pluginsOptions) { + private PluginOption getOption(String name) throws BadArgs { + for (PluginOption o : pluginsOptions) { if (o.matches(name)) { return o; } } - for (PlugOption o : mainOptions) { + for (PluginOption o : mainOptions) { if (o.matches(name)) { return o; } @@ -461,7 +497,7 @@ private String getPluginsPath(String[] args) throws BadArgs { String pp = null; for (int i = 0; i < args.length; i++) { - if (args[i].equals(PluginsOptions.PLUGINS_PATH)) { + if (args[i].equals(PluginsHelper.PLUGINS_PATH)) { if (i == args.length - 1) { throw new BadArgs("err.no.plugins.path").showUsage(true); } else { @@ -498,13 +534,13 @@ // Must extract it prior to do any option analysis. // Required to interpret custom plugin options. // Unit tests can call Task multiple time in same JVM. - pluginOptions = new PluginsOptions(getPluginsPath(args)); + pluginOptions = new PluginsHelper(getPluginsPath(args)); // First extract plugins path if any String pp = null; List<String> filteredArgs = new ArrayList<>(); for (int i = 0; i < args.length; i++) { - if (args[i].equals(PluginsOptions.PLUGINS_PATH)) { + if (args[i].equals(PluginsHelper.PLUGINS_PATH)) { if (i == args.length - 1) { throw new BadArgs("err.no.plugins.path").showUsage(true); } else { @@ -529,7 +565,7 @@ for (int i = 0; i < args.length; i++) { if (args[i].charAt(0) == '-') { String name = args[i]; - PlugOption pluginOption = null; + PluginOption pluginOption = null; Option<T> option = getOption(name); if (option == null) { pluginOption = pluginOptions.getOption(name); @@ -585,32 +621,13 @@ } public void showHelp(String progName) { - showHelp(progName, true); - } - - private void showHelp(String progName, boolean showsImageBuilder) { log.println(bundleHelper.getMessage("main.usage", progName)); - for (Option<?> o : options) { - String name = o.aliases[0].substring(1); // there must always be at least one name - name = name.charAt(0) == '-' ? name.substring(1) : name; - if (o.isHidden() || name.equals("h")) { - continue; - } - log.println(bundleHelper.getMessage("main.opt." + name)); - } - - for (Option<?> o : pluginOptions.mainOptions) { - if (o.aliases[0].equals(PluginsOptions.POST_PROCESS) - && !showsImageBuilder) { - continue; - } - String name = o.aliases[0].substring(1); // there must always be at least one name - name = name.charAt(0) == '-' ? name.substring(1) : name; - if (o.isHidden()) { - continue; - } - log.println(bundleHelper.getMessage("plugin.opt." + name)); - } + Stream.concat(options.stream(), pluginOptions.mainOptions.stream()) + .filter(option -> !option.isHidden()) + .sorted() + .forEach(option -> { + log.println(bundleHelper.getMessage(option.resourceName())); + }); log.println(bundleHelper.getMessage("main.command.files")); } @@ -619,6 +636,7 @@ log.println("\n" + bundleHelper.getMessage("main.extended.help")); List<Plugin> pluginList = PluginRepository. getPlugins(pluginOptions.pluginsLayer); + for (Plugin plugin : Utils.getSortedPlugins(pluginList)) { showPlugin(plugin, log); } @@ -671,7 +689,7 @@ } } - private PluginsOptions pluginOptions; + private PluginsHelper pluginOptions; private PrintWriter log; private final ResourceBundleHelper bundleHelper;
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/packager/AppRuntimeImageBuilder.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/packager/AppRuntimeImageBuilder.java Tue Nov 22 11:46:06 2016 -0800 @@ -118,8 +118,6 @@ null)); } - plugins.add(Jlink.newPlugin("installed-modules", Collections.emptyMap(), null)); - // build the image Jlink.PluginsConfiguration pluginConfig = new Jlink.PluginsConfiguration( plugins, new DefaultImageBuilder(outputDir), null);
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/jlink.properties Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/jlink.properties Tue Nov 22 11:46:06 2016 -0800 @@ -24,46 +24,51 @@ # main.usage.summary=\ -Usage: {0} <options> --module-path <modulepath> --add-modules <mods> --output <path>\n\ -use --help for a list of possible options +Usage: {0} <options> --module-path <modulepath> --add-modules <mods> --output\n\ +\<path> use --help for a list of possible options main.usage=\ -Usage: {0} <options> --module-path <modulepath> --add-modules <mods> --output <path>\n\ -\Possible options include: +Usage: {0} <options> --module-path <modulepath> --add-modules <mods> --output +\<path> Possible options include: error.prefix=Error: warn.prefix=Warning: main.opt.help=\ -\ -h, --help Print this help message +\ -h, --help Print this help message main.opt.version=\ -\ --version Version information +\ --version Version information main.opt.module-path=\ -\ -p <modulepath>\n\ -\ --module-path <modulepath> Module path +\ -p, --module-path <path> Module path main.opt.add-modules=\ -\ --add-modules <mod>[,<mod>...] Root modules to resolve +\ --add-modules <mod>[,<mod>...] Root modules to resolve main.opt.limit-modules=\ -\ --limit-modules <mod>[,<mod>...] Limit the universe of observable modules +\ --limit-modules <mod>[,<mod>...] Limit the universe of observable\n\ +\ modules main.opt.output=\ -\ --output <path> Location of output path +\ --output <path> Location of output path main.command.files=\ -\ @<filename> Read options from file +\ @<filename> Read options from file main.opt.endian=\ -\ --endian <little|big> Byte order of generated jimage (default:native) +\ --endian <little|big> Byte order of generated jimage\n\ +\ (default:native) main.opt.save-opts=\ -\ --save-opts <filename> Save jlink options in the given file +\ --save-opts <filename> Save jlink options in the given file main.opt.ignore-signing-information=\ -\ --ignore-signing-information Ignore signing information in modular JARs +\ --ignore-signing-information Suppress a fatal error when signed\n\ +\ modular JARs are linked in the image.\n\ +\ The signature related files of the\n\ +\ signed modular JARs are not copied to\n\ +\ the runtime image. main.msg.bug=\ An exception has occurred in jlink. \ @@ -75,13 +80,13 @@ \List of available plugins: main.extended.help.footer=\ -\For options requiring a <pattern-list>, the value will be a comma\ -\ separated list of elements each using one the following forms:\n\ +\For options requiring a <pattern-list>, the value will be a comma separated\n\ +\list of elements each using one the following forms:\n\ \ <glob-pattern>\n\ \ glob:<glob-pattern>\n\ \ regex:<regex-pattern>\n\ -\ @<filename> where filename is the name of a file containing patterns to be\ -\ used, one pattern per line\n\ +\ @<filename> where filename is the name of a file containing patterns to be\n\ +\ used, one pattern per line\n\ \n\ @@ -110,6 +115,6 @@ err.not.modular.format=selected module {0} ({1}) not in jmod or modular JAR format err.signing=signed modular JAR {0} is currently not supported,\ \ use --ignore-signing-information to suppress error -warn.signing=signed modular JAR {0} is currently not supported +warn.signing=WARNING: signed modular JAR {0} is currently not supported warn.invalid.arg=invalid classname or pathname not exist: {0} warn.split.package=package {0} defined in {1} {2}
--- a/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties Tue Nov 22 11:46:06 2016 -0800 @@ -132,32 +132,33 @@ List of available plugin options: plugin.opt.list-plugins=\ -\ --list-plugins List available plugins +\ --list-plugins List available plugins plugin.opt.post-process-path=\ -\ --post-process-path <imagefile> Post process an existing image +\ --post-process-path <imagefile> Post process an existing image plugin.opt.resources-last-sorter=\ -\ --resources-last-sorter <name> The last plugin allowed to sort resources +\ --resources-last-sorter <name> The last plugin allowed to sort\n\ +\ resources plugin.opt.plugin-module-path=\ -\ --plugin-module-path <modulepath> Custom plugin module path +\ --plugin-module-path <modulepath> Custom plugin module path plugin.opt.disable-plugin=\ -\ --disable-plugin <pluginname> Disable the plugin mentioned +\ --disable-plugin <pluginname> Disable the plugin mentioned -plugin.opt.c=\ -\ -c, --compress=<0|1|2> Enable compression of resources\ -\n More details in --list-plugins option +plugin.opt.compress=\ +\ -c, --compress=<0|1|2> Enable compression of resources\n\ +\ More details in --list-plugins option -plugin.opt.G=\ -\ -G, --strip-debug Strip debug information +plugin.opt.strip-debug=\ +\ -G, --strip-debug Strip debug information plugin.opt.no-man-pages=\ -\ --no-man-pages Exclude man pages +\ --no-man-pages Exclude man pages plugin.opt.no-header-files=\ -\ --no-header-files Exclude include header files +\ --no-header-files Exclude include header files main.plugin.name=\ \Plugin Name
--- a/jdk/test/Makefile Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/Makefile Tue Nov 22 11:46:06 2016 -0800 @@ -55,7 +55,7 @@ UNAME = uname UNIQ = uniq WC = wc -ZIP = zip +ZIPEXE = zip # Get OS name from uname (Cygwin inexplicably adds _NT-5.1) UNAME_S := $(shell $(UNAME) -s | $(CUT) -f1 -d_) @@ -143,7 +143,8 @@ -timeoutHandlerDir:$(FAILURE_HANDLER_DIR_MIXED)/jtregFailureHandler.jar \ -observerDir:$(FAILURE_HANDLER_DIR_MIXED)/jtregFailureHandler.jar \ -timeoutHandler:jdk.test.failurehandler.jtreg.GatherProcessInfoTimeoutHandler \ - -observer:jdk.test.failurehandler.jtreg.GatherDiagnosticInfoObserver + -observer:jdk.test.failurehandler.jtreg.GatherDiagnosticInfoObserver \ + -timeoutHandlerTimeout:0 ifeq ($(UNAME_S), CYGWIN) JTREG_FAILURE_HANDLER_OPTIONS += -J-Djava.library.path="$(FAILURE_HANDLER_DIR_MIXED)" endif @@ -161,7 +162,7 @@ ZIP_UP_RESULTS = ( $(MKDIR) -p `$(DIRNAME) $(ARCHIVE_BUNDLE)` \ && $(CD) $(ABS_TEST_OUTPUT_DIR) \ && $(CHMOD) -R a+r . \ - && $(ZIP) -q -r $(ARCHIVE_BUNDLE) . ) + && $(ZIPEXE) -q -r $(ARCHIVE_BUNDLE) . ) # important results files SUMMARY_TXT = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/JTreport/text/summary.txt")
--- a/jdk/test/ProblemList.txt Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/ProblemList.txt Tue Nov 22 11:46:06 2016 -0800 @@ -124,6 +124,7 @@ # jdk_lang java/lang/StringCoding/CheckEncodings.sh 7008363 generic-all +java/lang/ClassLoader/platformClassLoader/DefinePlatformClass.java 8169639 windows-all ############################################################################ @@ -135,7 +136,7 @@ java/lang/instrument/BootClassPath/BootClassPathTest.sh 8072130 macosx-all java/lang/management/MemoryMXBean/Pending.java 8158837 generic-all -java/lang/management/MemoryMXBean/PendingAllGC.sh 8158760 generic-all +java/lang/management/MemoryMXBean/PendingAllGC.sh 8158837 generic-all ############################################################################ @@ -252,10 +253,14 @@ # core_tools -tools/pack200/CommandLineTests.java 7143279,8059906 generic-all +tools/pack200/CommandLineTests.java 8059906 generic-all tools/launcher/FXLauncherTest.java 8068049 linux-all,macosx-all +tools/jimage/JImageExtractTest.java 8169713 generic-all +tools/jimage/JImageListTest.java 8169713 generic-all +tools/jimage/JImageVerifyTest.java 8169713 generic-all + ############################################################################ # jdk_jdi @@ -292,16 +297,6 @@ sun/tools/jcmd/TestJcmdSanity.java 8031482 windows-all -sun/tools/jhsdb/BasicLauncherTest.java 8160376 macosx-all - -sun/tools/jhsdb/HeapDumpTest.java 8160376 macosx-all - -sun/tools/jhsdb/heapconfig/JMapHeapConfigTest.java 8160376 macosx-all - -sun/tools/jps/TestJpsJar.java 8165500 generic-all - -sun/tools/jps/TestJpsJarRelative.java 6456333 generic-all - sun/jvmstat/monitor/MonitoredVm/MonitorVmStartTerminate.java 8057732 generic-all demo/jvmti/compiledMethodLoad/CompiledMethodLoadTest.java 8151899 generic-all
--- a/jdk/test/com/sun/jndi/dns/CheckAccess.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/com/sun/jndi/dns/CheckAccess.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,11 +24,13 @@ /* * @test * @bug 6657619 + * @modules jdk.naming.dns * @summary DnsContext.debug is public static mutable (findbugs) * @author Vincent Ryan */ -import java.lang.reflect.*; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; /* * Check that the 'debug' class member is no longer publicly accessible.
--- a/jdk/test/com/sun/jndi/dns/Test6991580.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/com/sun/jndi/dns/Test6991580.java Tue Nov 22 11:46:06 2016 -0800 @@ -30,13 +30,14 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -/** +/* * @test * @bug 6991580 8080108 8133035 * @requires os.family != "windows" * @summary IPv6 Nameservers in resolv.conf throws NumberFormatException - * @modules jdk.naming.dns/com.sun.jndi.dns - * @build IPv6NameserverPlatformParsingTest + * @modules java.desktop + * jdk.naming.dns/com.sun.jndi.dns + * @compile --add-modules jdk.naming.dns IPv6NameserverPlatformParsingTest.java * @run main/manual Test6991580 */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/com/sun/jndi/ldap/TEST.properties Tue Nov 22 11:46:06 2016 -0800 @@ -0,0 +1,1 @@ +modules = java.naming
--- a/jdk/test/com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,6 +28,7 @@ * successfully. * @modules java.rmi/sun.rmi.registry java.rmi/sun.rmi.server * java.rmi/sun.rmi.transport java.rmi/sun.rmi.transport.tcp + * jdk.naming.rmi * @library ../../../../../../java/rmi/testlibrary * @build TestLibrary * @run main UnbindIdempotent @@ -49,8 +50,10 @@ try { rctx = (Context)ictx.lookup("rmi://localhost:" + Integer.toString(registryPort)); + System.out.println("Got context: " + rctx.getClass()); } catch (NamingException e) { // Unable to set up for test. + System.err.println("WARNING: The test skipped due to NamingException: " + e); return; }
--- a/jdk/test/com/sun/management/GarbageCollectorMXBean/GarbageCollectionNotificationContentTest.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/com/sun/management/GarbageCollectorMXBean/GarbageCollectionNotificationContentTest.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -72,22 +72,9 @@ public static void main(String[] args) throws Exception { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - final Boolean isNotificationSupported = AccessController.doPrivileged (new PrivilegedAction<Boolean>() { - public Boolean run() { - try { - Class cl = Class.forName("sun.management.VMManagementImpl"); - Field f = cl.getDeclaredField("gcNotificationSupport"); - f.setAccessible(true); - return f.getBoolean(null); - } catch(ClassNotFoundException e) { - return false; - } catch(NoSuchFieldException e) { - return false; - } catch(IllegalAccessException e) { - return false; - } - } - }); + final boolean isNotificationSupported = + sun.management.ManagementFactoryHelper.getVMManagement().isGcNotificationSupported(); + if(!isNotificationSupported) { System.out.println("GC Notification not supported by the JVM, test skipped"); return;
--- a/jdk/test/com/sun/management/GarbageCollectorMXBean/GarbageCollectionNotificationTest.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/com/sun/management/GarbageCollectorMXBean/GarbageCollectionNotificationTest.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -71,22 +71,9 @@ public static void main(String[] args) throws Exception { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - final Boolean isNotificationSupported = AccessController.doPrivileged (new PrivilegedAction<Boolean>() { - public Boolean run() { - try { - Class cl = Class.forName("sun.management.VMManagementImpl"); - Field f = cl.getDeclaredField("gcNotificationSupport"); - f.setAccessible(true); - return f.getBoolean(null); - } catch(ClassNotFoundException e) { - return false; - } catch(NoSuchFieldException e) { - return false; - } catch(IllegalAccessException e) { - return false; - } - } - }); + final boolean isNotificationSupported = + sun.management.ManagementFactoryHelper.getVMManagement().isGcNotificationSupported(); + if(!isNotificationSupported) { System.out.println("GC Notification not supported by the JVM, test skipped"); return;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/com/sun/nio/sctp/TEST.properties Tue Nov 22 11:46:06 2016 -0800 @@ -0,0 +1,2 @@ +modules = jdk.sctp +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/modules/AppendToClassPathModuleTest.java Tue Nov 22 11:46:06 2016 -0800 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8169909 + * @library src /lib/testlibrary + * @build test/* + * @run shell AppendToClassPathModuleTest.sh + * @run main AppendToClassPathModuleTest + */ + +import java.util.Map; +import static jdk.testlibrary.ProcessTools.*; + +/** + * Launch a modular test with no class path and no CLASSPATH set. + * The java agent appends to the "hidden" directory to the class path + * at runtime. + */ +public class AppendToClassPathModuleTest { + public static void main(String... args) throws Throwable { + String modulepath = System.getProperty("test.module.path"); + ProcessBuilder pb = + createJavaProcessBuilder("-javaagent:Agent.jar", + "--module-path", modulepath, + "-m", "test/jdk.test.Main"); + + // remove CLASSPATH environment variable + Map<String,String> env = pb.environment(); + String value = env.remove("CLASSPATH"); + + int exitCode = executeCommand(pb).getExitValue(); + if (exitCode != 0) { + throw new RuntimeException("Test failed: " + exitCode); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/modules/AppendToClassPathModuleTest.sh Tue Nov 22 11:46:06 2016 -0800 @@ -0,0 +1,67 @@ +#!/bin/sh + +# +# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code 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 +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +if [ "${TESTSRC}" = "" ] +then + echo "TESTSRC not set. Test cannot execute. Failed." + exit 1 +fi +echo "TESTSRC=${TESTSRC}" + +if [ "${TESTJAVA}" = "" ] +then + echo "TESTJAVA not set. Test cannot execute. Failed." + exit 1 +fi +echo "TESTJAVA=${TESTJAVA}" + +if [ "${COMPILEJAVA}" = "" ] +then + COMPILEJAVA="${TESTJAVA}" +fi +echo "COMPILEJAVA=${COMPILEJAVA}" + +if [ "${TESTCLASSES}" = "" ] +then + echo "TESTCLASSES not set. Test cannot execute. Failed." + exit 1 +fi + +echo "TESTCLASSES=${TESTCLASSES}" + +mkdir -p hidden +${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} \ + -d hidden ${TESTSRC}/../ExampleForClassPath.java + +mkdir -p classes +${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} \ + -d classes ${TESTSRC}/../InstrumentationHandoff.java + +echo "Manifest-Version: 1.0" > Agent.mf +echo "Class-Path: hidden/" >> Agent.mf +echo "Premain-Class: InstrumentationHandoff" >> Agent.mf + +${TESTJAVA}/bin/jar ${TESTTOOLVMOPTS} cvfm Agent.jar \ + Agent.mf -C classes InstrumentationHandoff.class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/modules/src/test/jdk/test/Main.java Tue Nov 22 11:46:06 2016 -0800 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.test; + +/** + * Launched by AppendToClassPathModuleTest. + */ +public class Main { + public static void main(String... args) throws Exception { + // "java.class.path" system property is expected to be empty. + String value = System.getProperty("java.class.path"); + if (!value.isEmpty()) { + throw new RuntimeException("Non-empty java.class.path=" + value); + } + + // load the "hidden" class that should be loaded by the system loader + Class<?> c = Class.forName("ExampleForClassPath"); + if (c.getClassLoader() != ClassLoader.getSystemClassLoader()) { + throw new RuntimeException(c + " loaderd by " + c.getClassLoader()); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/instrument/modules/src/test/module-info.java Tue Nov 22 11:46:06 2016 -0800 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +module test { +}
--- a/jdk/test/java/lang/invoke/8022701/InvokeSeveralWays.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/lang/invoke/8022701/InvokeSeveralWays.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,18 +37,11 @@ failures++; } catch (InvocationTargetException e) { Throwable c = e.getCause(); - if (BootstrapMethodError.class.isInstance(c)) { - c = c.getCause(); - if (expected.isInstance(c)) - System.out.println("EXPECTED: " + expected.getName() + ", "+ c); - else { - failures++; - System.out.println("FAIL: Unexpected wrapped exception " + c); - e.printStackTrace(System.out); - } - } else { + if (expected.isInstance(c)) + System.out.println("EXPECTED: " + expected.getName() + ", "+ c); + else { failures++; - System.out.println("FAIL: Exception from MethodHandle invocation not wrapped in BootstrapMethodError " + c); + System.out.println("FAIL: Unexpected wrapped exception " + c); e.printStackTrace(System.out); } } catch (Throwable e) { @@ -80,19 +73,14 @@ Invoker.invoke(); System.out.println("FAIL: No exception throw, probably failed to load modified bytecodes for MethodSupplier"); failures++; - } catch (BootstrapMethodError e) { - Throwable c = e.getCause(); - if (expected.isInstance(c)) - System.out.println("EXPECTED: " + expected.getName() + ", "+ c); + } catch (Throwable e) { + if (expected.isInstance(e)) + System.out.println("EXPECTED: " + expected.getName() + ", "+ e); else { failures++; - System.out.println("FAIL: Unexpected exception has been caught " + c); + System.out.println("FAIL: Unexpected exception has been caught " + e); e.printStackTrace(System.out); } - } catch (Throwable e) { - failures++; - System.out.println("FAIL: Exception from MethodHandle invocation not wrapped in BootstrapMethodError " + e); - e.printStackTrace(System.out); } System.out.println(); try {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/management/ManagementFactory/DefaultManagementProviderTest.java Tue Nov 22 11:46:06 2016 -0800 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8151099 + * @summary Verify platform MXBeans initialized properly with java.management + * module only. No other management provider + * @run main/othervm --limit-modules=java.management DefaultManagementProviderTest + */ +import java.lang.management.ManagementFactory; + +public class DefaultManagementProviderTest { + public static void main(String[] argv) { + ManagementFactory.getPlatformMBeanServer(); + System.out.println("Test case passed"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/net/Authenticator/GetAuthenticatorTest.java Tue Nov 22 11:46:06 2016 -0800 @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +import java.lang.ref.Reference; +import java.net.Authenticator; +import java.net.NetPermission; +import java.net.PasswordAuthentication; +import java.security.AccessControlException; + +/** + * @test + * @bug 8169068 + * @summary Basic test for Authenticator.getDefault() + * @run main/othervm GetAuthenticatorTest + */ +public class GetAuthenticatorTest { + + static final class MyAuthenticator extends Authenticator { + + MyAuthenticator () { + super (); + } + + @Override + public PasswordAuthentication getPasswordAuthentication () { + System.out.println ("Auth called"); + return (new PasswordAuthentication ("user", + "passwordNotCheckedAnyway".toCharArray())); + } + + } + + public static void main (String args[]) throws Exception { + Authenticator defaultAuth = Authenticator.getDefault(); + if (defaultAuth != null) { + throw new RuntimeException("Unexpected authenticator: null expected"); + } + MyAuthenticator auth = new MyAuthenticator(); + Authenticator.setDefault(auth); + defaultAuth = Authenticator.getDefault(); + if (defaultAuth != auth) { + throw new RuntimeException("Unexpected authenticator: auth expected"); + } + System.setSecurityManager(new SecurityManager()); + try { + defaultAuth = Authenticator.getDefault(); + throw new RuntimeException("Expected security exception not raised"); + } catch (AccessControlException s) { + System.out.println("Got expected exception: " + s); + if (!s.getPermission().equals(new NetPermission("requestPasswordAuthentication"))) { + throw new RuntimeException("Unexpected permission check: " + s.getPermission()); + } + } + System.out.println("Test passed with default authenticator " + + defaultAuth); + } +}
--- a/jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java Tue Nov 22 11:46:06 2016 -0800 @@ -219,7 +219,8 @@ throw new RuntimeException("ExecutionException expected"); } catch (ExecutionException x) { if (!(x.getCause() instanceof ClosedChannelException)) - throw new RuntimeException("Cause of ClosedChannelException expected"); + throw new RuntimeException("Cause of ClosedChannelException expected", + x.getCause()); } final AtomicReference<Throwable> connectException = new AtomicReference<>(); ch.connect(server.address(), (Void)null, new CompletionHandler<Void,Void>() { @@ -233,7 +234,8 @@ Thread.sleep(100); } if (!(connectException.get() instanceof ClosedChannelException)) - throw new RuntimeException("ClosedChannelException expected"); + throw new RuntimeException("ClosedChannelException expected", + connectException.get()); } // test that failure to connect closes the channel @@ -353,7 +355,8 @@ Thread.sleep(100); } if (!(writeException.get() instanceof AsynchronousCloseException)) - throw new RuntimeException("AsynchronousCloseException expected"); + throw new RuntimeException("AsynchronousCloseException expected", + writeException.get()); } } @@ -460,7 +463,8 @@ throw new RuntimeException("ExecutionException expected"); } catch (ExecutionException x) { if (!(x.getCause() instanceof ClosedChannelException)) - throw new RuntimeException("Cause of ClosedChannelException expected"); + throw new RuntimeException("Cause of ClosedChannelException expected", + x.getCause()); } } } @@ -630,7 +634,8 @@ throw new RuntimeException("ExecutionException expected"); } catch (ExecutionException x) { if (!(x.getCause() instanceof ClosedChannelException)) - throw new RuntimeException("Cause of ClosedChannelException expected"); + throw new RuntimeException("Cause of ClosedChannelException expected", + x.getCause()); } } } @@ -738,7 +743,8 @@ throw new RuntimeException("ClosedChannelException expected"); } catch (ExecutionException x) { if (!(x.getCause() instanceof ClosedChannelException)) - throw new RuntimeException("ClosedChannelException expected"); + throw new RuntimeException("ClosedChannelException expected", + x.getCause()); } } } @@ -776,7 +782,8 @@ Thread.sleep(100); } if (!(readException.get() instanceof InterruptedByTimeoutException)) - throw new RuntimeException("InterruptedByTimeoutException expected"); + throw new RuntimeException("InterruptedByTimeoutException expected", + readException.get()); // after a timeout then further reading should throw unspecified runtime exception boolean exceptionThrown = false; @@ -813,7 +820,8 @@ Thread.sleep(100); } if (!(writeException.get() instanceof InterruptedByTimeoutException)) - throw new RuntimeException("InterruptedByTimeoutException expected"); + throw new RuntimeException("InterruptedByTimeoutException expected", + writeException.get()); // after a timeout then further writing should throw unspecified runtime exception boolean exceptionThrown = false;
--- a/jdk/test/java/rmi/activation/Activatable/checkActivateRef/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/checkActivateRef/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -4,4 +4,6 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.rmi.server.useDynamicProxies=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/Activatable/checkAnnotations/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/checkAnnotations/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,6 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/Activatable/checkImplClassLoader/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/checkImplClassLoader/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,6 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/Activatable/checkRegisterInLog/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/checkRegisterInLog/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,7 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; + permission java.net.SocketPermission "*:1024-", "listen,resolve,connect,accept"; };
--- a/jdk/test/java/rmi/activation/Activatable/createPrivateActivable/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/createPrivateActivable/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,6 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/Activatable/downloadParameterClass/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/downloadParameterClass/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,6 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -4,4 +4,6 @@ permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/Activatable/forceLogSnapshot/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/forceLogSnapshot/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,7 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; + permission java.net.SocketPermission "*:1024-", "listen,resolve,connect,accept"; };
--- a/jdk/test/java/rmi/activation/Activatable/inactiveGroup/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/inactiveGroup/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,6 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/Activatable/lookupActivationSystem/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/lookupActivationSystem/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -1,4 +1,6 @@ grant { permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/Activatable/nestedActivate/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/nestedActivate/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,6 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/Activatable/nonExistentActivatable/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/nonExistentActivatable/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,6 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/Activatable/restartCrashedService/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/restartCrashedService/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,7 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; + permission java.net.SocketPermission "*:1024-", "listen,resolve,connect,accept"; };
--- a/jdk/test/java/rmi/activation/Activatable/restartLatecomer/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/restartLatecomer/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,6 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/Activatable/restartService/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/restartService/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,7 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; + permission java.net.SocketPermission "*:1024-", "listen,resolve,connect,accept"; };
--- a/jdk/test/java/rmi/activation/Activatable/shutdownGracefully/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/shutdownGracefully/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -4,4 +4,6 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Ddummyname=dummyvalue"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/Activatable/unregisterInactive/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/Activatable/unregisterInactive/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,6 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,6 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; };
--- a/jdk/test/java/rmi/activation/ActivationSystem/modifyDescriptor/ModifyDescriptor.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/ActivationSystem/modifyDescriptor/ModifyDescriptor.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -33,8 +33,9 @@ * java.rmi/sun.rmi.server * java.rmi/sun.rmi.transport * java.rmi/sun.rmi.transport.tcp + * java.base/sun.nio.ch * @build TestLibrary RMID ActivationLibrary - * ActivateMe ModifyDescriptor_Stub + * ActivateMe ModifyDescriptor_Stub RMIDSelectorProvider * @run main/othervm/policy=security.policy/timeout=240 ModifyDescriptor */
--- a/jdk/test/java/rmi/activation/ActivationSystem/modifyDescriptor/rmid.security.policy Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/activation/ActivationSystem/modifyDescriptor/rmid.security.policy Tue Nov 22 11:46:06 2016 -0800 @@ -3,4 +3,9 @@ permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; permission com.sun.rmi.rmid.ExecOptionPermission "-Dtest.message=hello"; permission com.sun.rmi.rmid.ExecOptionPermission "-Dtest.message=hello, again"; + permission java.lang.RuntimePermission "selectorProvider"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.port", "read"; + permission java.util.PropertyPermission "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", "read"; + permission java.net.SocketPermission "*:1024-", "listen,resolve,connect,accept"; };
--- a/jdk/test/java/rmi/testlibrary/RMID.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/testlibrary/RMID.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ import java.rmi.*; import java.rmi.activation.*; import java.rmi.registry.*; +import java.time.LocalTime; import java.util.concurrent.TimeoutException; /** @@ -44,6 +45,15 @@ private static final long STARTTIME_MS = 15_000L; private static final long POLLTIME_MS = 100L; + // when restart rmid, it may take more time than usual because of + // "port in use" by a possible interloper (check JDK-8168975), + // so need to set a longer timeout for restart. + private static long restartTimeout; + // Same reason to inheritedChannel in RMIDSelectorProvider. + // Put it here rather than in RMIDSelectorProvider to adjust + // both timeout values together. + private static long inheritedChannelTimeout; + private static final String SYSTEM_NAME = ActivationSystem.class.getName(); // "java.rmi.activation.ActivationSystem" @@ -73,7 +83,8 @@ } /** make test options and arguments */ - private static String makeOptions(int port, boolean debugExec) { + private static String makeOptions(int port, boolean debugExec, + boolean enableSelectorProvider) { String options = " -Dsun.rmi.server.activation.debugExec=" + debugExec; @@ -98,12 +109,24 @@ // to avoid spurious timeouts on slow machines. options += " -Dsun.rmi.activation.execTimeout=60000"; - if (port == 0) { + // It's important to set handshakeTimeout to small value, for example + // 5 sec (default is 60 sec) to avoid wasting too much time when + // calling lookupSystem(port) in restart(), because + // 1. If use default value of this option, it will take about 2 minutes + // to finish lookupSystem(port) in 2 loops in restart(); + // 2. If set this option as 5 sec then lookupSystem(port) will return + // very quickly. + options += " -Dsun.rmi.transport.tcp.handshakeTimeout=5000"; + + if (port == 0 || enableSelectorProvider) { // Ephemeral port, so have the rmid child process create the // server socket channel and report its port number, over stdin. options += " -classpath " + TestParams.testClassPath; options += " --add-exports=java.base/sun.nio.ch=ALL-UNNAMED"; options += " -Djava.nio.channels.spi.SelectorProvider=RMIDSelectorProvider"; + options += " -Dtest.java.rmi.testlibrary.RMIDSelectorProvider.port=" + port; + options += " -Dtest.java.rmi.testlibrary.RMIDSelectorProvider.timeout=" + + inheritedChannelTimeout; // Disable redirection of System.err to /tmp options += " -Dsun.rmi.server.activation.disableErrRedirect=true"; @@ -112,6 +135,10 @@ return options; } + private static String makeArgs() { + return makeArgs(false, 0); + } + private static String makeArgs(boolean includePortArg, int port) { String propagateManager = null; @@ -183,7 +210,7 @@ boolean debugExec, boolean includePortArg, int port) { - String options = makeOptions(port, debugExec); + String options = makeOptions(port, debugExec, false); String args = makeArgs(includePortArg, port); RMID rmid = new RMID("sun.rmi.server.Activation", options, args, out, err, port); @@ -193,14 +220,14 @@ } public static RMID createRMIDOnEphemeralPort() { - return createRMID(System.out, System.err, true, true, 0); + return createRMID(System.out, System.err, true, false, 0); } public static RMID createRMIDOnEphemeralPort(OutputStream out, OutputStream err, boolean debugExec) { - return createRMID(out, err, debugExec, true, 0); + return createRMID(out, err, debugExec, false, 0); } @@ -213,6 +240,9 @@ { super(classname, options, args, out, err); this.port = port; + long waitTime = (long)(240_000 * TestLibrary.getTimeoutFactor()); + restartTimeout = (long)(waitTime * 0.9); + inheritedChannelTimeout = (long)(waitTime * 0.8); } /** @@ -280,11 +310,11 @@ // if rmid is already running, then the test will fail with // a well recognized exception (port already in use...). - mesg("Starting rmid on port " + port + "."); + mesg("Starting rmid on port " + port + ", at " + LocalTime.now()); int p = super.startAndGetPort(); if (p != -1) port = p; - mesg("Started rmid on port " + port + "."); + mesg("Started rmid on port " + port + ", at " + LocalTime.now()); // int slopFactor = 1; // try { @@ -318,6 +348,7 @@ // The rmid process is alive; check to see whether // it responds to a remote call. + mesg("looking up activation system, at " + LocalTime.now()); if (lookupSystem(port) != null) { /* * We need to set the java.rmi.activation.port value as the @@ -328,10 +359,11 @@ */ System.setProperty("java.rmi.activation.port", Integer.toString(port)); mesg("Started successfully after " + - (System.currentTimeMillis() - startTime) + "ms."); + (System.currentTimeMillis() - startTime) + "ms, at " + LocalTime.now()); return; } + mesg("after fail to looking up activation system, at " + LocalTime.now()); if (System.currentTimeMillis() > deadline) { TestLibrary.bomb("Failed to start rmid, giving up after " + (System.currentTimeMillis() - startTime) + "ms.", null); @@ -347,9 +379,10 @@ */ public void restart() throws IOException { destroy(); - options = makeOptions(port, true); - args = makeArgs(true, port); - start(); + options = makeOptions(port, true, true); + args = makeArgs(); + + start(restartTimeout); } /**
--- a/jdk/test/java/rmi/testlibrary/RMIDSelectorProvider.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/testlibrary/RMIDSelectorProvider.java Tue Nov 22 11:46:06 2016 -0800 @@ -22,6 +22,7 @@ */ import java.io.*; +import java.net.BindException; import java.net.InetSocketAddress; import java.net.ProtocolFamily; import java.nio.channels.Channel; @@ -31,6 +32,7 @@ import java.nio.channels.SocketChannel; import java.nio.channels.spi.AbstractSelector; import java.nio.channels.spi.SelectorProvider; +import java.time.LocalTime; import static java.net.StandardSocketOptions.SO_REUSEADDR; import static java.net.StandardSocketOptions.SO_REUSEPORT; @@ -98,7 +100,37 @@ channel.setOption(SO_REUSEPORT, true); } - channel.bind(new InetSocketAddress(0)); + // when it comes here, these properties should have been set with + // a valid value, but assign a default value anyway. + long timeout = Long.getLong( + "test.java.rmi.testlibrary.RMIDSelectorProvider.timeout", + 200_000); + long deadline = System.currentTimeMillis() + timeout; + int port = Integer.getInteger( + "test.java.rmi.testlibrary.RMIDSelectorProvider.port", 0); + while (true) { + try { + channel.bind(new InetSocketAddress(port)); + break; + } catch (BindException ex) { + System.out.format("RMIDSelectorProvider: " + + "failed to bind to port %d due to \"%s\", at %s%n", + port, ex.getMessage(), LocalTime.now()); + } + if (System.currentTimeMillis() > deadline) { + System.out.format("RMIDSelectorProvider: " + + "fail to bind to port %d after trying for " + + "%d seconds, exiting rmid process, at %s%n", + port, timeout/1000, LocalTime.now()); + channel.close(); + // can not start rmid on specific port, + // there is no need to continue run rmid. + System.exit(1); + } + try { + Thread.sleep(1000); + } catch(InterruptedException ignore) { } + } System.out.println(RMID.EPHEMERAL_MSG + channel.socket().getLocalPort()); }
--- a/jdk/test/java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -53,7 +53,7 @@ public class ReuseDefaultPort implements Remote { - private static final int PORT = TestLibrary.getUnusedRandomPort(); + private static int rmiPort = 0; private ReuseDefaultPort() { } @@ -64,7 +64,7 @@ Remote stub = UnicastRemoteObject.exportObject(impl, 0); System.err.println("- exported object: " + stub); try { - Registry registry = LocateRegistry.createRegistry(PORT); + Registry registry = LocateRegistry.createRegistry(rmiPort); System.err.println("- exported registry: " + registry); System.err.println("TEST PASSED"); } finally { @@ -77,13 +77,15 @@ RMISocketFactory.getDefaultSocketFactory(); SF() { } public Socket createSocket(String host, int port) throws IOException { + System.err.format("in SF::createSocket: %s, %d%n", host, port); return defaultFactory.createSocket(host, port); } public ServerSocket createServerSocket(int port) throws IOException { - if (port == 0) { - port = PORT; - } - return defaultFactory.createServerSocket(port); + System.err.format("in SF::createServerSocket: %d%n", port); + ServerSocket server = defaultFactory.createServerSocket(port); + rmiPort = server.getLocalPort(); + System.err.println("rmiPort: " + rmiPort); + return server; } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/security/ProtectionDomain/NullGetActions.java Tue Nov 22 11:46:06 2016 -0800 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8043252 + * @summary Debug of access control is obfuscated - NullPointerException in + * ProtectionDomain + * @run main/othervm/java.security.policy=NullGetActions.policy NullGetActions + */ + +import java.net.*; +import java.security.*; + +public class NullGetActions { + + public static void main(String[] args) throws Exception { + Permissions permset = new Permissions(); + permset.add(new EvilPermission("java.let.me.do.stuff")); + + Policy.getPolicy(); + ProtectionDomain protDom = new ProtectionDomain( + new CodeSource(new URL("http://bar"), + (java.security.cert.Certificate[])null), permset, + null, null); + + System.out.println("Protection Domain:\n" + protDom); + } + + public static class EvilPermission extends Permission { + public EvilPermission(String name) { + super(name); + } + + @Override + public String getActions() { + return null; + } + + @Override + public boolean equals(Object obj) { + return (obj == this); + } + + @Override + public int hashCode() { + return 42; + } + + @Override + public boolean implies(Permission permission) { + return false; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/security/ProtectionDomain/NullGetActions.policy Tue Nov 22 11:46:06 2016 -0800 @@ -0,0 +1,3 @@ +grant { + permission java.security.SecurityPermission "getPolicy"; +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/security/SecureRandom/NoSync.java Tue Nov 22 11:46:06 2016 -0800 @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.security.Provider; +import java.security.SecureRandom; +import java.security.Security; +import java.util.Date; +import java.util.concurrent.atomic.AtomicBoolean; + +/* + * @test + * @bug 7004967 + * @run main/othervm NoSync + * @summary SecureRandom should be more explicit about threading + */ +public class NoSync { + public static void main(String[] args) throws Exception { + for (Provider p : Security.getProviders()) { + for (Provider.Service s : p.getServices()) { + if (s.getType().equals("SecureRandom") && + !s.getAlgorithm().contains("Block")) { + test(SecureRandom.getInstance(s.getAlgorithm(), p)); + } + } + } + Security.setProperty("securerandom.drbg.config", "HMAC_DRBG"); + test(SecureRandom.getInstance("DRBG")); + Security.setProperty("securerandom.drbg.config", "CTR_DRBG"); + test(SecureRandom.getInstance("DRBG")); + } + + static void test(SecureRandom sr) throws Exception { + test(sr, 20, 3000); + // All out-of-box impl should have the ThreadSafe attribute + String attr = sr.getProvider().getProperty("SecureRandom." + + sr.getAlgorithm() + " ThreadSafe"); + if (!"true".equals(attr)) { + throw new Exception("Not ThreadSafe: " + attr); + } + } + + public static void test(SecureRandom sr, int tnum, int rnum) + throws Exception { + + System.out.println(sr); + System.out.println(sr.getAlgorithm() + " " + sr.getProvider().getName()); + + System.out.println(new Date()); + boolean reseed = sr.getParameters() != null; + Thread[] threads = new Thread[tnum]; + AtomicBoolean failed = new AtomicBoolean(false); + Thread.UncaughtExceptionHandler h = (t, e) -> { + failed.set(true); + e.printStackTrace(); + }; + for (int i = 0; i < threads.length; i++) { + threads[i] = new Thread() { + @Override + public void run() { + for (int j = 0; j < rnum; j++) { + sr.nextBytes(new byte[j%100+100]); + sr.setSeed((long)j); + if (reseed) { + sr.reseed(); + } + } + } + }; + threads[i].setUncaughtExceptionHandler(h); + threads[i].start(); + } + for (int i = 0; i < threads.length; i++) { + threads[i].join(); + } + System.out.println(new Date()); + System.out.println(); + if (failed.get()) { + throw new RuntimeException("Failed"); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/security/SecureRandom/ThreadSafe.java Tue Nov 22 11:46:06 2016 -0800 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.security.Provider; +import java.security.SecureRandom; +import java.security.SecureRandomSpi; +import java.util.Map; + +/* + * @test + * @bug 7004967 + * @summary SecureRandom should be more explicit about threading + */ +public class ThreadSafe { + public static void main(String[] args) throws Exception { + Provider p = new P(); + NoSync.test(SecureRandom.getInstance("S1", p), 5, 5); + try { + NoSync.test(SecureRandom.getInstance("S2", p), 5, 5); + throw new Exception("Failed"); + } catch (RuntimeException re) { + // Good + } + NoSync.test(SecureRandom.getInstance("S3", p), 5, 5); + try { + NoSync.test(SecureRandom.getInstance("S4", p), 5, 5); + throw new Exception("Failed"); + } catch (RuntimeException re) { + // Good + } + } + + public static class P extends Provider { + public P() { + + super("P", 1.0d, "Haha"); + + // Good. No attribute. + put("SecureRandom.S1", S.class.getName()); + + // Bad. Boasting ThreadSafe but isn't + put("SecureRandom.S2", S.class.getName()); + put("SecureRandom.S2 ThreadSafe", "true"); + + // Good. No attribute. + putService(new Service(this, "SecureRandom", "S3", + S.class.getName(), null, null)); + + // Bad. Boasting ThreadSafe but isn't + putService(new Service(this, "SecureRandom", "S4", + S.class.getName(), null, Map.of("ThreadSafe", "true"))); + } + } + + // This implementation is not itself thread safe. + public static class S extends SecureRandomSpi { + @java.lang.Override + protected void engineSetSeed(byte[] seed) { + return; + } + + private volatile boolean inCall = false; + @Override + protected void engineNextBytes(byte[] bytes) { + if (inCall) { + throw new RuntimeException("IN CALL"); + } + inCall = true; + try { + Thread.sleep(100); + } catch (Exception e) { + // OK + } + inCall = false; + } + + @Override + protected byte[] engineGenerateSeed(int numBytes) { + return new byte[numBytes]; + } + } +}
--- a/jdk/test/java/text/testlib/IntlTest.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/text/testlib/IntlTest.java Tue Nov 22 11:46:06 2016 -0800 @@ -89,6 +89,9 @@ case "-nothrow": nothrow = true; break; + case "-exitcode": + exitCode = true; + break; default: Method m = testMethods.get(arg); if (m == null) { @@ -138,7 +141,12 @@ } } if (nothrow) { - System.exit(errorCount); + if (exitCode) { + System.exit(errorCount); + } + if (errorCount > 0) { + throw new IllegalArgumentException("encountered " + errorCount + " errors"); + } } } @@ -243,7 +251,7 @@ */ void usage() { System.out.println(getClass().getName() + - ": [-verbose] [-nothrow] [-prompt] [test names]"); + ": [-verbose] [-nothrow] [-exitcode] [-prompt] [test names]"); System.out.println(" Available test names:"); for (String methodName : testMethods.keySet()) { @@ -254,7 +262,7 @@ private boolean prompt; private boolean nothrow; protected boolean verbose; - + private boolean exitCode; private PrintWriter log; private int indentLevel; private boolean needLineFeed;
--- a/jdk/test/java/time/tck/java/time/format/TCKDateTimeFormatterBuilder.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/time/tck/java/time/format/TCKDateTimeFormatterBuilder.java Tue Nov 22 11:46:06 2016 -0800 @@ -594,7 +594,7 @@ @Test(dataProvider = "formatGenericTimeZonePatterns") public void test_appendZoneText_formatGenericTimeZonePatterns(String pattern, String input, String expected) { ZonedDateTime zdt = ZonedDateTime.of(LocalDateTime.now(), ZoneId.of(input)); - DateTimeFormatter df = DateTimeFormatter.ofPattern(pattern); + DateTimeFormatter df = DateTimeFormatter.ofPattern(pattern, Locale.US); assertEquals(zdt.format(df), expected); } @@ -641,7 +641,7 @@ @Test(dataProvider = "formatNonGenericTimeZonePatterns_1") public void test_appendZoneText_parseNonGenricTimeZonePatterns_1(String pattern, LocalDateTime ldt, String expected) { ZoneId zId = ZoneId.of("America/Los_Angeles"); - DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern(pattern).toFormatter(); + DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern(pattern).toFormatter(Locale.US); ZonedDateTime zdt = ZonedDateTime.of(ldt, zId); String actual = df.format(zdt); assertEquals(actual, expected); @@ -668,7 +668,7 @@ @Test(dataProvider = "formatNonGenericTimeZonePatterns_2") public void test_appendZoneText_parseNonGenricTimeZonePatterns_2(String pattern, LocalDateTime ldt, String expected) { ZoneId zId = ZoneId.of("America/Los_Angeles"); - DateTimeFormatter df = DateTimeFormatter.ofPattern(pattern).withZone(zId); + DateTimeFormatter df = DateTimeFormatter.ofPattern(pattern, Locale.US).withZone(zId); String actual = df.format(ldt); assertEquals(actual, expected); }
--- a/jdk/test/java/time/tck/java/time/zone/TCKZoneRulesProvider.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/time/tck/java/time/zone/TCKZoneRulesProvider.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -91,10 +91,11 @@ public void test_getAvailableGroupIds() { Set<String> zoneIds = ZoneRulesProvider.getAvailableZoneIds(); assertEquals(zoneIds.contains("Europe/London"), true); - zoneIds.clear(); - assertEquals(zoneIds.size(), 0); - Set<String> zoneIds2 = ZoneRulesProvider.getAvailableZoneIds(); - assertEquals(zoneIds2.contains("Europe/London"), true); + } + + @Test(expectedExceptions=UnsupportedOperationException.class) + public void test_getAvailableGroupIds_modifyZoneId() { + ZoneRulesProvider.getAvailableZoneIds().clear(); } //-----------------------------------------------------------------------
--- a/jdk/test/java/util/BitSet/BitSetStreamTest.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/util/BitSet/BitSetStreamTest.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -60,25 +60,6 @@ public int getAsInt() { int s = n1; n1 = n2; n2 = s + n1; return s; } } - private static final Object[][] testcases = new Object[][] { - { "none", IntStream.empty() }, - { "index 0", IntStream.of(0) }, - { "index 255", IntStream.of(255) }, - { "every bit", IntStream.range(0, 255) }, - { "step 2", IntStream.range(0, 255).map(f -> f * 2) }, - { "step 3", IntStream.range(0, 255).map(f -> f * 3) }, - { "step 5", IntStream.range(0, 255).map(f -> f * 5) }, - { "step 7", IntStream.range(0, 255).map(f -> f * 7) }, - { "1, 10, 100, 1000", IntStream.of(1, 10, 100, 1000) }, - { "max int", IntStream.of(Integer.MAX_VALUE) }, - { "25 fibs", IntStream.generate(new Fibs()).limit(25) } - }; - - @DataProvider(name = "cases") - public static Object[][] produceCases() { - return testcases; - } - @Test public void testFibs() { Fibs f = new Fibs(); @@ -93,22 +74,46 @@ assertEquals(987, Fibs.fibs(16)); } + + @DataProvider(name = "cases") + public static Object[][] produceCases() { + return new Object[][] { + { "none", IntStream.empty() }, + { "index 0", IntStream.of(0) }, + { "index 255", IntStream.of(255) }, + { "index 0 and 255", IntStream.of(0, 255) }, + { "index Integer.MAX_VALUE", IntStream.of(Integer.MAX_VALUE) }, + { "index Integer.MAX_VALUE - 1", IntStream.of(Integer.MAX_VALUE - 1) }, + { "index 0 and Integer.MAX_VALUE", IntStream.of(0, Integer.MAX_VALUE) }, + { "every bit", IntStream.range(0, 255) }, + { "step 2", IntStream.range(0, 255).map(f -> f * 2) }, + { "step 3", IntStream.range(0, 255).map(f -> f * 3) }, + { "step 5", IntStream.range(0, 255).map(f -> f * 5) }, + { "step 7", IntStream.range(0, 255).map(f -> f * 7) }, + { "1, 10, 100, 1000", IntStream.of(1, 10, 100, 1000) }, + { "25 fibs", IntStream.generate(new Fibs()).limit(25) } + }; + } + @Test(dataProvider = "cases") public void testBitsetStream(String name, IntStream data) { - BitSet bs = new BitSet(); - long setBits = data.distinct() - .peek(i -> bs.set(i)) - .count(); + BitSet bs = data.collect(BitSet::new, BitSet::set, BitSet::or); + + assertEquals(bs.cardinality(), bs.stream().count()); - assertEquals(bs.cardinality(), setBits); - assertEquals(bs.cardinality(), bs.stream().reduce(0, (s, i) -> s+1)); + int[] indexHolder = new int[] { -1 }; + bs.stream().forEach(i -> { + int ei = indexHolder[0]; + indexHolder[0] = bs.nextSetBit(ei + 1); + assertEquals(i, indexHolder[0]); + }); PrimitiveIterator.OfInt it = bs.stream().iterator(); - for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) { + for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { assertTrue(it.hasNext()); assertEquals(it.nextInt(), i); if (i == Integer.MAX_VALUE) - break; // or (i+1) would overflow + break; // or (i + 1) would overflow } assertFalse(it.hasNext()); } @@ -123,16 +128,20 @@ for (int seed : seeds) { final Random random = new Random(seed); random.nextBytes(bytes); - final BitSet bitSet = BitSet.valueOf(bytes); - final int cardinality = bitSet.cardinality(); - final IntStream stream = bitSet.stream(); - final int[] array = stream.toArray(); - assertEquals(array.length, cardinality); - int nextSetBit = -1; - for (int i=0; i < cardinality; i++) { - nextSetBit = bitSet.nextSetBit(nextSetBit + 1); - assertEquals(array[i], nextSetBit); - } + + BitSet bitSet = BitSet.valueOf(bytes); + testBitSetContents(bitSet, bitSet.stream().toArray()); + testBitSetContents(bitSet, bitSet.stream().parallel().toArray()); + } + } + + void testBitSetContents(BitSet bitSet, int[] array) { + int cardinality = bitSet.cardinality(); + assertEquals(array.length, cardinality); + int nextSetBit = -1; + for (int i = 0; i < cardinality; i++) { + nextSetBit = bitSet.nextSetBit(nextSetBit + 1); + assertEquals(array[i], nextSetBit); } } }
--- a/jdk/test/java/util/Calendar/Bug4766302.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/util/Calendar/Bug4766302.java Tue Nov 22 11:46:06 2016 -0800 @@ -29,9 +29,11 @@ import java.util.GregorianCalendar; +@SuppressWarnings("serial") public class Bug4766302 { static class MyCalendar extends GregorianCalendar { + boolean isTimeStillSet() { return isTimeSet; }
--- a/jdk/test/java/util/Calendar/Bug4958050.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/util/Calendar/Bug4958050.java Tue Nov 22 11:46:06 2016 -0800 @@ -29,9 +29,11 @@ import java.util.Locale; import java.util.TimeZone; + import static java.util.Calendar.*; public class Bug4958050 { + static int errorCount = 0; public static void main(String[] args) { @@ -41,87 +43,87 @@ System.out.println("Time zone = " + cal.getTimeZone().getID()); // Test the week fields - int[] weekFields = { WEEK_OF_YEAR, WEEK_OF_MONTH, DAY_OF_WEEK_IN_MONTH }; + int[] weekFields = {WEEK_OF_YEAR, WEEK_OF_MONTH, DAY_OF_WEEK_IN_MONTH}; for (int i = 0; i < weekFields.length; i++) { int field = weekFields[i]; // add() cal.clear(); - cal.set(1919, DECEMBER, 14-7, 23, 50, 00); + cal.set(1919, DECEMBER, 14 - 7, 23, 50, 00); cal.add(weekFields[i], +1); if (!cal.checkDate(1919, DECEMBER, 14)) { - error("1919/12/07: add("+cal.getFieldName(weekFields[i])+", +1)\n" - + cal.getMessage()+" " + cal.toDateTimeString()); + error("1919/12/07: add(" + Koyomi.getFieldName(weekFields[i]) + ", +1)\n" + + cal.getMessage() + " " + cal.toDateTimeString()); } cal.clear(); - cal.set(1930, JUNE, 21-7); + cal.set(1930, JUNE, 21 - 7); cal.add(weekFields[i], +1); if (!cal.checkDateTime(1930, JUNE, 21, 01, 00, 00, 000)) { - error("1930/6/14: add("+cal.getFieldName(weekFields[i])+", +1)\n" - + cal.getMessage()+" " + cal.toDateTimeString()); + error("1930/6/14: add(" + Koyomi.getFieldName(weekFields[i]) + ", +1)\n" + + cal.getMessage() + " " + cal.toDateTimeString()); } // roll() cal.clear(); - cal.set(1919, DECEMBER, 14-7, 23, 50, 00); + cal.set(1919, DECEMBER, 14 - 7, 23, 50, 00); cal.roll(weekFields[i], +1); if (!cal.checkDate(1919, DECEMBER, 14)) { - error("1919/12/07: roll("+cal.getFieldName(weekFields[i])+", +1)\n" - + cal.getMessage()+" " + cal.toDateTimeString()); + error("1919/12/07: roll(" + Koyomi.getFieldName(weekFields[i]) + ", +1)\n" + + cal.getMessage() + " " + cal.toDateTimeString()); } cal.clear(); - cal.set(1930, JUNE, 21-7); + cal.set(1930, JUNE, 21 - 7); cal.roll(weekFields[i], +1); if (!cal.checkDateTime(1930, JUNE, 21, 01, 00, 00, 000)) { - error("1930/6/14: roll("+cal.getFieldName(weekFields[i])+", +1)\n" - + cal.getMessage()+" " + cal.toDateTimeString()); + error("1930/6/14: roll(" + Koyomi.getFieldName(weekFields[i]) + ", +1)\n" + + cal.getMessage() + " " + cal.toDateTimeString()); } } // Test the day fields - int[] dayFields = { DAY_OF_MONTH, DAY_OF_YEAR, DAY_OF_WEEK }; + int[] dayFields = {DAY_OF_MONTH, DAY_OF_YEAR, DAY_OF_WEEK}; for (int i = 0; i < dayFields.length; i++) { int field = dayFields[i]; // add() cal.clear(); - cal.set(1919, DECEMBER, 14-1, 23, 50, 00); + cal.set(1919, DECEMBER, 14 - 1, 23, 50, 00); cal.add(field, +1); if (!cal.checkDate(1919, DECEMBER, 14)) { - error("1919/12/13: add("+cal.getFieldName(field)+", +1)\n" - + cal.getMessage()+" " + cal.toDateTimeString()); + error("1919/12/13: add(" + Koyomi.getFieldName(field) + ", +1)\n" + + cal.getMessage() + " " + cal.toDateTimeString()); } cal.clear(); cal.set(1919, DECEMBER, 14, 00, 00, 00); cal.add(field, -1); if (!cal.checkDate(1919, DECEMBER, 13)) { - error("1919/12/14: add("+cal.getFieldName(field)+", -1)\n" - + cal.getMessage()+" " + cal.toDateTimeString()); + error("1919/12/14: add(" + Koyomi.getFieldName(field) + ", -1)\n" + + cal.getMessage() + " " + cal.toDateTimeString()); } cal.clear(); - cal.set(1930, JUNE, 21-1); + cal.set(1930, JUNE, 21 - 1); cal.add(field, +1); if (!cal.checkDateTime(1930, JUNE, 21, 01, 00, 00, 000)) { - error("1930/6/20: add("+cal.getFieldName(field)+", +1)\n" - + cal.getMessage() + cal.toDateTimeString()); + error("1930/6/20: add(" + Koyomi.getFieldName(field) + ", +1)\n" + + cal.getMessage() + cal.toDateTimeString()); } cal.clear(); cal.set(1930, JUNE, 21, 01, 00, 00); cal.add(field, -1); if (!cal.checkDateTime(1930, JUNE, 20, 01, 00, 00, 000)) { - error("1930/6/21: add("+cal.getFieldName(field)+", -1)\n" - + cal.getMessage()+" " + cal.toDateTimeString()); + error("1930/6/21: add(" + Koyomi.getFieldName(field) + ", -1)\n" + + cal.getMessage() + " " + cal.toDateTimeString()); } // roll() cal.clear(); - cal.set(1930, JUNE, 21-1); + cal.set(1930, JUNE, 21 - 1); int amount = +1; if (field == DAY_OF_WEEK) { amount += 700; } cal.roll(field, amount); if (!cal.checkDateTime(1930, JUNE, 21, 01, 00, 00, 000)) { - error("1930/6/20: roll("+cal.getFieldName(field)+", +"+amount+")\n" - + cal.getMessage() + " " + cal.toDateTimeString()); + error("1930/6/20: roll(" + Koyomi.getFieldName(field) + ", +" + amount + ")\n" + + cal.getMessage() + " " + cal.toDateTimeString()); } cal.clear(); cal.set(1930, JUNE, 21, 01, 00, 00); @@ -131,93 +133,93 @@ } cal.roll(field, amount); if (!cal.checkDateTime(1930, JUNE, 20, 01, 00, 00, 000)) { - error("1930/6/21: roll("+cal.getFieldName(field)+", "+amount+")\n" - + cal.getMessage()+" "+cal.toDateTimeString()); + error("1930/6/21: roll(" + Koyomi.getFieldName(field) + ", " + amount + ")\n" + + cal.getMessage() + " " + cal.toDateTimeString()); } } // Test the AM_PM field // add() cal.clear(); - cal.set(1919, DECEMBER, 14-1, 23, 50, 00); + cal.set(1919, DECEMBER, 14 - 1, 23, 50, 00); cal.add(AM_PM, +1); if (!cal.checkDate(1919, DECEMBER, 14) - || !cal.checkFieldValue(AM_PM, AM)) { + || !cal.checkFieldValue(AM_PM, AM)) { error("1919/12/13: add(AM_PM, +1)\n" - + cal.getMessage()+" "+cal.toDateTimeString()); + + cal.getMessage() + " " + cal.toDateTimeString()); } cal.clear(); - cal.set(1930, JUNE, 21-1, 12, 00, 00); + cal.set(1930, JUNE, 21 - 1, 12, 00, 00); cal.add(AM_PM, +1); if (!cal.checkDate(1930, JUNE, 21) - || !cal.checkFieldValue(AM_PM, AM)) { + || !cal.checkFieldValue(AM_PM, AM)) { error("1930/6/20: add(AM_PM, +1)\n" - + cal.getMessage()+" "+cal.toDateTimeString()); + + cal.getMessage() + " " + cal.toDateTimeString()); } cal.clear(); - cal.set(1930, JUNE, 21-2, 12, 00, 00); + cal.set(1930, JUNE, 21 - 2, 12, 00, 00); cal.add(AM_PM, +3); if (!cal.checkDate(1930, JUNE, 21) - || !cal.checkFieldValue(AM_PM, AM)) { + || !cal.checkFieldValue(AM_PM, AM)) { error("1930/6/10: add(AM_PM, +3)\n" - + cal.getMessage()+" "+cal.toDateTimeString()); + + cal.getMessage() + " " + cal.toDateTimeString()); } cal.clear(); cal.set(1919, DECEMBER, 14, 11, 50, 00); cal.add(AM_PM, -1); - if (!cal.checkDateTime(1919, DECEMBER, 14-1, 23, 50, 00, 000) - || !cal.checkFieldValue(AM_PM, PM)) { + if (!cal.checkDateTime(1919, DECEMBER, 14 - 1, 23, 50, 00, 000) + || !cal.checkFieldValue(AM_PM, PM)) { error("1919/12/14 11:50:00: add(AM_PM, -1)\n" - + cal.getMessage()+" "+cal.toDateTimeString()); + + cal.getMessage() + " " + cal.toDateTimeString()); } cal.clear(); cal.set(1930, JUNE, 21, 01, 00, 00); cal.add(AM_PM, -1); - if (!cal.checkDateTime(1930, JUNE, 21-1, 01+12, 00, 00, 000) - || !cal.checkFieldValue(AM_PM, PM)) { + if (!cal.checkDateTime(1930, JUNE, 21 - 1, 01 + 12, 00, 00, 000) + || !cal.checkFieldValue(AM_PM, PM)) { error("1930/6/20: add(AM_PM, -1)\n" - + cal.getMessage()+" "+cal.toDateTimeString()); + + cal.getMessage() + " " + cal.toDateTimeString()); } cal.clear(); cal.set(1930, JUNE, 21, 01, 00, 00); cal.add(AM_PM, -3); - if (!cal.checkDateTime(1930, JUNE, 21-2, 01+12, 00, 00, 000) - || !cal.checkFieldValue(AM_PM, PM)) { + if (!cal.checkDateTime(1930, JUNE, 21 - 2, 01 + 12, 00, 00, 000) + || !cal.checkFieldValue(AM_PM, PM)) { error("1930/6/10: add(AM_PM, -3)\n" - + cal.getMessage()+" "+cal.toDateTimeString()); + + cal.getMessage() + " " + cal.toDateTimeString()); } // roll() (should NOT change the date) cal.clear(); - cal.set(1919, DECEMBER, 14-1, 23, 50, 00); + cal.set(1919, DECEMBER, 14 - 1, 23, 50, 00); cal.roll(AM_PM, +1); - if (!cal.checkDateTime(1919, DECEMBER, 14-1, 23-12, 50, 00, 000) - || !cal.checkFieldValue(AM_PM, AM)) { + if (!cal.checkDateTime(1919, DECEMBER, 14 - 1, 23 - 12, 50, 00, 000) + || !cal.checkFieldValue(AM_PM, AM)) { error("1919/12/13: roll(AM_PM, +1)\n" - + cal.getMessage()+" "+cal.toDateTimeString()); + + cal.getMessage() + " " + cal.toDateTimeString()); } cal.clear(); - cal.set(1930, JUNE, 21-1, 12, 00, 00); + cal.set(1930, JUNE, 21 - 1, 12, 00, 00); cal.roll(AM_PM, +1); - if (!cal.checkDateTime(1930, JUNE, 21-1, 12-12, 00, 00, 000) - || !cal.checkFieldValue(AM_PM, AM)) { + if (!cal.checkDateTime(1930, JUNE, 21 - 1, 12 - 12, 00, 00, 000) + || !cal.checkFieldValue(AM_PM, AM)) { error("1930/6/20: roll(AM_PM, +1)\n" - + cal.getMessage()+" "+cal.toDateTimeString()); + + cal.getMessage() + " " + cal.toDateTimeString()); } cal.clear(); - cal.set(1930, JUNE, 21-2, 12, 00, 00); + cal.set(1930, JUNE, 21 - 2, 12, 00, 00); cal.roll(AM_PM, +3); - if (!cal.checkDateTime(1930, JUNE, 21-2, 12-12, 00, 00, 000) - || !cal.checkFieldValue(AM_PM, AM)) { + if (!cal.checkDateTime(1930, JUNE, 21 - 2, 12 - 12, 00, 00, 000) + || !cal.checkFieldValue(AM_PM, AM)) { error("1930/6/10: roll(AM_PM, +3)\n" - + cal.getMessage()+" "+cal.toDateTimeString()); + + cal.getMessage() + " " + cal.toDateTimeString()); } // Test the HOUR_OF_DAY field @@ -227,7 +229,7 @@ cal.add(HOUR_OF_DAY, +1); if (!cal.checkDateTime(1930, JUNE, 21, 01, 00, 00, 000)) { error("1930/6/20 23:00:00: add(HOUR_OF_DAY, +1)\n" - + cal.getMessage()+" "+cal.toDateTimeString()); + + cal.getMessage() + " " + cal.toDateTimeString()); } // roll() (should NOT change the date) @@ -236,7 +238,7 @@ cal.roll(HOUR_OF_DAY, +1); if (!cal.checkDateTime(1930, JUNE, 20, 00, 00, 00, 000)) { error("1930/6/20 23:00:00: roll(HOUR_OF_DAY, +1)\n" - + cal.getMessage()+" "+cal.toDateTimeString()); + + cal.getMessage() + " " + cal.toDateTimeString()); } checkErrors();
--- a/jdk/test/java/util/Calendar/CalendarRegression.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/util/Calendar/CalendarRegression.java Tue Nov 22 11:46:06 2016 -0800 @@ -34,11 +34,24 @@ * @library /java/text/testlib * @run main CalendarRegression */ +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.text.DateFormat; +import java.text.NumberFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.SimpleTimeZone; +import java.util.TimeZone; -import java.lang.reflect.*; -import java.io.*; -import java.util.*; -import java.text.*; +import static java.util.Calendar.*; public class CalendarRegression extends IntlTest { @@ -47,99 +60,101 @@ } /* - Synopsis: java.sql.Timestamp constructor works wrong on Windows 95 + Synopsis: java.sql.Timestamp constructor works wrong on Windows 95 - ==== Here is the test ==== - public static void main (String args[]) { - java.sql.Timestamp t= new java.sql.Timestamp(0,15,5,5,8,13,123456700); - logln("expected=1901-04-05 05:08:13.1234567"); - logln(" result="+t); - } + ==== Here is the test ==== + public static void main (String args[]) { + java.sql.Timestamp t= new java.sql.Timestamp(0,15,5,5,8,13,123456700); + logln("expected=1901-04-05 05:08:13.1234567"); + logln(" result="+t); + } - ==== Here is the output of the test on Solaris or NT ==== - expected=1901-04-05 05:08:13.1234567 - result=1901-04-05 05:08:13.1234567 + ==== Here is the output of the test on Solaris or NT ==== + expected=1901-04-05 05:08:13.1234567 + result=1901-04-05 05:08:13.1234567 - ==== Here is the output of the test on Windows95 ==== - expected=1901-04-05 05:08:13.1234567 - result=1901-04-05 06:08:13.1234567 - */ - + ==== Here is the output of the test on Windows95 ==== + expected=1901-04-05 05:08:13.1234567 + result=1901-04-05 06:08:13.1234567 + */ public void Test4031502() { // This bug actually occurs on Windows NT as well, and doesn't // require the host zone to be set; it can be set in Java. String[] ids = TimeZone.getAvailableIDs(); boolean bad = false; - for (int i=0; i<ids.length; ++i) { + for (int i = 0; i < ids.length; ++i) { TimeZone zone = TimeZone.getTimeZone(ids[i]); GregorianCalendar cal = new GregorianCalendar(zone); cal.clear(); cal.set(1900, 15, 5, 5, 8, 13); - if (cal.get(Calendar.HOUR) != 5) { - logln(zone.getID() + " " + - //zone.useDaylightTime() + " " + - cal.get(Calendar.DST_OFFSET) / (60*60*1000) + " " + - zone.getRawOffset() / (60*60*1000) + - ": HOUR = " + cal.get(Calendar.HOUR)); + if (cal.get(HOUR) != 5) { + logln(zone.getID() + " " + + //zone.useDaylightTime() + " " + + cal.get(DST_OFFSET) / (60 * 60 * 1000) + " " + + zone.getRawOffset() / (60 * 60 * 1000) + + ": HOUR = " + cal.get(HOUR)); bad = true; } } - if (bad) errln("TimeZone problems with GC"); + if (bad) { + errln("TimeZone problems with GC"); + } } public void Test4035301() { GregorianCalendar c = new GregorianCalendar(98, 8, 7); GregorianCalendar d = new GregorianCalendar(98, 8, 7); - if (c.after(d) || - c.after(c) || - c.before(d) || - c.before(c) || - !c.equals(c) || - !c.equals(d)) + if (c.after(d) + || c.after(c) + || c.before(d) + || c.before(c) + || !c.equals(c) + || !c.equals(d)) { errln("Fail"); + } } public void Test4040996() { String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); - pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); - pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); + pdt.setStartRule(APRIL, 1, SUNDAY, 2 * 60 * 60 * 1000); + pdt.setEndRule(OCTOBER, -1, SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); - calendar.set(Calendar.MONTH,3); - calendar.set(Calendar.DAY_OF_MONTH,18); - calendar.set(Calendar.SECOND, 30); + calendar.set(MONTH, 3); + calendar.set(DAY_OF_MONTH, 18); + calendar.set(SECOND, 30); - logln("MONTH: " + calendar.get(Calendar.MONTH)); - logln("DAY_OF_MONTH: " + - calendar.get(Calendar.DAY_OF_MONTH)); - logln("MINUTE: " + calendar.get(Calendar.MINUTE)); - logln("SECOND: " + calendar.get(Calendar.SECOND)); + logln("MONTH: " + calendar.get(MONTH)); + logln("DAY_OF_MONTH: " + + calendar.get(DAY_OF_MONTH)); + logln("MINUTE: " + calendar.get(MINUTE)); + logln("SECOND: " + calendar.get(SECOND)); - calendar.add(Calendar.SECOND,6); + calendar.add(SECOND, 6); //This will print out todays date for MONTH and DAY_OF_MONTH //instead of the date it was set to. //This happens when adding MILLISECOND or MINUTE also - logln("MONTH: " + calendar.get(Calendar.MONTH)); - logln("DAY_OF_MONTH: " + - calendar.get(Calendar.DAY_OF_MONTH)); - logln("MINUTE: " + calendar.get(Calendar.MINUTE)); - logln("SECOND: " + calendar.get(Calendar.SECOND)); - if (calendar.get(Calendar.MONTH) != 3 || - calendar.get(Calendar.DAY_OF_MONTH) != 18 || - calendar.get(Calendar.SECOND) != 36) + logln("MONTH: " + calendar.get(MONTH)); + logln("DAY_OF_MONTH: " + + calendar.get(DAY_OF_MONTH)); + logln("MINUTE: " + calendar.get(MINUTE)); + logln("SECOND: " + calendar.get(SECOND)); + if (calendar.get(MONTH) != 3 + || calendar.get(DAY_OF_MONTH) != 18 + || calendar.get(SECOND) != 36) { errln("Fail: Calendar.add misbehaves"); + } } public void Test4051765() { Calendar cal = Calendar.getInstance(); cal.setLenient(false); - cal.set(Calendar.DAY_OF_WEEK, 0); + cal.set(DAY_OF_WEEK, 0); try { cal.getTime(); errln("Fail: DAY_OF_WEEK 0 should be disallowed"); - } - catch (IllegalArgumentException e) { + } catch (IllegalArgumentException e) { return; } } @@ -200,51 +215,54 @@ logln("DST_OFFSET: " + (calendar.get(calendar.DST_OFFSET)/(60*60*1000))); // in hours } - */ - + */ public void Test4059654() { GregorianCalendar gc = new GregorianCalendar(); gc.set(1997, 3, 1, 15, 16, 17); // April 1, 1997 - gc.set(Calendar.HOUR, 0); - gc.set(Calendar.AM_PM, Calendar.AM); - gc.set(Calendar.MINUTE, 0); - gc.set(Calendar.SECOND, 0); - gc.set(Calendar.MILLISECOND, 0); + gc.set(HOUR, 0); + gc.set(AM_PM, AM); + gc.set(MINUTE, 0); + gc.set(SECOND, 0); + gc.set(MILLISECOND, 0); Date cd = gc.getTime(); + @SuppressWarnings("deprecation") Date exp = new Date(97, 3, 1, 0, 0, 0); - if (!cd.equals(exp)) + if (!cd.equals(exp)) { errln("Fail: Calendar.set broken. Got " + cd + " Want " + exp); + } } public void Test4061476() { SimpleDateFormat fmt = new SimpleDateFormat("ddMMMyy", Locale.UK); Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"), - Locale.UK); + Locale.UK); fmt.setCalendar(cal); - try - { - Date date = fmt.parse("29MAY97"); - cal.setTime(date); - } - catch (Exception e) {;} - cal.set(Calendar.HOUR_OF_DAY, 13); - logln("Hour: "+cal.get(Calendar.HOUR_OF_DAY)); - cal.add(Calendar.HOUR_OF_DAY, 6); - logln("Hour: "+cal.get(Calendar.HOUR_OF_DAY)); - if (cal.get(Calendar.HOUR_OF_DAY) != 19) - errln("Fail: Want 19 Got " + cal.get(Calendar.HOUR_OF_DAY)); + try { + Date date = fmt.parse("29MAY97"); + cal.setTime(date); + } catch (Exception e) { + } + cal.set(HOUR_OF_DAY, 13); + logln("Hour: " + cal.get(HOUR_OF_DAY)); + cal.add(HOUR_OF_DAY, 6); + logln("Hour: " + cal.get(HOUR_OF_DAY)); + if (cal.get(HOUR_OF_DAY) != 19) { + errln("Fail: Want 19 Got " + cal.get(HOUR_OF_DAY)); + } } public void Test4070502() { + @SuppressWarnings("deprecation") Date d = getAssociatedDate(new Date(98, 0, 30)); Calendar cal = new GregorianCalendar(); cal.setTime(d); - if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || - cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) + if (cal.get(DAY_OF_WEEK) == SATURDAY + || cal.get(DAY_OF_WEEK) == SUNDAY) { errln("Fail: Want weekday Got " + d); + } } /** @@ -260,13 +278,13 @@ //cal.add(field, amount); //<-- PROBLEM SEEN WITH field = DATE,MONTH // cal.getTime(); // <--- REMOVE THIS TO SEE BUG while (true) { - int wd = cal.get(Calendar.DAY_OF_WEEK); - if (wd == Calendar.SATURDAY || wd == Calendar.SUNDAY) { - cal.add(Calendar.DATE, 1); + int wd = cal.get(DAY_OF_WEEK); + if (wd == SATURDAY || wd == SUNDAY) { + cal.add(DATE, 1); // cal.getTime(); + } else { + break; } - else - break; } return cal.getTime(); } @@ -278,41 +296,47 @@ void dowTest(boolean lenient) { GregorianCalendar cal = new GregorianCalendar(); - cal.set(1997, Calendar.AUGUST, 12); // Wednesday + cal.set(1997, AUGUST, 12); // Wednesday // cal.getTime(); // Force update cal.setLenient(lenient); - cal.set(1996, Calendar.DECEMBER, 1); // Set the date to be December 1, 1996 - int dow = cal.get(Calendar.DAY_OF_WEEK); - int min = cal.getMinimum(Calendar.DAY_OF_WEEK); - int max = cal.getMaximum(Calendar.DAY_OF_WEEK); + cal.set(1996, DECEMBER, 1); // Set the date to be December 1, 1996 + int dow = cal.get(DAY_OF_WEEK); + int min = cal.getMinimum(DAY_OF_WEEK); + int max = cal.getMaximum(DAY_OF_WEEK); logln(cal.getTime().toString()); - if (min != Calendar.SUNDAY || max != Calendar.SATURDAY) + if (min != SUNDAY || max != SATURDAY) { errln("FAIL: Min/max bad"); - if (dow < min || dow > max) + } + if (dow < min || dow > max) { errln("FAIL: Day of week " + dow + " out of range"); - if (dow != Calendar.SUNDAY) + } + if (dow != SUNDAY) { errln("FAIL: Day of week should be SUNDAY Got " + dow); + } } + @SuppressWarnings("deprecation") public void Test4071385() { Calendar cal = Calendar.getInstance(); - cal.setTime(new Date(98, Calendar.JUNE, 24)); - cal.set(Calendar.MONTH, Calendar.NOVEMBER); // change a field + cal.setTime(new Date(98, JUNE, 24)); + cal.set(MONTH, NOVEMBER); // change a field logln(cal.getTime().toString()); - if (!cal.getTime().equals(new Date(98, Calendar.NOVEMBER, 24))) + if (!cal.getTime().equals(new Date(98, NOVEMBER, 24))) { errln("Fail"); + } } public void Test4073929() { GregorianCalendar foo1 = new GregorianCalendar(1997, 8, 27); - foo1.add(Calendar.DAY_OF_MONTH, +1); - int testyear = foo1.get(Calendar.YEAR); - int testmonth = foo1.get(Calendar.MONTH); - int testday = foo1.get(Calendar.DAY_OF_MONTH); - if (testyear != 1997 || - testmonth != 8 || - testday != 28) + foo1.add(DAY_OF_MONTH, +1); + int testyear = foo1.get(YEAR); + int testmonth = foo1.get(MONTH); + int testday = foo1.get(DAY_OF_MONTH); + if (testyear != 1997 + || testmonth != 8 + || testday != 28) { errln("Fail: Calendar not initialized"); + } } public void Test4083167() { @@ -322,27 +346,26 @@ Date firstDate = new Date(); Calendar cal = new GregorianCalendar(); cal.setTime(firstDate); - long firstMillisInDay = cal.get(Calendar.HOUR_OF_DAY) * 3600000L + - cal.get(Calendar.MINUTE) * 60000L + - cal.get(Calendar.SECOND) * 1000L + - cal.get(Calendar.MILLISECOND); + long firstMillisInDay = cal.get(HOUR_OF_DAY) * 3600000L + + cal.get(MINUTE) * 60000L + + cal.get(SECOND) * 1000L + + cal.get(MILLISECOND); logln("Current time: " + firstDate.toString()); - for (int validity=0; validity<30; validity++) { - Date lastDate = new Date(firstDate.getTime() + - (long)validity*1000*24*60*60); + for (int validity = 0; validity < 30; validity++) { + Date lastDate = new Date(firstDate.getTime() + + (long) validity * 1000 * 24 * 60 * 60); cal.setTime(lastDate); - long millisInDay = cal.get(Calendar.HOUR_OF_DAY) * 3600000L + - cal.get(Calendar.MINUTE) * 60000L + - cal.get(Calendar.SECOND) * 1000L + - cal.get(Calendar.MILLISECOND); + long millisInDay = cal.get(HOUR_OF_DAY) * 3600000L + + cal.get(MINUTE) * 60000L + + cal.get(SECOND) * 1000L + + cal.get(MILLISECOND); if (firstMillisInDay != millisInDay) { errln("Day has shifted " + lastDate); } } - } - finally { + } finally { TimeZone.setDefault(saveZone); } } @@ -359,61 +382,60 @@ TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); date = new SimpleDateFormat("zzzz"); - Calendar cal=Calendar.getInstance(); - cal.set(1997,Calendar.SEPTEMBER,30); - Date now=cal.getTime(); + Calendar cal = Calendar.getInstance(); + cal.set(1997, SEPTEMBER, 30); + Date now = cal.getTime(); String formattedDate = date.format(now); if (!formattedDate.equals(summerTime)) { errln("Wrong display name \"" + formattedDate - + "\" for <" + now + ">"); + + "\" for <" + now + ">"); } - int weekOfYear = cal.get(Calendar.WEEK_OF_YEAR); + int weekOfYear = cal.get(WEEK_OF_YEAR); if (weekOfYear != 40) { errln("Wrong week-of-year " + weekOfYear - + " for <" + now + ">"); + + " for <" + now + ">"); } - cal.set(1996,Calendar.DECEMBER,31); - now=cal.getTime(); + cal.set(1996, DECEMBER, 31); + now = cal.getTime(); formattedDate = date.format(now); if (!formattedDate.equals(standardTime)) { errln("Wrong display name \"" + formattedDate - + "\" for <" + now + ">"); + + "\" for <" + now + ">"); } - weekOfYear = cal.get(Calendar.WEEK_OF_YEAR); + weekOfYear = cal.get(WEEK_OF_YEAR); if (weekOfYear != 1) { errln("Wrong week-of-year " + weekOfYear - + " for <" + now + ">"); + + " for <" + now + ">"); } - cal.set(1997,Calendar.JANUARY,1); - now=cal.getTime(); + cal.set(1997, JANUARY, 1); + now = cal.getTime(); formattedDate = date.format(now); if (!formattedDate.equals(standardTime)) { errln("Wrong display name \"" + formattedDate - + "\" for <" + now + ">"); + + "\" for <" + now + ">"); } - weekOfYear = cal.get(Calendar.WEEK_OF_YEAR); + weekOfYear = cal.get(WEEK_OF_YEAR); if (weekOfYear != 1) { errln("Wrong week-of-year " + weekOfYear - + " for <" + now + ">"); + + " for <" + now + ">"); } - cal.set(1997,Calendar.JANUARY,8); - now=cal.getTime(); + cal.set(1997, JANUARY, 8); + now = cal.getTime(); formattedDate = date.format(now); if (!formattedDate.equals(standardTime)) { errln("Wrong display name \"" + formattedDate - + "\" for <" + now + ">"); + + "\" for <" + now + ">"); } - weekOfYear = cal.get(Calendar.WEEK_OF_YEAR); + weekOfYear = cal.get(WEEK_OF_YEAR); if (weekOfYear != 2) { errln("Wrong week-of-year " + weekOfYear - + " for <" + now + ">"); + + " for <" + now + ">"); } - } - finally { + } finally { Locale.setDefault(saveLocale); TimeZone.setDefault(saveZone); } @@ -428,9 +450,9 @@ cal1.set( Calendar.MINUTE, 20 ); cal1.set( Calendar.SECOND, 40 ); */ - logln( " Cal1 = " + cal1.getTime().getTime() ); - logln( " Cal1 time in ms = " + cal1.get(Calendar.MILLISECOND) ); - for( int k = 0; k < 100 ; k++ ); + logln(" Cal1 = " + cal1.getTime().getTime()); + logln(" Cal1 time in ms = " + cal1.get(MILLISECOND)); + for (int k = 0; k < 100; k++); GregorianCalendar cal2 = new GregorianCalendar(1997, 10, 11, 10, 20, 40); /*cal2.set( Calendar.YEAR, 1997 ); @@ -440,17 +462,19 @@ cal2.set( Calendar.MINUTE, 20 ); cal2.set( Calendar.SECOND, 40 ); */ - logln( " Cal2 = " + cal2.getTime().getTime() ); - logln( " Cal2 time in ms = " + cal2.get(Calendar.MILLISECOND) ); - if( !cal1.equals( cal2 ) ) + logln(" Cal2 = " + cal2.getTime().getTime()); + logln(" Cal2 time in ms = " + cal2.get(MILLISECOND)); + if (!cal1.equals(cal2)) { errln("Fail: Milliseconds randomized"); + } } public void Test4095407() { - GregorianCalendar a = new GregorianCalendar(1997,Calendar.NOVEMBER, 13); - int dow = a.get(Calendar.DAY_OF_WEEK); - if (dow != Calendar.THURSDAY) + GregorianCalendar a = new GregorianCalendar(1997, NOVEMBER, 13); + int dow = a.get(DAY_OF_WEEK); + if (dow != THURSDAY) { errln("Fail: Want THURSDAY Got " + dow); + } } public void Test4096231() { @@ -461,72 +485,74 @@ Calendar cal1 = new GregorianCalendar(PST); cal1.setTime(new Date(880698639000L)); int p; - logln("PST 1 is: " + (p=cal1.get(cal1.HOUR_OF_DAY))); + logln("PST 1 is: " + (p = cal1.get(HOUR_OF_DAY))); cal1.setTimeZone(GMT); // Issue 1: Changing the timezone doesn't change the // represented time. - int h1,h2; - logln("GMT 1 is: " + (h1=cal1.get(cal1.HOUR_OF_DAY))); + int h1, h2; + logln("GMT 1 is: " + (h1 = cal1.get(HOUR_OF_DAY))); cal1.setTime(new Date(880698639000L)); - logln("GMT 2 is: " + (h2=cal1.get(cal1.HOUR_OF_DAY))); + logln("GMT 2 is: " + (h2 = cal1.get(HOUR_OF_DAY))); // Note: This test had a bug in it. It wanted h1!=h2, when // what was meant was h1!=p. Fixed this concurrent with fix // to 4177484. - if (p == h1 || h1 != h2) + if (p == h1 || h1 != h2) { errln("Fail: Hour same in different zones"); + } Calendar cal2 = new GregorianCalendar(GMT); Calendar cal3 = new GregorianCalendar(PST); - cal2.set(Calendar.MILLISECOND, 0); - cal3.set(Calendar.MILLISECOND, 0); + cal2.set(MILLISECOND, 0); + cal3.set(MILLISECOND, 0); - cal2.set(cal1.get(cal1.YEAR), - cal1.get(cal1.MONTH), - cal1.get(cal1.DAY_OF_MONTH), - cal1.get(cal1.HOUR_OF_DAY), - cal1.get(cal1.MINUTE), - cal1.get(cal1.SECOND)); + cal2.set(cal1.get(YEAR), + cal1.get(MONTH), + cal1.get(DAY_OF_MONTH), + cal1.get(HOUR_OF_DAY), + cal1.get(MINUTE), + cal1.get(SECOND)); - long t1,t2,t3,t4; - logln("RGMT 1 is: " + (t1=cal2.getTime().getTime())); + long t1, t2, t3, t4; + logln("RGMT 1 is: " + (t1 = cal2.getTime().getTime())); cal3.set(year, month, day, hr, min, sec); - logln("RPST 1 is: " + (t2=cal3.getTime().getTime())); + logln("RPST 1 is: " + (t2 = cal3.getTime().getTime())); cal3.setTimeZone(GMT); - logln("RGMT 2 is: " + (t3=cal3.getTime().getTime())); - cal3.set(cal1.get(cal1.YEAR), - cal1.get(cal1.MONTH), - cal1.get(cal1.DAY_OF_MONTH), - cal1.get(cal1.HOUR_OF_DAY), - cal1.get(cal1.MINUTE), - cal1.get(cal1.SECOND)); + logln("RGMT 2 is: " + (t3 = cal3.getTime().getTime())); + cal3.set(cal1.get(YEAR), + cal1.get(MONTH), + cal1.get(DAY_OF_MONTH), + cal1.get(HOUR_OF_DAY), + cal1.get(MINUTE), + cal1.get(SECOND)); // Issue 2: Calendar continues to use the timezone in its // constructor for set() conversions, regardless // of calls to setTimeZone() - logln("RGMT 3 is: " + (t4=cal3.getTime().getTime())); - if (t1 == t2 || - t1 != t4 || - t2 != t3) + logln("RGMT 3 is: " + (t4 = cal3.getTime().getTime())); + if (t1 == t2 + || t1 != t4 + || t2 != t3) { errln("Fail: Calendar zone behavior faulty"); + } } public void Test4096539() { - int[] y = {31,28,31,30,31,30,31,31,30,31,30,31}; + int[] y = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + for (int x = 0; x < 12; x++) { + GregorianCalendar gc = new GregorianCalendar(1997, x, y[x]); + int m1, m2; + log((m1 = gc.get(MONTH) + 1) + "/" + + gc.get(DATE) + "/" + gc.get(YEAR) + + " + 1mo = "); - for (int x=0;x<12;x++) { - GregorianCalendar gc = new - GregorianCalendar(1997,x,y[x]); - int m1,m2; - log((m1=gc.get(Calendar.MONTH)+1)+"/"+ - gc.get(Calendar.DATE)+"/"+gc.get(Calendar.YEAR)+ - " + 1mo = "); - - gc.add(Calendar.MONTH, 1); - logln((m2=gc.get(Calendar.MONTH)+1)+"/"+ - gc.get(Calendar.DATE)+"/"+gc.get(Calendar.YEAR) - ); + gc.add(MONTH, 1); + logln((m2 = gc.get(MONTH) + 1) + "/" + + gc.get(DATE) + "/" + gc.get(YEAR) + ); int m = (m1 % 12) + 1; - if (m2 != m) + if (m2 != m) { errln("Fail: Want " + m + " Got " + m2); + } } } @@ -538,13 +564,14 @@ return; } - GregorianCalendar cal = (GregorianCalendar)Calendar.getInstance(); - cal.set(Calendar.YEAR, 1997); - cal.set(Calendar.DAY_OF_YEAR, 1); + GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(); + cal.set(YEAR, 1997); + cal.set(DAY_OF_YEAR, 1); Date d = cal.getTime(); // Should be Jan 1 logln(d.toString()); - if (cal.get(Calendar.DAY_OF_YEAR) != 1) + if (cal.get(DAY_OF_YEAR) != 1) { errln("Fail: DAY_OF_YEAR not set"); + } } public void Test4103271() { @@ -555,28 +582,28 @@ } SimpleDateFormat sdf = new SimpleDateFormat(); - int numYears=40, startYear=1997, numDays=15; + int numYears = 40, startYear = 1997, numDays = 15; String output, testDesc; - GregorianCalendar testCal = (GregorianCalendar)Calendar.getInstance(); + GregorianCalendar testCal = (GregorianCalendar) Calendar.getInstance(); testCal.clear(); sdf.setCalendar(testCal); sdf.applyPattern("d MMM yyyy"); boolean fail = false; - for (int firstDay=1; firstDay<=2; firstDay++) { - for (int minDays=1; minDays<=7; minDays++) { + for (int firstDay = 1; firstDay <= 2; firstDay++) { + for (int minDays = 1; minDays <= 7; minDays++) { testCal.setMinimalDaysInFirstWeek(minDays); testCal.setFirstDayOfWeek(firstDay); testDesc = ("Test" + String.valueOf(firstDay) + String.valueOf(minDays)); - logln(testDesc + " => 1st day of week=" + - String.valueOf(firstDay) + - ", minimum days in first week=" + - String.valueOf(minDays)); - for (int j=startYear; j<=startYear+numYears; j++) { - testCal.set(j,11,25); - for(int i=0; i<numDays; i++) { - testCal.add(Calendar.DATE,1); + logln(testDesc + " => 1st day of week=" + + String.valueOf(firstDay) + + ", minimum days in first week=" + + String.valueOf(minDays)); + for (int j = startYear; j <= startYear + numYears; j++) { + testCal.set(j, 11, 25); + for (int i = 0; i < numDays; i++) { + testCal.add(DATE, 1); String calWOY; - int actWOY = testCal.get(Calendar.WEEK_OF_YEAR); + int actWOY = testCal.get(WEEK_OF_YEAR); if (actWOY < 1 || actWOY > 53) { Date d = testCal.getTime(); calWOY = String.valueOf(actWOY); @@ -592,20 +619,19 @@ int[] DATA = { 3, 52, 52, 52, 52, 52, 52, 52, - 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 4, 52, 52, 52, 52, 52, 52, 52, - 53, 53, 53, 53, 53, 53, 53, - 1, 1, 1, 1, 1, 1, 1, - }; - testCal.setFirstDayOfWeek(Calendar.SUNDAY); - for (int j=0; j<DATA.length; j+=22) { - logln("Minimal days in first week = " + DATA[j] + - " Week starts on Sunday"); + 53, 53, 53, 53, 53, 53, 53, + 1, 1, 1, 1, 1, 1, 1}; + testCal.setFirstDayOfWeek(SUNDAY); + for (int j = 0; j < DATA.length; j += 22) { + logln("Minimal days in first week = " + DATA[j] + + " Week starts on Sunday"); testCal.setMinimalDaysInFirstWeek(DATA[j]); - testCal.set(1997, Calendar.DECEMBER, 21); - for (int i=0; i<21; ++i) { - int woy = testCal.get(Calendar.WEEK_OF_YEAR); + testCal.set(1997, DECEMBER, 21); + for (int i = 0; i < 21; ++i) { + int woy = testCal.get(WEEK_OF_YEAR); log("\t" + testCal.getTime() + " " + woy); if (woy != DATA[j + 1 + i]) { log(" ERROR"); @@ -618,47 +644,47 @@ // get the same answer back. This is a round-trip test. Date save = testCal.getTime(); testCal.clear(); - testCal.set(Calendar.YEAR, DATA[j+1+i] < 25 ? 1998 : 1997); - testCal.set(Calendar.WEEK_OF_YEAR, DATA[j+1+i]); - testCal.set(Calendar.DAY_OF_WEEK, (i%7) + Calendar.SUNDAY); + testCal.set(YEAR, DATA[j + 1 + i] < 25 ? 1998 : 1997); + testCal.set(WEEK_OF_YEAR, DATA[j + 1 + i]); + testCal.set(DAY_OF_WEEK, (i % 7) + SUNDAY); if (!testCal.getTime().equals(save)) { logln(" Parse failed: " + testCal.getTime()); - fail= true; + fail = true; } else { logln(" Passed"); } testCal.setTime(save); - testCal.add(Calendar.DAY_OF_MONTH, 1); + testCal.add(DAY_OF_MONTH, 1); } } // Test field disambiguation with a few special hard-coded cases. // This shouldn't fail if the above cases aren't failing. + @SuppressWarnings("deprecation") Object[] DISAM = { - new Integer(1998), new Integer(1), new Integer(Calendar.SUNDAY), - new Date(97, Calendar.DECEMBER, 28), - new Integer(1998), new Integer(2), new Integer(Calendar.SATURDAY), - new Date(98, Calendar.JANUARY, 10), - new Integer(1998), new Integer(53), new Integer(Calendar.THURSDAY), - new Date(98, Calendar.DECEMBER, 31), - new Integer(1998), new Integer(53), new Integer(Calendar.FRIDAY), - new Date(99, Calendar.JANUARY, 1), - }; + 1998, 1, SUNDAY, + new Date(97, DECEMBER, 28), + 1998, 2, SATURDAY, + new Date(98, JANUARY, 10), + 1998, 53, THURSDAY, + new Date(98, DECEMBER, 31), + 1998, 53, FRIDAY, + new Date(99, JANUARY, 1)}; testCal.setMinimalDaysInFirstWeek(3); - testCal.setFirstDayOfWeek(Calendar.SUNDAY); - for (int i=0; i<DISAM.length; i+=4) { - int y = ((Integer)DISAM[i]).intValue(); - int woy = ((Integer)DISAM[i+1]).intValue(); - int dow = ((Integer)DISAM[i+2]).intValue(); - Date exp = (Date)DISAM[i+3]; + testCal.setFirstDayOfWeek(SUNDAY); + for (int i = 0; i < DISAM.length; i += 4) { + int y = (Integer) DISAM[i]; + int woy = (Integer) DISAM[i + 1]; + int dow = (Integer) DISAM[i + 2]; + Date exp = (Date) DISAM[i + 3]; testCal.clear(); - testCal.set(Calendar.YEAR, y); - testCal.set(Calendar.WEEK_OF_YEAR, woy); - testCal.set(Calendar.DAY_OF_WEEK, dow); + testCal.set(YEAR, y); + testCal.set(WEEK_OF_YEAR, woy); + testCal.set(DAY_OF_WEEK, dow); log(y + "-W" + woy + "-DOW" + dow); if (!testCal.getTime().equals(exp)) { - logln(" FAILED expect: " + exp + "\n got: " +testCal.getTime()); + logln(" FAILED expect: " + exp + "\n got: " + testCal.getTime()); fail = true; } else { logln(" OK"); @@ -668,47 +694,51 @@ // Now try adding and rolling Object ADD = new Object(); Object ROLL = new Object(); + @SuppressWarnings("deprecation") Object[] ADDROLL = { - ADD, new Integer(1), new Date(98, Calendar.DECEMBER, 25), new Date(99, Calendar.JANUARY, 1), - ADD, new Integer(1), new Date(97, Calendar.DECEMBER, 28), new Date(98, Calendar.JANUARY, 4), - ROLL, new Integer(1), new Date(98, Calendar.DECEMBER, 27), new Date(98, Calendar.JANUARY, 4), - ROLL, new Integer(1), new Date(99, Calendar.DECEMBER, 24), new Date(99, Calendar.DECEMBER, 31), - ROLL, new Integer(1), new Date(99, Calendar.DECEMBER, 25), new Date(99, Calendar.JANUARY, 9), - }; + ADD, 1, new Date(98, DECEMBER, 25), new Date(99, JANUARY, 1), + ADD, 1, new Date(97, DECEMBER, 28), new Date(98, JANUARY, 4), + ROLL, 1, new Date(98, DECEMBER, 27), new Date(98, JANUARY, 4), + ROLL, 1, new Date(99, DECEMBER, 24), new Date(99, DECEMBER, 31), + ROLL, 1, new Date(99, DECEMBER, 25), new Date(99, JANUARY, 9)}; testCal.setMinimalDaysInFirstWeek(3); - testCal.setFirstDayOfWeek(Calendar.SUNDAY); - for (int i=0; i<ADDROLL.length; i+=4) { - int amount = ((Integer)ADDROLL[i+1]).intValue(); - Date before = (Date)ADDROLL[i+2]; - Date after = (Date)ADDROLL[i+3]; + testCal.setFirstDayOfWeek(SUNDAY); + for (int i = 0; i < ADDROLL.length; i += 4) { + int amount = (Integer) ADDROLL[i + 1]; + Date before = (Date) ADDROLL[i + 2]; + Date after = (Date) ADDROLL[i + 3]; testCal.setTime(before); - if (ADDROLL[i] == ADD) - testCal.add(Calendar.WEEK_OF_YEAR, amount); - else - testCal.roll(Calendar.WEEK_OF_YEAR, amount); - log((ADDROLL[i]==ADD ? "add(WOY," : "roll(WOY,") + - amount + ")\t " + before + - "\n\t\t => " + testCal.getTime()); + if (ADDROLL[i] == ADD) { + testCal.add(WEEK_OF_YEAR, amount); + } else { + testCal.roll(WEEK_OF_YEAR, amount); + } + log((ADDROLL[i] == ADD ? "add(WOY," : "roll(WOY,") + + amount + ")\t " + before + + "\n\t\t => " + testCal.getTime()); if (!after.equals(testCal.getTime())) { logln("\tFAIL\n\t\texp: " + after); fail = true; - } else + } else { logln(" OK"); + } testCal.setTime(after); - if (ADDROLL[i] == ADD) - testCal.add(Calendar.WEEK_OF_YEAR, -amount); - else - testCal.roll(Calendar.WEEK_OF_YEAR, -amount); - log((ADDROLL[i]==ADD ? "add(WOY," : "roll(WOY,") + - (-amount) + ") " + after + - "\n\t\t => " + testCal.getTime()); + if (ADDROLL[i] == ADD) { + testCal.add(WEEK_OF_YEAR, -amount); + } else { + testCal.roll(WEEK_OF_YEAR, -amount); + } + log((ADDROLL[i] == ADD ? "add(WOY," : "roll(WOY,") + + (-amount) + ") " + after + + "\n\t\t => " + testCal.getTime()); if (!before.equals(testCal.getTime())) { logln("\tFAIL\n\t\texp: " + before); fail = true; + } else { + logln("\tOK"); } - else logln("\tOK"); } if (fail) { @@ -719,63 +749,68 @@ public void Test4106136() { Locale saveLocale = Locale.getDefault(); try { - Locale[] locales = { Locale.CHINESE, Locale.CHINA }; - for (int i=0; i<locales.length; ++i) { + Locale[] locales = {Locale.CHINESE, Locale.CHINA}; + for (int i = 0; i < locales.length; ++i) { Locale.setDefault(locales[i]); int[] n = { - Calendar.getAvailableLocales().length, + getAvailableLocales().length, DateFormat.getAvailableLocales().length, - NumberFormat.getAvailableLocales().length - }; - for (int j=0; j<n.length; ++j) { + NumberFormat.getAvailableLocales().length}; + for (int j = 0; j < n.length; ++j) { if (n[j] == 0) { errln("Fail: No locales for " + locales[i]); } } } - } - finally { + } finally { Locale.setDefault(saveLocale); } } + @SuppressWarnings("deprecation") public void Test4108764() { - Date d00 = new Date(97, Calendar.MARCH, 15, 12, 00, 00); - Date d01 = new Date(97, Calendar.MARCH, 15, 12, 00, 56); - Date d10 = new Date(97, Calendar.MARCH, 15, 12, 34, 00); - Date d11 = new Date(97, Calendar.MARCH, 15, 12, 34, 56); - Date epoch = new Date(70, Calendar.JANUARY, 1); + Date d00 = new Date(97, MARCH, 15, 12, 00, 00); + Date d01 = new Date(97, MARCH, 15, 12, 00, 56); + Date d10 = new Date(97, MARCH, 15, 12, 34, 00); + Date d11 = new Date(97, MARCH, 15, 12, 34, 56); + Date epoch = new Date(70, JANUARY, 1); Calendar cal = Calendar.getInstance(); cal.setTime(d11); - cal.clear( Calendar.MINUTE ); + cal.clear(MINUTE); logln(cal.getTime().toString()); - if (!cal.getTime().equals(d01)) + if (!cal.getTime().equals(d01)) { errln("Fail: clear(MINUTE) broken"); + } - cal.set( Calendar.SECOND, 0 ); + cal.set(SECOND, 0); logln(cal.getTime().toString()); - if (!cal.getTime().equals(d00)) + if (!cal.getTime().equals(d00)) { errln("Fail: set(SECOND, 0) broken"); + } cal.setTime(d11); - cal.set( Calendar.SECOND, 0 ); + cal.set(SECOND, 0); logln(cal.getTime().toString()); - if (!cal.getTime().equals(d10)) + if (!cal.getTime().equals(d10)) { errln("Fail: set(SECOND, 0) broken #2"); + } - cal.clear( Calendar.MINUTE ); + cal.clear(MINUTE); logln(cal.getTime().toString()); - if (!cal.getTime().equals(d00)) + if (!cal.getTime().equals(d00)) { errln("Fail: clear(MINUTE) broken #2"); + } cal.clear(); logln(cal.getTime().toString()); - if (!cal.getTime().equals(epoch)) + if (!cal.getTime().equals(epoch)) { errln("Fail: clear() broken Want " + epoch); + } } + @SuppressWarnings("deprecation") public void Test4114578() { Locale locale = Locale.getDefault(); if (!TestUtils.usesGregorianCalendar(locale)) { @@ -783,14 +818,14 @@ return; } - int ONE_HOUR = 60*60*1000; + int ONE_HOUR = 60 * 60 * 1000; TimeZone saveZone = TimeZone.getDefault(); boolean fail = false; try { TimeZone.setDefault(TimeZone.getTimeZone("PST")); Calendar cal = Calendar.getInstance(); - long onset = new Date(98, Calendar.APRIL, 5, 1, 0).getTime() + ONE_HOUR; - long cease = new Date(98, Calendar.OCTOBER, 25, 0, 0).getTime() + 2*ONE_HOUR; + long onset = new Date(98, APRIL, 5, 1, 0).getTime() + ONE_HOUR; + long cease = new Date(98, OCTOBER, 25, 0, 0).getTime() + 2 * ONE_HOUR; final int ADD = 1; final int ROLL = 2; @@ -807,26 +842,25 @@ // time value may jump 2 hours by skipping non-existent wall-clock time. // Note that JDK-4114578 was a problem of add(), not roll(). cease - ONE_HOUR, ROLL, 1, ONE_HOUR * 2, - cease, ROLL, -1, -ONE_HOUR * 2, - }; + cease, ROLL, -1, -ONE_HOUR * 2}; - for (int i=0; i<DATA.length; i+=4) { + for (int i = 0; i < DATA.length; i += 4) { Date date = new Date(DATA[i]); - int amt = (int) DATA[i+2]; - long expectedChange = DATA[i+3]; + int amt = (int) DATA[i + 2]; + long expectedChange = DATA[i + 3]; log(date.toString()); cal.setTime(date); - switch ((int) DATA[i+1]) { - case ADD: - log(" add (HOUR," + (amt<0?"":"+")+amt + ")= "); - cal.add(Calendar.HOUR, amt); - break; - case ROLL: - log(" roll(HOUR," + (amt<0?"":"+")+amt + ")= "); - cal.roll(Calendar.HOUR, amt); - break; + switch ((int) DATA[i + 1]) { + case ADD: + log(" add (HOUR," + (amt < 0 ? "" : "+") + amt + ")= "); + cal.add(HOUR, amt); + break; + case ROLL: + log(" roll(HOUR," + (amt < 0 ? "" : "+") + amt + ")= "); + cal.roll(HOUR, amt); + break; } log(cal.getTime().toString()); @@ -835,8 +869,9 @@ if (change != expectedChange) { fail = true; logln(" FAIL"); + } else { + logln(" OK"); } - else logln(" OK"); } } finally { TimeZone.setDefault(saveZone); @@ -852,10 +887,11 @@ */ public void Test4118384() { Calendar cal = Calendar.getInstance(); - if (cal.getMaximum(Calendar.HOUR) != 11 || - cal.getLeastMaximum(Calendar.HOUR) != 11 || - cal.getActualMaximum(Calendar.HOUR) != 11) + if (cal.getMaximum(HOUR) != 11 + || cal.getLeastMaximum(HOUR) != 11 + || cal.getActualMaximum(HOUR) != 11) { errln("Fail: maximum of HOUR field should be 11"); + } } /** @@ -871,13 +907,14 @@ GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(); DateFormat fmt = new SimpleDateFormat("MMMM d, yyyy G"); cal.clear(); - for (int y=-20; y<=10; ++y) { - cal.set(Calendar.ERA, y < 1 ? GregorianCalendar.BC : GregorianCalendar.AD); - cal.set(Calendar.YEAR, y < 1 ? 1 - y : y); - logln(y + " = " + fmt.format(cal.getTime()) + " " + - cal.isLeapYear(y)); - if (cal.isLeapYear(y) != ((y+40)%4 == 0)) + for (int y = -20; y <= 10; ++y) { + cal.set(ERA, y < 1 ? GregorianCalendar.BC : GregorianCalendar.AD); + cal.set(YEAR, y < 1 ? 1 - y : y); + logln(y + " = " + fmt.format(cal.getTime()) + " " + + cal.isLeapYear(y)); + if (cal.isLeapYear(y) != ((y + 40) % 4 == 0)) { errln("Leap years broken"); + } } } @@ -895,14 +932,15 @@ GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(); DateFormat fmt = new SimpleDateFormat("MMMM d, yyyy G"); cal.clear(); - cal.set(Calendar.ERA, GregorianCalendar.BC); - cal.set(Calendar.YEAR, 81); // 81 BC is a leap year (proleptically) - cal.set(Calendar.MONTH, Calendar.FEBRUARY); - cal.set(Calendar.DATE, 28); - cal.add(Calendar.DATE, 1); - if (cal.get(Calendar.DATE) != 29 || - !cal.isLeapYear(-80)) // -80 == 81 BC + cal.set(ERA, GregorianCalendar.BC); + cal.set(YEAR, 81); // 81 BC is a leap year (proleptically) + cal.set(MONTH, FEBRUARY); + cal.set(DATE, 28); + cal.add(DATE, 1); + if (cal.get(DATE) != 29 + || !cal.isLeapYear(-80)) { // -80 == 81 BC errln("Calendar not proleptic"); + } } /** @@ -912,16 +950,16 @@ */ public void Test4136399() { /* Note: This test is actually more strict than it has to be. - * Technically, there is no requirement that unequal objects have - * unequal hashes. We only require equal objects to have equal hashes. - * It is desirable for unequal objects to have distributed hashes, but - * there is no hard requirement here. - * - * In this test we make assumptions about certain attributes of calendar - * objects getting represented in the hash, which need not always be the - * case (although it does work currently with the given test). */ + * Technically, there is no requirement that unequal objects have + * unequal hashes. We only require equal objects to have equal hashes. + * It is desirable for unequal objects to have distributed hashes, but + * there is no hard requirement here. + * + * In this test we make assumptions about certain attributes of calendar + * objects getting represented in the hash, which need not always be the + * case (although it does work currently with the given test). */ Calendar a = Calendar.getInstance(); - Calendar b = (Calendar)a.clone(); + Calendar b = (Calendar) a.clone(); if (a.hashCode() != b.hashCode()) { errln("Calendar hash code unequal for cloned objects"); } @@ -946,19 +984,19 @@ // Assume getTimeZone() returns a reference, not a clone // of a reference -- this is true as of this writing - b.getTimeZone().setRawOffset(a.getTimeZone().getRawOffset() + 60*60*1000); + b.getTimeZone().setRawOffset(a.getTimeZone().getRawOffset() + 60 * 60 * 1000); if (a.hashCode() == b.hashCode()) { errln("Calendar hash code ignores zone"); } b.getTimeZone().setRawOffset(a.getTimeZone().getRawOffset()); GregorianCalendar c = new GregorianCalendar(); - GregorianCalendar d = (GregorianCalendar)c.clone(); + GregorianCalendar d = (GregorianCalendar) c.clone(); if (c.hashCode() != d.hashCode()) { errln("GregorianCalendar hash code unequal for clones objects"); } Date cutover = c.getGregorianChange(); - d.setGregorianChange(new Date(cutover.getTime() + 24*60*60*1000)); + d.setGregorianChange(new Date(cutover.getTime() + 24 * 60 * 60 * 1000)); if (c.hashCode() == d.hashCode()) { errln("GregorianCalendar hash code ignores cutover"); } @@ -969,9 +1007,9 @@ */ public void Test4141665() { GregorianCalendar cal = new GregorianCalendar(); - GregorianCalendar cal2 = (GregorianCalendar)cal.clone(); + GregorianCalendar cal2 = (GregorianCalendar) cal.clone(); Date cut = cal.getGregorianChange(); - Date cut2 = new Date(cut.getTime() + 100*24*60*60*1000L); // 100 days later + Date cut2 = new Date(cut.getTime() + 100 * 24 * 60 * 60 * 1000L); // 100 days later if (!cal.equals(cal2)) { errln("Cloned GregorianCalendars not equal"); } @@ -990,12 +1028,10 @@ try { calendar.roll(-1, true); errln("Test failed, no exception trown"); - } - catch (IllegalArgumentException e) { + } catch (IllegalArgumentException e) { // OK: Do nothing // logln("Test passed"); - } - catch (Exception e) { + } catch (Exception e) { errln("Test failed. Unexpected exception is thrown: " + e); e.printStackTrace(); } @@ -1014,12 +1050,12 @@ calendar.setTimeZone(TimeZone.getTimeZone("GMT")); calendar.setTime(new Date(Long.MIN_VALUE)); - int year1 = calendar.get(Calendar.YEAR); - int era1 = calendar.get(Calendar.ERA); + int year1 = calendar.get(YEAR); + int era1 = calendar.get(ERA); calendar.setTime(new Date(Long.MAX_VALUE)); - int year2 = calendar.get(Calendar.YEAR); - int era2 = calendar.get(Calendar.ERA); + int year2 = calendar.get(YEAR); + int era2 = calendar.get(ERA); if (year1 == year2 && era1 == era2) { errln("Fail: Long.MIN_VALUE or Long.MAX_VALUE wrapping around"); @@ -1032,14 +1068,14 @@ public void Test4145983() { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); - Date[] DATES = { new Date(Long.MAX_VALUE), new Date(Long.MIN_VALUE) }; - for (int i=0; i<DATES.length; ++i) { + Date[] DATES = {new Date(Long.MAX_VALUE), new Date(Long.MIN_VALUE)}; + for (int i = 0; i < DATES.length; ++i) { calendar.setTime(DATES[i]); - int year = calendar.get(Calendar.YEAR); - int maxYear = calendar.getMaximum(Calendar.YEAR); + int year = calendar.get(YEAR); + int maxYear = calendar.getMaximum(YEAR); if (year > maxYear) { - errln("Failed for "+DATES[i].getTime()+" ms: year=" + - year + ", maxYear=" + maxYear); + errln("Failed for " + DATES[i].getTime() + " ms: year=" + + year + ", maxYear=" + maxYear); } } } @@ -1068,28 +1104,29 @@ "SECOND", "MILLISECOND", "ZONE_OFFSET", - "DST_OFFSET" - }; + "DST_OFFSET"}; GregorianCalendar calendar = new GregorianCalendar(); calendar.setLenient(false); - Date date = new Date(1996-1900, Calendar.JANUARY, 3); // Arbitrary date - for (int field = 0; field < Calendar.FIELD_COUNT; field++) { + @SuppressWarnings("deprecation") + Date date = new Date(1996 - 1900, JANUARY, 3); // Arbitrary date + for (int field = 0; field < FIELD_COUNT; field++) { calendar.setTime(date); // Note: In the bug report, getActualMaximum() was called instead // of getMaximum() -- this was an error. The validation code doesn't // use getActualMaximum(), since that's too costly. int max = calendar.getMaximum(field); - int value = max+1; + int value = max + 1; calendar.set(field, value); try { calendar.getTime(); // Force time computation // We expect an exception to be thrown. If we fall through // to the next line, then we have a bug. - errln("Test failed with field " + fieldName[field] + - ", date before: " + date + - ", date after: " + calendar.getTime() + - ", value: " + value + " (max = " + max +")"); - } catch (IllegalArgumentException e) {} + errln("Test failed with field " + fieldName[field] + + ", date before: " + date + + ", date after: " + calendar.getTime() + + ", value: " + value + " (max = " + max + ")"); + } catch (IllegalArgumentException e) { + } } } @@ -1099,19 +1136,19 @@ * CANNOT REPRODUCE THIS BUG */ public void Test4149677() { - TimeZone[] zones = { TimeZone.getTimeZone("GMT"), - TimeZone.getTimeZone("PST"), - TimeZone.getTimeZone("EAT") }; - for (int i=0; i<zones.length; ++i) { + TimeZone[] zones = {TimeZone.getTimeZone("GMT"), + TimeZone.getTimeZone("PST"), + TimeZone.getTimeZone("EAT")}; + for (int i = 0; i < zones.length; ++i) { GregorianCalendar calendar = new GregorianCalendar(zones[i]); // Make sure extreme values don't wrap around calendar.setTime(new Date(Long.MIN_VALUE)); - if (calendar.get(Calendar.ERA) != GregorianCalendar.BC) { + if (calendar.get(ERA) != GregorianCalendar.BC) { errln("Fail: Date(Long.MIN_VALUE) has an AD year in " + zones[i]); } calendar.setTime(new Date(Long.MAX_VALUE)); - if (calendar.get(Calendar.ERA) != GregorianCalendar.AD) { + if (calendar.get(ERA) != GregorianCalendar.AD) { errln("Fail: Date(Long.MAX_VALUE) has a BC year in " + zones[i]); } @@ -1139,23 +1176,25 @@ Date d; try { - for (int i=0; i<5; ++i) { - if (i>0) logln("---"); + for (int i = 0; i < 5; ++i) { + if (i > 0) { + logln("---"); + } cal.clear(); - cal.set(1998, Calendar.APRIL, 5, i, 0); + cal.set(1998, APRIL, 5, i, 0); d = cal.getTime(); String s0 = d.toString(); logln("0 " + i + ": " + s0); cal.clear(); - cal.set(1998, Calendar.APRIL, 4, i+24, 0); + cal.set(1998, APRIL, 4, i + 24, 0); d = cal.getTime(); String sPlus = d.toString(); logln("+ " + i + ": " + sPlus); cal.clear(); - cal.set(1998, Calendar.APRIL, 6, i-24, 0); + cal.set(1998, APRIL, 6, i - 24, 0); d = cal.getTime(); String sMinus = d.toString(); logln("- " + i + ": " + sMinus); @@ -1164,8 +1203,7 @@ errln("Fail: All three lines must match"); } } - } - finally { + } finally { TimeZone.setDefault(savedTz); } } @@ -1174,14 +1212,14 @@ * Adding 12 months behaves differently from adding 1 year */ public void Test4165343() { - GregorianCalendar calendar = new GregorianCalendar(1996, Calendar.FEBRUARY, 29); + GregorianCalendar calendar = new GregorianCalendar(1996, FEBRUARY, 29); Date start = calendar.getTime(); logln("init date: " + start); - calendar.add(Calendar.MONTH, 12); + calendar.add(MONTH, 12); Date date1 = calendar.getTime(); logln("after adding 12 months: " + date1); calendar.setTime(start); - calendar.add(Calendar.YEAR, 1); + calendar.add(YEAR, 1); Date date2 = calendar.getTime(); logln("after adding one year : " + date2); if (date1.equals(date2)) { @@ -1196,34 +1234,34 @@ */ public void Test4166109() { /* Test month: - * - * March 1998 - * Su Mo Tu We Th Fr Sa - * 1 2 3 4 5 6 7 - * 8 9 10 11 12 13 14 - * 15 16 17 18 19 20 21 - * 22 23 24 25 26 27 28 - * 29 30 31 + * + * March 1998 + * Su Mo Tu We Th Fr Sa + * 1 2 3 4 5 6 7 + * 8 9 10 11 12 13 14 + * 15 16 17 18 19 20 21 + * 22 23 24 25 26 27 28 + * 29 30 31 */ boolean passed = true; - int field = Calendar.WEEK_OF_MONTH; + int field = WEEK_OF_MONTH; GregorianCalendar calendar = new GregorianCalendar(Locale.US); - calendar.set(1998, Calendar.MARCH, 1); + calendar.set(1998, MARCH, 1); calendar.setMinimalDaysInFirstWeek(1); logln("Date: " + calendar.getTime()); - int firstInMonth = calendar.get(Calendar.DAY_OF_MONTH); + int firstInMonth = calendar.get(DAY_OF_MONTH); - for (int firstInWeek = Calendar.SUNDAY; firstInWeek <= Calendar.SATURDAY; firstInWeek++) { + for (int firstInWeek = SUNDAY; firstInWeek <= SATURDAY; firstInWeek++) { calendar.setFirstDayOfWeek(firstInWeek); int returned = calendar.getActualMaximum(field); - int expected = (31 + ((firstInMonth - firstInWeek + 7)% 7) + 6) / 7; + int expected = (31 + ((firstInMonth - firstInWeek + 7) % 7) + 6) / 7; - logln("First day of week = " + firstInWeek + - " getActualMaximum(WEEK_OF_MONTH) = " + returned + - " expected = " + expected + - ((returned == expected) ? " ok" : " FAIL")); + logln("First day of week = " + firstInWeek + + " getActualMaximum(WEEK_OF_MONTH) = " + returned + + " expected = " + expected + + ((returned == expected) ? " ok" : " FAIL")); if (returned != expected) { passed = false; @@ -1242,19 +1280,19 @@ * changed. See 4928615. */ public void Test4167060() { - int field = Calendar.YEAR; + int field = YEAR; DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy G", - Locale.US); + Locale.US); int[][] dates = { // year, month, day of month - { 100, Calendar.NOVEMBER, 1 }, - { -99 /*100BC*/, Calendar.JANUARY, 1 }, - { 1996, Calendar.FEBRUARY, 29 }}; + {100, NOVEMBER, 1}, + {-99 /*100BC*/, JANUARY, 1}, + {1996, FEBRUARY, 29}}; - String[] id = { "Hybrid", "Gregorian", "Julian" }; + String[] id = {"Hybrid", "Gregorian", "Julian"}; - for (int k=0; k<3; ++k) { + for (int k = 0; k < 3; ++k) { logln("--- " + id[k] + " ---"); for (int j = 0; j < dates.length; ++j) { @@ -1265,7 +1303,7 @@ calendar.setGregorianChange(new Date(Long.MAX_VALUE)); } calendar.set(dates[j][0], dates[j][1], dates[j][2]); - format.setCalendar((Calendar)calendar.clone()); + format.setCalendar((Calendar) calendar.clone()); Date dateBefore = calendar.getTime(); @@ -1273,7 +1311,7 @@ logln("maxYear: " + maxYear + " for " + format.format(calendar.getTime())); logln("date before: " + format.format(dateBefore)); - int years[] = {2000, maxYear-1, maxYear, maxYear+1}; + int[] years = {2000, maxYear - 1, maxYear, maxYear + 1}; for (int i = 0; i < years.length; i++) { boolean valid = years[i] <= maxYear; @@ -1282,8 +1320,8 @@ int newYear = calendar.get(field); calendar.setTime(dateBefore); // restore calendar for next use - logln(" Year " + years[i] + (valid? " ok " : " bad") + - " => " + format.format(dateAfter)); + logln(" Year " + years[i] + (valid ? " ok " : " bad") + + " => " + format.format(dateAfter)); if (valid && newYear != years[i]) { errln(" FAIL: " + newYear + " should be valid; date, month and time shouldn't change"); } else if (!valid && newYear == years[i]) { @@ -1305,18 +1343,16 @@ return; } - int fieldsList[][] = { - { 1997, Calendar.FEBRUARY, 1, 10, 45, 15, 900 }, - { 1999, Calendar.DECEMBER, 22, 23, 59, 59, 999 }, + int[][] fieldsList = { + {1997, FEBRUARY, 1, 10, 45, 15, 900}, + {1999, DECEMBER, 22, 23, 59, 59, 999}, // test case for 4960642 with default cutover - { 1582, Calendar.OCTOBER, 4, 23, 59, 59, 999 }, - }; + {1582, OCTOBER, 4, 23, 59, 59, 999}}; String[] fieldNames = { "ERA", "YEAR", "MONTH", "WEEK_OF_YEAR", "WEEK_OF_MONTH", "DAY_OF_MONTH", "DAY_OF_YEAR", "DAY_OF_WEEK", "DAY_OF_WEEK_IN_MONTH", "AM_PM", "HOUR", "HOUR_OF_DAY", "MINUTE", "SECOND", "MILLISECOND", - "ZONE_OFFSET", "DST_OFFSET" - }; + "ZONE_OFFSET", "DST_OFFSET"}; Locale savedLocale = Locale.getDefault(); Locale.setDefault(Locale.US); @@ -1326,25 +1362,25 @@ GregorianCalendar cal = new GregorianCalendar(); cal.setTime(new Date(0)); - cal.roll(Calendar.HOUR, 0x7F000000); - cal.roll(Calendar.HOUR, -0x7F000000); + cal.roll(HOUR, 0x7F000000); + cal.roll(HOUR, -0x7F000000); if (cal.getTime().getTime() != 0) { - errln("Hour rolling broken. expected 0, got "+cal.getTime().getTime()); + errln("Hour rolling broken. expected 0, got " + cal.getTime().getTime()); } - for (int op=0; op<2; ++op) { - logln("Testing GregorianCalendar " + (op==0 ? "add" : "roll")); + for (int op = 0; op < 2; ++op) { + logln("Testing GregorianCalendar " + (op == 0 ? "add" : "roll")); - for (int field=0; field < Calendar.FIELD_COUNT; ++field) { - if (field != Calendar.ZONE_OFFSET && - field != Calendar.DST_OFFSET) { - for (int j=0; j<fieldsList.length; ++j) { - int fields[] = fieldsList[j]; + for (int field = 0; field < FIELD_COUNT; ++field) { + if (field != ZONE_OFFSET + && field != DST_OFFSET) { + for (int j = 0; j < fieldsList.length; ++j) { + int[] fields = fieldsList[j]; cal.clear(); cal.set(fields[0], fields[1], fields[2], fields[3], fields[4], fields[5]); - cal.set(Calendar.MILLISECOND, fields[6]); - for (int i = 0; i < 2*limit; i++) { + cal.set(MILLISECOND, fields[6]); + for (int i = 0; i < 2 * limit; i++) { if (op == 0) { cal.add(field, i < limit ? 1 : -1); } else { @@ -1352,45 +1388,45 @@ } } - if (cal.get(Calendar.YEAR) != fields[0] || - cal.get(Calendar.MONTH) != fields[1] || - cal.get(Calendar.DATE) != fields[2] || - cal.get(Calendar.HOUR_OF_DAY) != fields[3] || - cal.get(Calendar.MINUTE) != fields[4] || - cal.get(Calendar.SECOND) != fields[5] || - cal.get(Calendar.MILLISECOND) != fields[6]) { - errln("Field " + field + - " (" + fieldNames[field] + - ") FAIL, expected " + - fields[0] + - "/" + (fields[1] + 1) + - "/" + fields[2] + - " " + fields[3] + - ":" + fields[4] + - ":" + fields[5] + - "." + fields[6] + - ", got " + cal.get(Calendar.YEAR) + - "/" + (cal.get(Calendar.MONTH) + 1) + - "/" + cal.get(Calendar.DATE) + - " " + cal.get(Calendar.HOUR_OF_DAY) + - ":" + cal.get(Calendar.MINUTE) + - ":" + cal.get(Calendar.SECOND) + - "." + cal.get(Calendar.MILLISECOND)); + if (cal.get(YEAR) != fields[0] + || cal.get(MONTH) != fields[1] + || cal.get(DATE) != fields[2] + || cal.get(HOUR_OF_DAY) != fields[3] + || cal.get(MINUTE) != fields[4] + || cal.get(SECOND) != fields[5] + || cal.get(MILLISECOND) != fields[6]) { + errln("Field " + field + + " (" + fieldNames[field] + + ") FAIL, expected " + + fields[0] + + "/" + (fields[1] + 1) + + "/" + fields[2] + + " " + fields[3] + + ":" + fields[4] + + ":" + fields[5] + + "." + fields[6] + + ", got " + cal.get(YEAR) + + "/" + (cal.get(MONTH) + 1) + + "/" + cal.get(DATE) + + " " + cal.get(HOUR_OF_DAY) + + ":" + cal.get(MINUTE) + + ":" + cal.get(SECOND) + + "." + cal.get(MILLISECOND)); cal.clear(); cal.set(fields[0], fields[1], fields[2], fields[3], fields[4], fields[5]); - cal.set(Calendar.MILLISECOND, fields[6]); - errln(cal.get(Calendar.YEAR) + - "/" + (cal.get(Calendar.MONTH) + 1) + - "/" + cal.get(Calendar.DATE) + - " " + cal.get(Calendar.HOUR_OF_DAY) + - ":" + cal.get(Calendar.MINUTE) + - ":" + cal.get(Calendar.SECOND) + - "." + cal.get(Calendar.MILLISECOND)); + cal.set(MILLISECOND, fields[6]); + errln(cal.get(YEAR) + + "/" + (cal.get(MONTH) + 1) + + "/" + cal.get(DATE) + + " " + cal.get(HOUR_OF_DAY) + + ":" + cal.get(MINUTE) + + ":" + cal.get(SECOND) + + "." + cal.get(MILLISECOND)); long prev = cal.getTime().getTime(); - for (int i = 0; i < 2*limit; i++) { + for (int i = 0; i < 2 * limit; i++) { if (op == 0) { cal.add(field, i < limit ? 1 : -1); } else { @@ -1399,25 +1435,24 @@ long t = cal.getTime().getTime(); long delta = t - prev; prev = t; - errln((op == 0 ? "add(" : "roll(") + - fieldNames[field] + ", " + - (i < limit ? "+" : "-") + "1) => " + - cal.get(Calendar.YEAR) + - "/" + (cal.get(Calendar.MONTH) + 1) + - "/" + cal.get(Calendar.DATE) + - " " + cal.get(Calendar.HOUR_OF_DAY) + - ":" + cal.get(Calendar.MINUTE) + - ":" + cal.get(Calendar.SECOND) + - "." + cal.get(Calendar.MILLISECOND) + - " d=" + delta); + errln((op == 0 ? "add(" : "roll(") + + fieldNames[field] + ", " + + (i < limit ? "+" : "-") + "1) => " + + cal.get(YEAR) + + "/" + (cal.get(MONTH) + 1) + + "/" + cal.get(DATE) + + " " + cal.get(HOUR_OF_DAY) + + ":" + cal.get(MINUTE) + + ":" + cal.get(SECOND) + + "." + cal.get(MILLISECOND) + + " d=" + delta); } } } } } } - } - finally { + } finally { Locale.setDefault(savedLocale); } } @@ -1425,14 +1460,14 @@ public void Test4174361() { GregorianCalendar calendar = new GregorianCalendar(1996, 1, 29); - calendar.add(Calendar.MONTH, 10); + calendar.add(MONTH, 10); Date date1 = calendar.getTime(); - int d1 = calendar.get(Calendar.DAY_OF_MONTH); + int d1 = calendar.get(DAY_OF_MONTH); calendar = new GregorianCalendar(1996, 1, 29); - calendar.add(Calendar.MONTH, 11); + calendar.add(MONTH, 11); Date date2 = calendar.getTime(); - int d2 = calendar.get(Calendar.DAY_OF_MONTH); + int d2 = calendar.get(DAY_OF_MONTH); if (d1 != d2) { errln("adding months to Feb 29 broken"); @@ -1449,9 +1484,9 @@ Calendar cal = Calendar.getInstance(PST, Locale.US); cal.clear(); cal.set(1999, 3, 21, 15, 5, 0); // Arbitrary - int h1 = cal.get(Calendar.HOUR_OF_DAY); + int h1 = cal.get(HOUR_OF_DAY); cal.setTimeZone(EST); - int h2 = cal.get(Calendar.HOUR_OF_DAY); + int h2 = cal.get(HOUR_OF_DAY); if (h1 == h2) { errln("FAIL: Fields not updated after setTimeZone"); } @@ -1460,7 +1495,7 @@ // getTime() returns zone-independent time in ms. cal.clear(); cal.setTimeZone(PST); - cal.set(Calendar.HOUR_OF_DAY, 10); + cal.set(HOUR_OF_DAY, 10); Date pst10 = cal.getTime(); cal.setTimeZone(EST); Date est10 = cal.getTime(); @@ -1474,28 +1509,27 @@ */ public void Test4197699() { GregorianCalendar cal = new GregorianCalendar(); - cal.setFirstDayOfWeek(Calendar.MONDAY); + cal.setFirstDayOfWeek(MONDAY); cal.setMinimalDaysInFirstWeek(4); DateFormat fmt = new SimpleDateFormat("E dd MMM yyyy 'DOY='D 'WOY='w"); fmt.setCalendar(cal); int[] DATA = { - 2000, Calendar.JANUARY, 1, 52, - 2001, Calendar.DECEMBER, 31, 1, - }; + 2000, JANUARY, 1, 52, + 2001, DECEMBER, 31, 1}; - for (int i=0; i<DATA.length; ) { + for (int i = 0; i < DATA.length;) { cal.set(DATA[i++], DATA[i++], DATA[i++]); int expWOY = DATA[i++]; - int actWOY = cal.get(Calendar.WEEK_OF_YEAR); + int actWOY = cal.get(WEEK_OF_YEAR); if (expWOY == actWOY) { logln("Ok: " + fmt.format(cal.getTime())); } else { errln("FAIL: " + fmt.format(cal.getTime()) - + ", expected WOY=" + expWOY); - cal.add(Calendar.DATE, -8); - for (int j=0; j<14; ++j) { - cal.add(Calendar.DATE, 1); + + ", expected WOY=" + expWOY); + cal.add(DATE, -8); + for (int j = 0; j < 14; ++j) { + cal.add(DATE, 1); logln(fmt.format(cal.getTime())); } } @@ -1514,6 +1548,7 @@ * DAY_OF_YEAR * WEEK_OF_YEAR + DAY_OF_WEEK */ + @SuppressWarnings("deprecation") public void Test4209071() { Calendar cal = Calendar.getInstance(Locale.US); @@ -1524,106 +1559,104 @@ // Add new test cases as needed. // 0 - new int[] {}, new Date(Y, Calendar.JANUARY, 1), + new int[]{}, new Date(Y, JANUARY, 1), // 1 - new int[] { Calendar.MONTH, Calendar.MARCH }, - new Date(Y, Calendar.MARCH, 1), + new int[]{MONTH, MARCH}, + new Date(Y, MARCH, 1), // 2 - new int[] { Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY }, - new Date(Y, Calendar.JANUARY, 4), + new int[]{DAY_OF_WEEK, WEDNESDAY}, + new Date(Y, JANUARY, 4), // 3 - new int[] { Calendar.DAY_OF_WEEK, Calendar.THURSDAY, - Calendar.DAY_OF_MONTH, 18, }, - new Date(Y, Calendar.JANUARY, 18), + new int[]{DAY_OF_WEEK, THURSDAY, + DAY_OF_MONTH, 18,}, + new Date(Y, JANUARY, 18), // 4 - new int[] { Calendar.DAY_OF_MONTH, 18, - Calendar.DAY_OF_WEEK, Calendar.THURSDAY, }, - new Date(Y, Calendar.JANUARY, 18), + new int[]{DAY_OF_MONTH, 18, + DAY_OF_WEEK, THURSDAY,}, + new Date(Y, JANUARY, 18), // 5 (WOM -1 is in previous month) - new int[] { Calendar.DAY_OF_MONTH, 18, - Calendar.WEEK_OF_MONTH, -1, - Calendar.DAY_OF_WEEK, Calendar.THURSDAY, }, - new Date(Y-1, Calendar.DECEMBER, 22), + new int[]{DAY_OF_MONTH, 18, + WEEK_OF_MONTH, -1, + DAY_OF_WEEK, THURSDAY,}, + new Date(Y - 1, DECEMBER, 22), // 6 - new int[] { Calendar.DAY_OF_MONTH, 18, - Calendar.WEEK_OF_MONTH, 4, - Calendar.DAY_OF_WEEK, Calendar.THURSDAY, }, - new Date(Y, Calendar.JANUARY, 26), + new int[]{DAY_OF_MONTH, 18, + WEEK_OF_MONTH, 4, + DAY_OF_WEEK, THURSDAY,}, + new Date(Y, JANUARY, 26), // 7 (DIM -1 is in same month) - new int[] { Calendar.DAY_OF_MONTH, 18, - Calendar.DAY_OF_WEEK_IN_MONTH, -1, - Calendar.DAY_OF_WEEK, Calendar.THURSDAY, }, - new Date(Y, Calendar.JANUARY, 26), + new int[]{DAY_OF_MONTH, 18, + DAY_OF_WEEK_IN_MONTH, -1, + DAY_OF_WEEK, THURSDAY,}, + new Date(Y, JANUARY, 26), // 8 - new int[] { Calendar.WEEK_OF_YEAR, 9, - Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY, }, - new Date(Y, Calendar.MARCH, 1), + new int[]{WEEK_OF_YEAR, 9, + DAY_OF_WEEK, WEDNESDAY,}, + new Date(Y, MARCH, 1), // 9 - new int[] { Calendar.MONTH, Calendar.OCTOBER, - Calendar.DAY_OF_WEEK_IN_MONTH, 1, - Calendar.DAY_OF_WEEK, Calendar.FRIDAY, }, - new Date(Y, Calendar.OCTOBER, 6), + new int[]{MONTH, OCTOBER, + DAY_OF_WEEK_IN_MONTH, 1, + DAY_OF_WEEK, FRIDAY,}, + new Date(Y, OCTOBER, 6), // 10 - new int[] { Calendar.MONTH, Calendar.OCTOBER, - Calendar.WEEK_OF_MONTH, 2, - Calendar.DAY_OF_WEEK, Calendar.FRIDAY, }, - new Date(Y, Calendar.OCTOBER, 13), + new int[]{MONTH, OCTOBER, + WEEK_OF_MONTH, 2, + DAY_OF_WEEK, FRIDAY,}, + new Date(Y, OCTOBER, 13), // 11 - new int[] { Calendar.MONTH, Calendar.OCTOBER, - Calendar.DAY_OF_MONTH, 15, - Calendar.DAY_OF_YEAR, 222, }, - new Date(Y, Calendar.AUGUST, 10), + new int[]{MONTH, OCTOBER, + DAY_OF_MONTH, 15, + DAY_OF_YEAR, 222,}, + new Date(Y, AUGUST, 10), // 12 - new int[] { Calendar.DAY_OF_WEEK, Calendar.THURSDAY, - Calendar.MONTH, Calendar.DECEMBER, }, - new Date(Y, Calendar.DECEMBER, 7), - }; + new int[]{DAY_OF_WEEK, THURSDAY, + MONTH, DECEMBER,}, + new Date(Y, DECEMBER, 7)}; - for (int i=0; i<FIELD_DATA.length; i+=2) { + for (int i = 0; i < FIELD_DATA.length; i += 2) { int[] fields = (int[]) FIELD_DATA[i]; - Date exp = (Date) FIELD_DATA[i+1]; + Date exp = (Date) FIELD_DATA[i + 1]; cal.clear(); - cal.set(Calendar.YEAR, Y + 1900); - for (int j=0; j<fields.length; j+=2) { - cal.set(fields[j], fields[j+1]); + cal.set(YEAR, Y + 1900); + for (int j = 0; j < fields.length; j += 2) { + cal.set(fields[j], fields[j + 1]); } Date act = cal.getTime(); if (!act.equals(exp)) { - errln("FAIL: Test " + (i/2) + " got " + act + - ", want " + exp + - " (see test/java/util/Calendar/CalendarRegression.java"); + errln("FAIL: Test " + (i / 2) + " got " + act + + ", want " + exp + + " (see test/java/util/Calendar/CalendarRegression.java"); } } // Test specific failure reported in bug + @SuppressWarnings("deprecation") Object[] DATA = { - new Integer(1), new Date(1997-1900, Calendar.JANUARY, 5), - new Integer(4), new Date(1997-1900, Calendar.JANUARY, 26), - new Integer(8), new Date(1997-1900, Calendar.FEBRUARY, 23), - new Integer(-1), new Date(1997-1900, Calendar.JANUARY, 26), - new Integer(-4), new Date(1997-1900, Calendar.JANUARY, 5), - new Integer(-8), new Date(1996-1900, Calendar.DECEMBER, 8), - }; - for (int i=0; i<DATA.length; i+=2) { + 1, new Date(1997 - 1900, JANUARY, 5), + 4, new Date(1997 - 1900, JANUARY, 26), + 8, new Date(1997 - 1900, FEBRUARY, 23), + -1, new Date(1997 - 1900, JANUARY, 26), + -4, new Date(1997 - 1900, JANUARY, 5), + -8, new Date(1996 - 1900, DECEMBER, 8)}; + for (int i = 0; i < DATA.length; i += 2) { cal.clear(); - cal.set(Calendar.DAY_OF_WEEK_IN_MONTH, + cal.set(DAY_OF_WEEK_IN_MONTH, ((Number) DATA[i]).intValue()); - cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); - cal.set(Calendar.MONTH, Calendar.JANUARY); - cal.set(Calendar.YEAR, 1997); + cal.set(DAY_OF_WEEK, SUNDAY); + cal.set(MONTH, JANUARY); + cal.set(YEAR, 1997); Date actual = cal.getTime(); - if (!actual.equals(DATA[i+1])) { - errln("FAIL: Sunday " + DATA[i] + - " of Jan 1997 -> " + actual + - ", want " + DATA[i+1]); + if (!actual.equals(DATA[i + 1])) { + errln("FAIL: Sunday " + DATA[i] + + " of Jan 1997 -> " + actual + + ", want " + DATA[i + 1]); } } } - public void Test4288792() throws Exception - { + public void Test4288792() throws Exception { TimeZone savedTZ = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT")); GregorianCalendar cal = new GregorianCalendar(); @@ -1631,45 +1664,44 @@ for (int i = 1900; i < 2100; i++) { for (int j1 = 1; j1 <= 7; j1++) { // Loop for MinimalDaysInFirstWeek: 1..7 - for (int j = Calendar.SUNDAY; j <= Calendar.SATURDAY; j++) { + for (int j = SUNDAY; j <= SATURDAY; j++) { // Loop for FirstDayOfWeek: SUNDAY..SATURDAY cal.clear(); cal.setMinimalDaysInFirstWeek(j1); cal.setFirstDayOfWeek(j); - cal.set(Calendar.YEAR, i); - int maxWeek = cal.getActualMaximum(Calendar.WEEK_OF_YEAR); - cal.set(Calendar.WEEK_OF_YEAR, maxWeek); - cal.set(Calendar.DAY_OF_WEEK, j); + cal.set(YEAR, i); + int maxWeek = cal.getActualMaximum(WEEK_OF_YEAR); + cal.set(WEEK_OF_YEAR, maxWeek); + cal.set(DAY_OF_WEEK, j); for (int k = 1; k < 7; k++) { - cal.add(Calendar.DATE, 1); - int WOY = cal.get(Calendar.WEEK_OF_YEAR); + cal.add(DATE, 1); + int WOY = cal.get(WEEK_OF_YEAR); if (WOY != maxWeek) { errln(cal.getTime() + ",got=" + WOY - + ",expected=" + maxWeek - + ",min=" + j1 + ",first=" + j); + + ",expected=" + maxWeek + + ",min=" + j1 + ",first=" + j); } } - cal.add(Calendar.DATE, 1); - int WOY = cal.get(Calendar.WEEK_OF_YEAR); + cal.add(DATE, 1); + int WOY = cal.get(WEEK_OF_YEAR); if (WOY != 1) { errln(cal.getTime() + ",got=" + WOY - + ",expected=1,min=" + j1 + ",first" + j); + + ",expected=1,min=" + j1 + ",first" + j); } } } } - } - finally { + } finally { TimeZone.setDefault(savedTZ); } } public void Test4328747() throws Exception { - Calendar c = (Calendar)Calendar.getInstance(Locale.US); + Calendar c = Calendar.getInstance(Locale.US); c.clear(); - c.set(1966,0,1); // 1 jan 1966 + c.set(1966, 0, 1); // 1 jan 1966 // serialize ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -1679,16 +1711,16 @@ // deserialize ObjectInputStream t = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray())); - Calendar result = (Calendar)t.readObject(); + Calendar result = (Calendar) t.readObject(); // let recalculate fields with the same UTC time result.setTime(result.getTime()); // Bug gives 1965 11 19 - if ((result.get(c.YEAR) != 1966) || (result.get(c.MONTH) != 0) - || (result.get(c.DATE) != 1)) { + if ((result.get(YEAR) != 1966) || (result.get(MONTH) != 0) + || (result.get(DATE) != 1)) { errln("deserialized Calendar returned wrong date field(s): " - + result.get(c.YEAR) + "/" + result.get(c.MONTH) + "/" + result.get(c.DATE) - + ", expected 1966/0/1"); + + result.get(YEAR) + "/" + result.get(MONTH) + "/" + result.get(DATE) + + ", expected 1966/0/1"); } } @@ -1700,13 +1732,13 @@ TimeZone savedTimeZone = TimeZone.getDefault(); try { boolean pass = true; - String[] IDs = new String[] {"Undefined", "PST", "US/Pacific", - "GMT+3:00", "GMT-01:30"}; + String[] IDs = new String[]{"Undefined", "PST", "US/Pacific", + "GMT+3:00", "GMT-01:30"}; for (int i = 0; i < IDs.length; i++) { TimeZone tz = TimeZone.getTimeZone(IDs[i]); TimeZone.setDefault(tz); - Calendar c = (Calendar)Calendar.getInstance(); + Calendar c = Calendar.getInstance(); // serialize ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -1719,26 +1751,20 @@ if (!c.equals(t.readObject())) { pass = false; - logln("Calendar instance which uses TimeZone <" + - IDs[i] + "> is incorrectly serialized/deserialized."); + logln("Calendar instance which uses TimeZone <" + + IDs[i] + "> is incorrectly serialized/deserialized."); } else { - logln("Calendar instance which uses TimeZone <" + - IDs[i] + "> is correctly serialized/deserialized."); + logln("Calendar instance which uses TimeZone <" + + IDs[i] + "> is correctly serialized/deserialized."); } } if (!pass) { errln("Fail: Calendar serialization/equality bug"); } - } - catch (IOException e) { + } catch (IOException | ClassNotFoundException e) { errln("Fail: " + e); e.printStackTrace(); - } - catch (ClassNotFoundException e) { - errln("Fail: " + e); - e.printStackTrace(); - } - finally { + } finally { TimeZone.setDefault(savedTimeZone); } } @@ -1747,12 +1773,12 @@ * 4546637: Incorrect WEEK_OF_MONTH after changing First Day Of Week */ public void Test4546637() { - GregorianCalendar day = new GregorianCalendar (2001, Calendar.NOVEMBER, 04); + GregorianCalendar day = new GregorianCalendar(2001, NOVEMBER, 04); day.setMinimalDaysInFirstWeek(1); - int wom = day.get(Calendar.WEEK_OF_MONTH); + int wom = day.get(WEEK_OF_MONTH); - day.setFirstDayOfWeek(Calendar.MONDAY); - if (day.get(Calendar.WEEK_OF_MONTH) != 1) { + day.setFirstDayOfWeek(MONDAY); + if (day.get(WEEK_OF_MONTH) != 1) { errln("Fail: 2001/11/4 must be the first week of the month."); } } @@ -1761,14 +1787,14 @@ * 4623997: GregorianCalendar returns bad WEEK_OF_YEAR */ public void Test4623997() { - GregorianCalendar cal = new GregorianCalendar(2000, GregorianCalendar.JANUARY, 1); + GregorianCalendar cal = new GregorianCalendar(2000, JANUARY, 1); - int dow = cal.get(GregorianCalendar.DAY_OF_WEEK); + int dow = cal.get(DAY_OF_WEEK); - cal.setFirstDayOfWeek(GregorianCalendar.MONDAY); + cal.setFirstDayOfWeek(MONDAY); cal.setMinimalDaysInFirstWeek(4); - if (cal.get(GregorianCalendar.WEEK_OF_YEAR) != 52) { + if (cal.get(WEEK_OF_YEAR) != 52) { errln("Fail: 2000/1/1 must be the 52nd week of the year."); } } @@ -1800,9 +1826,9 @@ } t = calendar.getTime(); - calendar.set(Calendar.DAY_OF_MONTH, 33); + calendar.set(DAY_OF_MONTH, 33); t = calendar.getTime(); - calendar.set(Calendar.DAY_OF_MONTH, 0); + calendar.set(DAY_OF_MONTH, 0); s = df.format(calendar.getTime()); if (!expected.equals(s)) { errln("DAY_OF_MONTH w/o ZONE_OFFSET: expected: " + expected + ", got: " + s); @@ -1815,10 +1841,10 @@ throw new RuntimeException("Unexpected parse exception", e); } t = calendar.getTime(); - calendar.set(calendar.ZONE_OFFSET, calendar.get(calendar.ZONE_OFFSET)); - calendar.set(Calendar.DAY_OF_MONTH, 33); + calendar.set(ZONE_OFFSET, calendar.get(ZONE_OFFSET)); + calendar.set(DAY_OF_MONTH, 33); t = calendar.getTime(); - calendar.set(Calendar.DAY_OF_MONTH, 0); + calendar.set(DAY_OF_MONTH, 0); s = df.format(calendar.getTime()); if (!expected.equals(s)) { errln("DAY_OF_MONTH: expected: " + expected + ", got: " + s); @@ -1834,11 +1860,11 @@ throw new RuntimeException("Unexpected parse exception", e); } t = calendar.getTime(); - calendar.set(calendar.ZONE_OFFSET, calendar.get(calendar.ZONE_OFFSET)); + calendar.set(ZONE_OFFSET, calendar.get(ZONE_OFFSET)); // jump to the next year - calendar.set(Calendar.WEEK_OF_YEAR, 100); + calendar.set(WEEK_OF_YEAR, 100); t = calendar.getTime(); - calendar.set(Calendar.WEEK_OF_YEAR, 0); + calendar.set(WEEK_OF_YEAR, 0); s = df.format(calendar.getTime()); if (!expected.equals(s)) { errln("WEEK_OF_YEAR: expected: " + expected + ", got: " + s); @@ -1846,11 +1872,11 @@ // change the state back calendar.clear(); calendar.setTime(initialDate); - calendar.set(calendar.ZONE_OFFSET, calendar.get(calendar.ZONE_OFFSET)); + calendar.set(ZONE_OFFSET, calendar.get(ZONE_OFFSET)); // jump to next month - calendar.set(Calendar.WEEK_OF_MONTH, 7); + calendar.set(WEEK_OF_MONTH, 7); t = calendar.getTime(); - calendar.set(Calendar.WEEK_OF_MONTH, 0); + calendar.set(WEEK_OF_MONTH, 0); s = df.format(calendar.getTime()); if (!expected.equals(s)) { errln("WEEK_OF_MONTH: expected: " + expected + ", got: " + s); @@ -1870,10 +1896,10 @@ } t = calendar.getTime(); // time should be 22:59:59. - calendar.set(Calendar.MINUTE, 61); + calendar.set(MINUTE, 61); // time should be 23:01:59. t = calendar.getTime(); - calendar.set(Calendar.MINUTE, -1); + calendar.set(MINUTE, -1); // time should be back to 22:59:59. s = df.format(calendar.getTime()); if (!expected.equals(s)) { @@ -1896,15 +1922,15 @@ Calendar cal = Calendar.getInstance(); cal.setTime(new Date(1029814211523L)); - cal.set(Calendar.YEAR, 2001); + cal.set(YEAR, 2001); Date t = cal.getTime(); - cal.set(Calendar.MONTH, Calendar.JANUARY); + cal.set(MONTH, JANUARY); t = cal.getTime(); - cal.set(Calendar.DAY_OF_MONTH, 8); + cal.set(DAY_OF_MONTH, 8); t = cal.getTime(); - cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); + cal.set(DAY_OF_WEEK, MONDAY); DateFormat df = new SimpleDateFormat("yyyy/MM/dd", Locale.US); String expected = "2001/01/08"; String s = df.format(cal.getTime()); @@ -1923,9 +1949,9 @@ */ public void Test4683492() { Calendar cal = new GregorianCalendar(2002, 3, 29, 10, 0, 0); - cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); - cal.set(Calendar.DAY_OF_WEEK_IN_MONTH, -1); - cal.set(Calendar.MONTH, 12); + cal.set(DAY_OF_WEEK, FRIDAY); + cal.set(DAY_OF_WEEK_IN_MONTH, -1); + cal.set(MONTH, 12); DateFormat df = new SimpleDateFormat("yyyy/MM/dd", Locale.US); String expected = "2003/01/31"; String s = df.format(cal.getTime()); @@ -1940,31 +1966,31 @@ public void Test4080631() { Calendar cal = Calendar.getInstance(); int h1 = cal.hashCode(); - cal.add(cal.SECOND, +1); + cal.add(SECOND, +1); int h2 = cal.hashCode(); Calendar cal2 = (Calendar) cal.clone(); - cal.add(cal.MILLISECOND, +1); + cal.add(MILLISECOND, +1); int h3 = cal.hashCode(); - logln("hash code: h1="+h1+", h2="+h2+", h3="+h3); + logln("hash code: h1=" + h1 + ", h2=" + h2 + ", h3=" + h3); if (h1 == h2 || h1 == h3 || h2 == h3) { - errln("hash code is poor: hashCode="+h1); + errln("hash code is poor: hashCode=" + h1); } h2 = cal2.hashCode(); - cal.add(cal.MILLISECOND, -1); + cal.add(MILLISECOND, -1); int h4 = cal.hashCode(); - logln("hash code: h2="+h2+", h4="+h4); + logln("hash code: h2=" + h2 + ", h4=" + h4); if (cal.equals(cal2) && h2 != h4) { - errln("broken hash code: h2="+h2+", h4="+h4); + errln("broken hash code: h2=" + h2 + ", h4=" + h4); } int x = cal.getFirstDayOfWeek() + 3; - if (x > cal.SATURDAY) { + if (x > SATURDAY) { x -= 7; } cal.setFirstDayOfWeek(x); int h5 = cal.hashCode(); - logln("hash code: h4="+h4+", h5="+h5); + logln("hash code: h4=" + h4 + ", h5=" + h5); if (h4 == h5) { - errln("has code is poor with first day of week param: hashCode="+h4); + errln("has code is poor with first day of week param: hashCode=" + h4); } } @@ -1991,8 +2017,7 @@ errln("Wrong BCE and/or CE values"); } } - */ - + */ /** * 4167995: GregorianCalendar.setGregorianChange() not to spec */ @@ -2000,42 +2025,42 @@ Koyomi gc = new Koyomi(TimeZone.getTimeZone("GMT")); logln("Hybrid: min date"); gc.setTime(new Date(Long.MIN_VALUE)); - if (!gc.checkDate(292269055, gc.DECEMBER, 2, gc.SUNDAY) - || !gc.checkFieldValue(gc.ERA, gc.BC)) { + if (!gc.checkDate(292269055, DECEMBER, 2, SUNDAY) + || !gc.checkFieldValue(ERA, GregorianCalendar.BC)) { errln(gc.getMessage()); } logln("Hybrid: max date"); gc.setTime(new Date(Long.MAX_VALUE)); - if (!gc.checkDate(292278994, gc.AUGUST, 17, gc.SUNDAY) - || !gc.checkFieldValue(gc.ERA, gc.AD)) { + if (!gc.checkDate(292278994, AUGUST, 17, SUNDAY) + || !gc.checkFieldValue(ERA, GregorianCalendar.AD)) { errln(gc.getMessage()); } gc.setGregorianChange(new Date(Long.MIN_VALUE)); logln("Gregorian: min date"); gc.setTime(new Date(Long.MIN_VALUE)); - if (!gc.checkDate(292275056, gc.MAY, 16, gc.SUNDAY) - || !gc.checkFieldValue(gc.ERA, gc.BC)) { + if (!gc.checkDate(292275056, MAY, 16, SUNDAY) + || !gc.checkFieldValue(ERA, GregorianCalendar.BC)) { errln(gc.getMessage()); } logln("Gregorian: max date"); gc.setTime(new Date(Long.MAX_VALUE)); - if (!gc.checkDate(292278994, gc.AUGUST, 17, gc.SUNDAY) - || !gc.checkFieldValue(gc.ERA, gc.AD)) { + if (!gc.checkDate(292278994, AUGUST, 17, SUNDAY) + || !gc.checkFieldValue(ERA, GregorianCalendar.AD)) { errln(gc.getMessage()); } gc.setGregorianChange(new Date(Long.MAX_VALUE)); logln("Julian: min date"); gc.setTime(new Date(Long.MIN_VALUE)); - if (!gc.checkDate(292269055, gc.DECEMBER, 2, gc.SUNDAY) - || !gc.checkFieldValue(gc.ERA, gc.BC)) { + if (!gc.checkDate(292269055, DECEMBER, 2, SUNDAY) + || !gc.checkFieldValue(ERA, GregorianCalendar.BC)) { errln(gc.getMessage()); } logln("Julian: max date"); gc.setTime(new Date(Long.MAX_VALUE)); - if (!gc.checkDate(292272993, gc.JANUARY, 4, gc.SUNDAY) - || !gc.checkFieldValue(gc.ERA, gc.AD)) { + if (!gc.checkDate(292272993, JANUARY, 4, SUNDAY) + || !gc.checkFieldValue(ERA, GregorianCalendar.AD)) { errln(gc.getMessage()); } } @@ -2046,13 +2071,13 @@ public void Test4340146() { Koyomi cal = new Koyomi(); cal.clear(); - cal.set(2003, cal.OCTOBER, 32); + cal.set(2003, OCTOBER, 32); cal.equals(new Koyomi()); - if (!cal.checkInternalDate(2003, cal.OCTOBER, 32)) { + if (!cal.checkInternalDate(2003, OCTOBER, 32)) { errln(cal.getMessage()); } new Koyomi().equals(cal); - if (!cal.checkInternalDate(2003, cal.OCTOBER, 32)) { + if (!cal.checkInternalDate(2003, OCTOBER, 32)) { errln(cal.getMessage()); } } @@ -2065,10 +2090,10 @@ // throw IllegalArgumentException. Koyomi cal = new Koyomi(TimeZone.getTimeZone("Pacific/Kiritimati")); cal.setLenient(false); - cal.set(2003, cal.OCTOBER, 10); + cal.set(2003, OCTOBER, 10); cal.getTime(); cal.setTimeZone(TimeZone.getTimeZone("Pacific/Tongatapu")); - cal.set(2003, cal.OCTOBER, 10); + cal.set(2003, OCTOBER, 10); cal.getTime(); } @@ -2077,10 +2102,10 @@ */ public void Test4652815() { Koyomi cal = new Koyomi(Locale.US); - testRoll(cal, 2003, cal.SEPTEMBER, 29); - testRoll(cal, 2003, cal.DECEMBER, 24); - testRoll(cal, 1582, cal.DECEMBER, 19); - testRoll(cal, 1582, cal.DECEMBER, 20); + testRoll(cal, 2003, SEPTEMBER, 29); + testRoll(cal, 2003, DECEMBER, 24); + testRoll(cal, 1582, DECEMBER, 19); + testRoll(cal, 1582, DECEMBER, 20); } private void testRoll(Koyomi cal, int year, int month, int dayOfMonth) { @@ -2089,15 +2114,15 @@ cal.getTime(); // normalize fields logln("Roll backwards from " + cal.toDateString()); for (int i = 0; i < 1000; i++) { - cal.roll(cal.WEEK_OF_YEAR, -i); - if (!cal.checkFieldValue(cal.YEAR, year)) { + cal.roll(WEEK_OF_YEAR, -i); + if (!cal.checkFieldValue(YEAR, year)) { errln(cal.getMessage()); } } logln("Roll forewards from " + cal.toDateString()); for (int i = 0; i < 1000; i++) { - cal.roll(cal.WEEK_OF_YEAR, +i); - if (!cal.checkFieldValue(cal.YEAR, year)) { + cal.roll(WEEK_OF_YEAR, +i); + if (!cal.checkFieldValue(YEAR, year)) { errln(cal.getMessage()); } } @@ -2110,20 +2135,20 @@ Koyomi cal = new Koyomi(Locale.US); cal.clear(); logln("BCE 9-2-28 (leap year) roll DAY_OF_MONTH++ twice"); - cal.set(cal.ERA, cal.BC); - cal.set(9, cal.FEBRUARY, 28); - if (cal.getActualMaximum(cal.DAY_OF_YEAR) != 366) { + cal.set(ERA, GregorianCalendar.BC); + cal.set(9, FEBRUARY, 28); + if (cal.getActualMaximum(DAY_OF_YEAR) != 366) { errln(" wrong actual max of DAY_OF_YEAR: got " - + cal.getActualMaximum(cal.DAY_OF_YEAR) + " expected " + 366); + + cal.getActualMaximum(DAY_OF_YEAR) + " expected " + 366); } - cal.roll(cal.DAY_OF_MONTH, +1); - if (!cal.checkFieldValue(cal.ERA, cal.BC) - || !cal.checkDate(9, cal.FEBRUARY, 29)) { + cal.roll(DAY_OF_MONTH, +1); + if (!cal.checkFieldValue(ERA, GregorianCalendar.BC) + || !cal.checkDate(9, FEBRUARY, 29)) { errln(cal.getMessage()); } - cal.roll(cal.DAY_OF_MONTH, +1); - if (!cal.checkFieldValue(cal.ERA, cal.BC) - || !cal.checkDate(9, cal.FEBRUARY, 1)) { + cal.roll(DAY_OF_MONTH, +1); + if (!cal.checkFieldValue(ERA, GregorianCalendar.BC) + || !cal.checkDate(9, FEBRUARY, 1)) { errln(cal.getMessage()); } } @@ -2135,11 +2160,11 @@ logln("1999/(Feb+12)/1 should be normalized to 2000/Feb/1 for getActualMaximum"); Koyomi cal = new Koyomi(Locale.US); cal.clear(); - cal.set(1999, cal.FEBRUARY + 12, 1); - if (!cal.checkActualMaximum(cal.DAY_OF_YEAR, 366)) { + cal.set(1999, FEBRUARY + 12, 1); + if (!cal.checkActualMaximum(DAY_OF_YEAR, 366)) { errln(cal.getMessage()); } - if (!cal.checkActualMaximum(cal.DAY_OF_MONTH, 29)) { + if (!cal.checkActualMaximum(DAY_OF_MONTH, 29)) { errln(cal.getMessage()); } } @@ -2150,36 +2175,36 @@ public void Test4936355() { Koyomi cal = new Koyomi(TimeZone.getTimeZone("GMT")); cal.clear(); - cal.set(1970, cal.JANUARY, 1); - checkTimeCalculation(cal, cal.HOUR_OF_DAY, Integer.MAX_VALUE, - (long)Integer.MAX_VALUE * 60 * 60 * 1000); + cal.set(1970, JANUARY, 1); + checkTimeCalculation(cal, HOUR_OF_DAY, Integer.MAX_VALUE, + (long) Integer.MAX_VALUE * 60 * 60 * 1000); cal.clear(); - cal.set(1970, cal.JANUARY, 1); - checkTimeCalculation(cal, cal.HOUR, Integer.MAX_VALUE, - (long)Integer.MAX_VALUE * 60 * 60 * 1000); + cal.set(1970, JANUARY, 1); + checkTimeCalculation(cal, HOUR, Integer.MAX_VALUE, + (long) Integer.MAX_VALUE * 60 * 60 * 1000); cal.clear(); - cal.set(1970, cal.JANUARY, 1); - checkTimeCalculation(cal, cal.MINUTE, Integer.MAX_VALUE, - (long)Integer.MAX_VALUE * 60 * 1000); + cal.set(1970, JANUARY, 1); + checkTimeCalculation(cal, MINUTE, Integer.MAX_VALUE, + (long) Integer.MAX_VALUE * 60 * 1000); cal.clear(); // Make sure to use Gregorian dates (before and after the // set() call) for testing - cal.set(250000, cal.JANUARY, 1); - checkTimeCalculation(cal, cal.HOUR_OF_DAY, Integer.MIN_VALUE, - (long)Integer.MIN_VALUE * 60 * 60 * 1000); + cal.set(250000, JANUARY, 1); + checkTimeCalculation(cal, HOUR_OF_DAY, Integer.MIN_VALUE, + (long) Integer.MIN_VALUE * 60 * 60 * 1000); cal.clear(); - cal.set(250000, cal.JANUARY, 1); - checkTimeCalculation(cal, cal.HOUR, Integer.MIN_VALUE, - (long)Integer.MIN_VALUE * 60 * 60 * 1000); + cal.set(250000, JANUARY, 1); + checkTimeCalculation(cal, HOUR, Integer.MIN_VALUE, + (long) Integer.MIN_VALUE * 60 * 60 * 1000); cal.clear(); - cal.set(250000, cal.JANUARY, 1); - checkTimeCalculation(cal, cal.MINUTE, Integer.MIN_VALUE, - (long)Integer.MIN_VALUE * 60 * 1000); + cal.set(250000, JANUARY, 1); + checkTimeCalculation(cal, MINUTE, Integer.MIN_VALUE, + (long) Integer.MIN_VALUE * 60 * 1000); } private void checkTimeCalculation(Koyomi cal, int field, int value, long expectedDelta) { @@ -2189,7 +2214,7 @@ if ((time + expectedDelta) != time2) { String s = value == Integer.MAX_VALUE ? "Integer.MAX_VALUE" : "Integer.MIN_VALUE"; errln("set(" + Koyomi.getFieldName(field) + ", " + s + ") failed." + " got " + time2 - + ", expected " + (time+expectedDelta)); + + ", expected " + (time + expectedDelta)); } } @@ -2204,8 +2229,8 @@ cal2.clear(); cal2.setLenient(false); - cal1.set(2003, Calendar.OCTOBER, 31); - cal2.set(2003, Calendar.OCTOBER, 31); + cal1.set(2003, OCTOBER, 31); + cal2.set(2003, OCTOBER, 31); try { if (cal1.equals(cal2)) { errln("lenient and non-lenient shouldn't be equal. (2003/10/31)"); @@ -2217,8 +2242,8 @@ errln("equals threw IllegalArugumentException with non-lenient"); } - cal1.set(2003, Calendar.OCTOBER, 32); - cal2.set(2003, Calendar.OCTOBER, 32); + cal1.set(2003, OCTOBER, 32); + cal2.set(2003, OCTOBER, 32); try { if (cal1.equals(cal2)) { errln("lenient and non-lenient shouldn't be equal. (2003/10/32)"); @@ -2246,17 +2271,17 @@ * 4738710: API: Calendar comparison methods should be improved */ public void Test4738710() { - Calendar cal0 = new GregorianCalendar(2003, Calendar.SEPTEMBER, 30); - Comparable<Calendar> cal1 = new GregorianCalendar(2003, Calendar.OCTOBER, 1); - Calendar cal2 = new GregorianCalendar(2003, Calendar.OCTOBER, 2); + Calendar cal0 = new GregorianCalendar(2003, SEPTEMBER, 30); + Comparable<Calendar> cal1 = new GregorianCalendar(2003, OCTOBER, 1); + Calendar cal2 = new GregorianCalendar(2003, OCTOBER, 2); if (!(cal1.compareTo(cal0) > 0)) { errln("!(cal1 > cal0)"); } if (!(cal1.compareTo(cal2) < 0)) { errln("!(cal1 < cal2)"); } - if (cal1.compareTo(new GregorianCalendar(2003, Calendar.OCTOBER, 1)) != 0) { - errln("cal1 != new GregorianCalendar(2003, Calendar.OCTOBER, 1)"); + if (cal1.compareTo(new GregorianCalendar(2003, OCTOBER, 1)) != 0) { + errln("cal1 != new GregorianCalendar(2003, OCTOBER, 1)"); } if (cal0.after(cal2)) { @@ -2266,10 +2291,10 @@ errln("cal2 shouldn't be before cal0"); } - if (cal0.after(new Integer(0))) { + if (cal0.after(0)) { errln("cal0.after() returned true with an Integer."); } - if (cal0.before(new Integer(0))) { + if (cal0.before(0)) { errln("cal0.before() returned true with an Integer."); } if (cal0.after(null)) { @@ -2283,34 +2308,35 @@ /** * 4633646: Setting WEEK_OF_MONTH to 1 results in incorrect date */ + @SuppressWarnings("deprecation") public void Test4633646() { Koyomi cal = new Koyomi(Locale.US); - cal.setTime(new Date(2002-1900, 1-1, 28)); + cal.setTime(new Date(2002 - 1900, 1 - 1, 28)); sub4633646(cal); cal.setLenient(false); - cal.setTime(new Date(2002-1900, 1-1, 28)); + cal.setTime(new Date(2002 - 1900, 1 - 1, 28)); sub4633646(cal); cal = new Koyomi(Locale.US); cal.clear(); - cal.set(2002, cal.JANUARY, 28); + cal.set(2002, JANUARY, 28); sub4633646(cal); cal.clear(); cal.setLenient(false); - cal.set(2002, cal.JANUARY, 28); + cal.set(2002, JANUARY, 28); sub4633646(cal); } void sub4633646(Koyomi cal) { cal.getTime(); - cal.set(cal.WEEK_OF_MONTH, 1); + cal.set(WEEK_OF_MONTH, 1); if (cal.isLenient()) { - if (!cal.checkDate(2001, cal.DECEMBER, 31)) { + if (!cal.checkDate(2001, DECEMBER, 31)) { errln(cal.getMessage()); } - if (!cal.checkFieldValue(cal.WEEK_OF_MONTH, 6)) { + if (!cal.checkFieldValue(WEEK_OF_MONTH, 6)) { errln(cal.getMessage()); } } else { @@ -2329,29 +2355,29 @@ public void Test4846659() { Koyomi cal = new Koyomi(); cal.clear(); - cal.set(2003, cal.OCTOBER, 31, 10, 30, 30); + cal.set(2003, OCTOBER, 31, 10, 30, 30); cal.getTime(); // Test roll() - cal.roll(cal.AM_PM, +1); // should turn to PM - if (!cal.checkFieldValue(cal.HOUR_OF_DAY, 10+12)) { + cal.roll(AM_PM, +1); // should turn to PM + if (!cal.checkFieldValue(HOUR_OF_DAY, 10 + 12)) { errln("roll: AM_PM didn't change to PM"); } cal.clear(); - cal.set(2003, cal.OCTOBER, 31, 10, 30, 30); + cal.set(2003, OCTOBER, 31, 10, 30, 30); cal.getTime(); // Test set() - cal.set(cal.AM_PM, cal.PM); // should turn to PM - if (!cal.checkFieldValue(cal.HOUR_OF_DAY, 10+12)) { + cal.set(AM_PM, PM); // should turn to PM + if (!cal.checkFieldValue(HOUR_OF_DAY, 10 + 12)) { errln("set: AM_PM didn't change to PM"); } cal.clear(); - cal.set(2003, cal.OCTOBER, 31, 10, 30, 30); + cal.set(2003, OCTOBER, 31, 10, 30, 30); cal.getTime(); - cal.set(cal.AM_PM, cal.PM); - cal.set(cal.HOUR, 9); - if (!cal.checkFieldValue(cal.HOUR_OF_DAY, 9+12)) { + cal.set(AM_PM, PM); + cal.set(HOUR, 9); + if (!cal.checkFieldValue(HOUR_OF_DAY, 9 + 12)) { errln("set: both AM_PM and HOUT didn't change to PM"); } } @@ -2370,15 +2396,15 @@ // 29 30 cal.clear(); // 6/1 to 6/7 should be the 1st week of June. - cal.set(2003, cal.JUNE, 2); + cal.set(2003, JUNE, 2); cal.getTime(); // Let cal calculate time. - cal.setFirstDayOfWeek(cal.MONDAY); + cal.setFirstDayOfWeek(MONDAY); // Now 6/2 to 6/8 should be the 2nd week of June. Sunday of // that week is 6/8. - logln("1: " +cal.get(cal.WEEK_OF_MONTH)+", "+cal.get(cal.DAY_OF_MONTH)); - cal.set(cal.DAY_OF_WEEK, cal.SUNDAY); + logln("1: " + cal.get(WEEK_OF_MONTH) + ", " + cal.get(DAY_OF_MONTH)); + cal.set(DAY_OF_WEEK, SUNDAY); logln("1st Sunday of June 2003 with FirstDayOfWeek=MONDAY"); - if (!cal.checkDate(2003, cal.JUNE, 8)) { + if (!cal.checkDate(2003, JUNE, 8)) { errln(cal.getMessage()); } } @@ -2387,7 +2413,7 @@ * 4973919: Inconsistent GregorianCalendar hashCode before and after serialization */ public void Test4966499() throws Exception { - GregorianCalendar date1 = new GregorianCalendar(2004, Calendar.JANUARY, 7); + GregorianCalendar date1 = new GregorianCalendar(2004, JANUARY, 7); // Serialize date1 ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -2399,15 +2425,15 @@ // Deserialize it ByteArrayInputStream bais = new ByteArrayInputStream(buffer); ObjectInputStream ois = new ObjectInputStream(bais); - GregorianCalendar date2 = (GregorianCalendar)ois.readObject(); + GregorianCalendar date2 = (GregorianCalendar) ois.readObject(); if (!date1.equals(date2)) { errln("date1.equals(date2) != true"); } if (date1.hashCode() != date2.hashCode()) { errln("inconsistent hashCode() value (before=0x" - +Integer.toHexString(date1.hashCode())+ - ", after=0x"+Integer.toHexString(date2.hashCode())+")"); + + Integer.toHexString(date1.hashCode()) + + ", after=0x" + Integer.toHexString(date2.hashCode()) + ")"); } } @@ -2468,29 +2494,26 @@ TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("GMT")); try { - Map<Date, Boolean> data = new HashMap<Date, Boolean>(); - data.put(getGregorianDate(999, Calendar.OCTOBER, 1), Boolean.FALSE); - data.put(getGregorianDate(1000, Calendar.JANUARY, 1), Boolean.FALSE); - data.put(getGregorianDate(1000, Calendar.FEBRUARY, 1), Boolean.FALSE); - data.put(getGregorianDate(1000, Calendar.FEBRUARY, 28), Boolean.FALSE); - data.put(getGregorianDate(1000, Calendar.MARCH, 1), Boolean.TRUE); - data.put(getGregorianDate(1001, Calendar.JANUARY, 1), Boolean.TRUE); - data.put(getGregorianDate(1001, Calendar.JANUARY, 6), Boolean.TRUE); - data.put(getGregorianDate(1001, Calendar.MARCH, 1), Boolean.TRUE); + Map<Date, Boolean> data = new HashMap<>(); + data.put(getGregorianDate(999, OCTOBER, 1), Boolean.FALSE); + data.put(getGregorianDate(1000, JANUARY, 1), Boolean.FALSE); + data.put(getGregorianDate(1000, FEBRUARY, 1), Boolean.FALSE); + data.put(getGregorianDate(1000, FEBRUARY, 28), Boolean.FALSE); + data.put(getGregorianDate(1000, MARCH, 1), Boolean.TRUE); + data.put(getGregorianDate(1001, JANUARY, 1), Boolean.TRUE); + data.put(getGregorianDate(1001, JANUARY, 6), Boolean.TRUE); + data.put(getGregorianDate(1001, MARCH, 1), Boolean.TRUE); - Iterator<Date> itr = data.keySet().iterator(); - while (itr.hasNext()) { - Date d = itr.next(); - boolean expected = data.get(d).booleanValue(); + data.keySet().forEach(d -> { + boolean expected = data.get(d); GregorianCalendar cal = new GregorianCalendar(); cal.setGregorianChange(d); if (cal.isLeapYear(1000) != expected) { - errln("isLeapYear(1000) returned " + cal.isLeapYear(1000) + - " with cutover date (Julian) " + d); + errln("isLeapYear(1000) returned " + cal.isLeapYear(1000) + + " with cutover date (Julian) " + d); } - } - } - finally { + }); + } finally { TimeZone.setDefault(savedZone); } } @@ -2511,15 +2534,15 @@ */ public void Test5006864() { GregorianCalendar cal = new GregorianCalendar(); - int min = cal.getMinimum(cal.DAY_OF_WEEK_IN_MONTH); + int min = cal.getMinimum(DAY_OF_WEEK_IN_MONTH); if (min != 1) { errln("GregorianCalendar.getMinimum(DAY_OF_WEEK_IN_MONTH) returned " - + min + ", expected 1."); + + min + ", expected 1."); } - min = cal.getGreatestMinimum(cal.DAY_OF_WEEK_IN_MONTH); + min = cal.getGreatestMinimum(DAY_OF_WEEK_IN_MONTH); if (min != 1) { errln("GregorianCalendar.getGreatestMinimum(DAY_OF_WEEK_IN_MONTH) returned " - + min + ", expected 1."); + + min + ", expected 1."); } } }
--- a/jdk/test/java/util/Calendar/CalendarTest.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/util/Calendar/CalendarTest.java Tue Nov 22 11:46:06 2016 -0800 @@ -30,12 +30,25 @@ * @key randomness */ -import java.util.*; -import java.text.*; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.SimpleTimeZone; +import java.util.TimeZone; + +import static java.util.Calendar.*; public class CalendarTest extends IntlTest { - static final int ONE_DAY = 24*60*60*1000; + + static final int ONE_DAY = 24 * 60 * 60 * 1000; static final int EPOCH_JULIAN = 2440588; public static void main(String argv[]) throws Exception { @@ -64,32 +77,31 @@ Changeover +6 days: 1582/10/21 dow=5 Changeover +7 days: 1582/10/22 dow=6 */ - int MON[] = { 9, 9, 9,10,10,10,10, 10, 10, 10, 10, 10, 10, 10, 10 }; - int DOM[] = { 28, 29, 30, 1, 2, 3, 4, 15, 16, 17, 18, 19, 20, 21, 22 }; - int DOW[] = { 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6 }; + int[] MON = { 9, 9, 9,10,10,10,10, 10, 10, 10, 10, 10, 10, 10, 10 }; + int[] DOM = { 28, 29, 30, 1, 2, 3, 4, 15, 16, 17, 18, 19, 20, 21, 22 }; + int[] DOW = { 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6 }; // ^ <-Changeover Fri Oct 15 1582 - try { TimeZone.setDefault(TimeZone.getTimeZone("GMT")); - Date co = new Date(1582-1900, Calendar.OCTOBER, 15); + @SuppressWarnings("deprecation") + Date co = new Date(1582 - 1900, OCTOBER, 15); GregorianCalendar cal = new GregorianCalendar(); int j = 0; for (int i = -7; i <= 7; ++i, ++j) { - Date d = new Date(co.getTime() + i*ONE_DAY); + Date d = new Date(co.getTime() + i * ONE_DAY); cal.setTime(d); - int y = cal.get(Calendar.YEAR); - int mon = cal.get(Calendar.MONTH)+1-Calendar.JANUARY; - int dom = cal.get(Calendar.DATE); - int dow = cal.get(Calendar.DAY_OF_WEEK); + int y = cal.get(YEAR); + int mon = cal.get(MONTH) + 1 - JANUARY; + int dom = cal.get(DATE); + int dow = cal.get(DAY_OF_WEEK); - logln("Changeover " + (i>=0?"+":"") + i + - " days: " + y + "/" + mon + "/" + dom + " dow=" + dow); + logln("Changeover " + (i >= 0 ? "+" : "") + i + + " days: " + y + "/" + mon + "/" + dom + " dow=" + dow); if (y != 1582 || mon != MON[j] || dom != DOM[j] || dow != DOW[j]) { errln(" Fail: Above line is wrong"); } } - } - finally { + } finally { TimeZone.setDefault(savedZone); } } @@ -99,22 +111,22 @@ * of this test, we don't care about timezones and week data * (first day of week, minimal days in first week). */ + @SuppressWarnings("deprecation") public void TestMapping() { TimeZone saveZone = TimeZone.getDefault(); int[] DATA = { - // Julian# Year Month DOM JULIAN:Year, Month, DOM - 2440588, 1970, Calendar.JANUARY, 1, 1969, Calendar.DECEMBER, 19, - 2415080, 1900, Calendar.MARCH, 1, 1900, Calendar.FEBRUARY, 17, - 2451604, 2000, Calendar.FEBRUARY, 29, 2000, Calendar.FEBRUARY, 16, - 2452269, 2001, Calendar.DECEMBER, 25, 2001, Calendar.DECEMBER, 12, - 2416526, 1904, Calendar.FEBRUARY, 15, 1904, Calendar.FEBRUARY, 2, - 2416656, 1904, Calendar.JUNE, 24, 1904, Calendar.JUNE, 11, - 1721426, 1, Calendar.JANUARY, 1, 1, Calendar.JANUARY, 3, - 2000000, 763, Calendar.SEPTEMBER, 18, 763, Calendar.SEPTEMBER, 14, - 4000000, 6239, Calendar.JULY, 12, 6239, Calendar.MAY, 28, - 8000000, 17191, Calendar.FEBRUARY, 26, 17190, Calendar.OCTOBER, 22, - 10000000, 22666, Calendar.DECEMBER, 20, 22666, Calendar.JULY, 5, - }; + // Julian# Year Month DOM JULIAN:Year Month, DOM + 2440588, 1970, JANUARY, 1, 1969, DECEMBER, 19, + 2415080, 1900, MARCH, 1, 1900, FEBRUARY, 17, + 2451604, 2000, FEBRUARY, 29, 2000, FEBRUARY, 16, + 2452269, 2001, DECEMBER, 25, 2001, DECEMBER, 12, + 2416526, 1904, FEBRUARY, 15, 1904, FEBRUARY, 2, + 2416656, 1904, JUNE, 24, 1904, JUNE, 11, + 1721426, 1, JANUARY, 1, 1, JANUARY, 3, + 2000000, 763, SEPTEMBER, 18, 763, SEPTEMBER, 14, + 4000000, 6239, JULY, 12, 6239, MAY, 28, + 8000000, 17191, FEBRUARY, 26, 17190, OCTOBER, 22, + 10000000, 22666, DECEMBER, 20, 22666, JULY, 5}; try { TimeZone.setDefault(TimeZone.getTimeZone("UTC")); @@ -123,11 +135,11 @@ GregorianCalendar cal = new GregorianCalendar(); for (int i = 0; i < DATA.length; i += 7) { int julian = DATA[i]; - int year = DATA[i+1]; - int month = DATA[i+2]; - int dom = DATA[i+3]; + int year = DATA[i + 1]; + int month = DATA[i + 2]; + int dom = DATA[i + 3]; int year2, month2, dom2; - long millis = ((long)julian - EPOCH_JULIAN) * ONE_DAY; + long millis = ((long) julian - EPOCH_JULIAN) * ONE_DAY; String s; // Test Gregorian computation @@ -137,56 +149,55 @@ long calMillis = cal.getTime().getTime(); long delta = calMillis - millis; cal.setTime(new Date(millis)); - year2 = cal.get(Calendar.YEAR); - month2 = cal.get(Calendar.MONTH); - dom2 = cal.get(Calendar.DAY_OF_MONTH); - s = "G " + year + "-" + (month+1-Calendar.JANUARY) + "-" + dom + - " => " + calMillis + - " (" + ((float)delta/ONE_DAY) + " day delta) => " + - year2 + "-" + (month2+1-Calendar.JANUARY) + "-" + dom2; - if (delta != 0 || year != year2 || month != month2 || - dom != dom2) { + year2 = cal.get(YEAR); + month2 = cal.get(MONTH); + dom2 = cal.get(DAY_OF_MONTH); + s = "G " + year + "-" + (month + 1 - JANUARY) + "-" + dom + + " => " + calMillis + + " (" + ((float) delta / ONE_DAY) + " day delta) => " + + year2 + "-" + (month2 + 1 - JANUARY) + "-" + dom2; + if (delta != 0 || year != year2 || month != month2 + || dom != dom2) { errln(s + " FAIL"); } else { logln(s); } // Test Julian computation - year = DATA[i+4]; - month = DATA[i+5]; - dom = DATA[i+6]; + year = DATA[i + 4]; + month = DATA[i + 5]; + dom = DATA[i + 6]; cal.setGregorianChange(PURE_JULIAN); cal.clear(); cal.set(year, month, dom); calMillis = cal.getTime().getTime(); delta = calMillis - millis; cal.setTime(new Date(millis)); - year2 = cal.get(Calendar.YEAR); - month2 = cal.get(Calendar.MONTH); - dom2 = cal.get(Calendar.DAY_OF_MONTH); - s = "J " + year + "-" + (month+1-Calendar.JANUARY) + "-" + dom + - " => " + calMillis + - " (" + ((float)delta/ONE_DAY) + " day delta) => " + - year2 + "-" + (month2+1-Calendar.JANUARY) + "-" + dom2; - if (delta != 0 || year != year2 || month != month2 || - dom != dom2) { + year2 = cal.get(YEAR); + month2 = cal.get(MONTH); + dom2 = cal.get(DAY_OF_MONTH); + s = "J " + year + "-" + (month + 1 - JANUARY) + "-" + dom + + " => " + calMillis + + " (" + ((float) delta / ONE_DAY) + " day delta) => " + + year2 + "-" + (month2 + 1 - JANUARY) + "-" + dom2; + if (delta != 0 || year != year2 || month != month2 + || dom != dom2) { errln(s + " FAIL"); } else { logln(s); } } - cal.setGregorianChange(new Date(1582-1900, Calendar.OCTOBER, 15)); - auxMapping(cal, 1582, Calendar.OCTOBER, 4); - auxMapping(cal, 1582, Calendar.OCTOBER, 15); - auxMapping(cal, 1582, Calendar.OCTOBER, 16); - for (int y = 800; y < 3000; y += 1+(int)100*Math.random()) { - for (int m = Calendar.JANUARY; m <= Calendar.DECEMBER; ++m) { + cal.setGregorianChange(new Date(1582 - 1900, OCTOBER, 15)); + auxMapping(cal, 1582, OCTOBER, 4); + auxMapping(cal, 1582, OCTOBER, 15); + auxMapping(cal, 1582, OCTOBER, 16); + for (int y = 800; y < 3000; y += 1 + 100 * Math.random()) { + for (int m = JANUARY; m <= DECEMBER; ++m) { auxMapping(cal, y, m, 15); } } - } - finally { + } finally { TimeZone.setDefault(saveZone); } } @@ -195,14 +206,16 @@ cal.set(y, m, d); long millis = cal.getTime().getTime(); cal.setTime(new Date(millis)); - int year2 = cal.get(Calendar.YEAR); - int month2 = cal.get(Calendar.MONTH); - int dom2 = cal.get(Calendar.DAY_OF_MONTH); - if (y != year2 || m != month2 || dom2 != d) - errln("Round-trip failure: " + y + "-" + (m+1) + "-"+d+" =>ms=> " + - year2 + "-" + (month2+1) + "-" + dom2); + int year2 = cal.get(YEAR); + int month2 = cal.get(MONTH); + int dom2 = cal.get(DAY_OF_MONTH); + if (y != year2 || m != month2 || dom2 != d) { + errln("Round-trip failure: " + y + "-" + (m + 1) + "-" + d + " =>ms=> " + + year2 + "-" + (month2 + 1) + "-" + dom2); + } } + @SuppressWarnings("deprecation") public void TestGenericAPI() { Locale locale = Locale.getDefault(); if (!TestUtils.usesGregorianCalendar(locale)) { @@ -211,76 +224,95 @@ } String str; - - Date when = new Date(90, Calendar.APRIL, 15); + Date when = new Date(90, APRIL, 15); String tzid = "TestZone"; int tzoffset = 123400; SimpleTimeZone zone = new SimpleTimeZone(tzoffset, tzid); - Calendar cal = (Calendar)Calendar.getInstance((SimpleTimeZone)zone.clone()); + Calendar cal = Calendar.getInstance((SimpleTimeZone) zone.clone()); - if (!zone.equals(cal.getTimeZone())) errln("FAIL: Calendar.getTimeZone failed"); + if (!zone.equals(cal.getTimeZone())) { + errln("FAIL: Calendar.getTimeZone failed"); + } Calendar cal2 = Calendar.getInstance(cal.getTimeZone()); cal.setTime(when); cal2.setTime(when); - if (!(cal.equals(cal2))) errln("FAIL: Calendar.operator== failed"); + if (!(cal.equals(cal2))) { + errln("FAIL: Calendar.operator== failed"); + } // if ((*cal != *cal2)) errln("FAIL: Calendar.operator!= failed"); - if (!cal.equals(cal2) || - cal.before(cal2) || - cal.after(cal2)) errln("FAIL: equals/before/after failed"); + if (!cal.equals(cal2) + || cal.before(cal2) + || cal.after(cal2)) { + errln("FAIL: equals/before/after failed"); + } cal2.setTime(new Date(when.getTime() + 1000)); - if (cal.equals(cal2) || - cal2.before(cal) || - cal.after(cal2)) errln("FAIL: equals/before/after failed"); + if (cal.equals(cal2) + || cal2.before(cal) + || cal.after(cal2)) { + errln("FAIL: equals/before/after failed"); + } - cal.roll(Calendar.SECOND, true); - if (!cal.equals(cal2) || - cal.before(cal2) || - cal.after(cal2)) errln("FAIL: equals/before/after failed"); + cal.roll(SECOND, true); + if (!cal.equals(cal2) + || cal.before(cal2) + || cal.after(cal2)) { + errln("FAIL: equals/before/after failed"); + } // Roll back to January - cal.roll(Calendar.MONTH, (int)(1 + Calendar.DECEMBER - cal.get(Calendar.MONTH))); - if (cal.equals(cal2) || - cal2.before(cal) || - cal.after(cal2)) errln("FAIL: equals/before/after failed"); + cal.roll(MONTH, 1 + DECEMBER - cal.get(MONTH)); + if (cal.equals(cal2) + || cal2.before(cal) + || cal.after(cal2)) { + errln("FAIL: equals/before/after failed"); + } // C++ only /* TimeZone z = cal.orphanTimeZone(); - if (z.getID(str) != tzid || - z.getRawOffset() != tzoffset) - errln("FAIL: orphanTimeZone failed"); - */ - + if (z.getID(str) != tzid || + z.getRawOffset() != tzoffset) + errln("FAIL: orphanTimeZone failed"); + */ for (int i = 0; i < 2; ++i) { - boolean lenient = ( i > 0 ); + boolean lenient = (i > 0); cal.setLenient(lenient); - if (lenient != cal.isLenient()) errln("FAIL: setLenient/isLenient failed"); + if (lenient != cal.isLenient()) { + errln("FAIL: setLenient/isLenient failed"); + } // Later: Check for lenient behavior } int i; - for (i = Calendar.SUNDAY; i <= Calendar.SATURDAY; ++i) { + for (i = SUNDAY; i <= SATURDAY; ++i) { cal.setFirstDayOfWeek(i); - if (cal.getFirstDayOfWeek() != i) errln("FAIL: set/getFirstDayOfWeek failed"); + if (cal.getFirstDayOfWeek() != i) { + errln("FAIL: set/getFirstDayOfWeek failed"); + } } for (i = 0; i <= 7; ++i) { cal.setMinimalDaysInFirstWeek(i); - if (cal.getMinimalDaysInFirstWeek() != i) errln("FAIL: set/getFirstDayOfWeek failed"); + if (cal.getMinimalDaysInFirstWeek() != i) { + errln("FAIL: set/getFirstDayOfWeek failed"); + } } - for (i = 0; i < Calendar.FIELD_COUNT; ++i) { - if (cal.getMinimum(i) != cal.getGreatestMinimum(i)) + for (i = 0; i < FIELD_COUNT; ++i) { + if (cal.getMinimum(i) != cal.getGreatestMinimum(i)) { errln("FAIL: getMinimum doesn't match getGreatestMinimum for field " + i); - if (cal.getLeastMaximum(i) > cal.getMaximum(i)) + } + if (cal.getLeastMaximum(i) > cal.getMaximum(i)) { errln("FAIL: getLeastMaximum larger than getMaximum for field " + i); - if (cal.getMinimum(i) >= cal.getMaximum(i)) + } + if (cal.getMinimum(i) >= cal.getMaximum(i)) { errln("FAIL: getMinimum not less than getMaximum for field " + i); + } } cal.setTimeZone(TimeZone.getDefault()); @@ -306,30 +338,36 @@ } cal.getTime(); - for (i = 0; i < Calendar.FIELD_COUNT; ++i) { - switch(i) { - case Calendar.YEAR: case Calendar.MONTH: case Calendar.DATE: - case Calendar.HOUR_OF_DAY: case Calendar.MINUTE: case Calendar.SECOND: - if (!cal.isSet(i)) - errln("FAIL: !Calendar.isSet test failed: " + calendarFieldNames[i]); - break; - default: - if (cal.isSet(i)) - errln("FAIL: Calendar.isSet test failed: " + calendarFieldNames[i]); + for (i = 0; i < FIELD_COUNT; ++i) { + switch (i) { + case YEAR: + case MONTH: + case DATE: + case HOUR_OF_DAY: + case MINUTE: + case SECOND: + if (!cal.isSet(i)) { + errln("FAIL: !Calendar.isSet test failed: " + calendarFieldNames[i]); + } + break; + default: + if (cal.isSet(i)) { + errln("FAIL: Calendar.isSet test failed: " + calendarFieldNames[i]); + } } cal.clear(i); - if (cal.isSet(i)) errln("FAIL: Calendar.clear/isSet failed"); + if (cal.isSet(i)) { + errln("FAIL: Calendar.clear/isSet failed"); + } } // delete cal; // delete cal2; - Locale[] loc = Calendar.getAvailableLocales(); long count = loc.length; if (count < 1 || loc == null) { errln("FAIL: getAvailableLocales failed"); - } - else { + } else { for (i = 0; i < count; ++i) { cal = Calendar.getInstance(loc[i]); // delete cal; @@ -358,13 +396,15 @@ // delete gc; gc = new GregorianCalendar(1998, 10, 14, 21, 43); - if (gc.getTime().getTime() != new Date(98, 10, 14, 21, 43).getTime()) + if (gc.getTime().getTime() != new Date(98, 10, 14, 21, 43).getTime()) { errln("FAIL: new GregorianCalendar(ymdhm) failed"); + } // delete gc; gc = new GregorianCalendar(1998, 10, 14, 21, 43, 55); - if (gc.getTime().getTime() != new Date(98, 10, 14, 21, 43, 55).getTime()) + if (gc.getTime().getTime() != new Date(98, 10, 14, 21, 43, 55).getTime()) { errln("FAIL: new GregorianCalendar(ymdhms) failed"); + } // C++ only: // GregorianCalendar gc2 = new GregorianCalendar(Locale.ENGLISH); @@ -378,19 +418,20 @@ public void TestRog() { GregorianCalendar gc = new GregorianCalendar(); - int year = 1997, month = Calendar.APRIL, date = 1; + int year = 1997, month = APRIL, date = 1; gc.set(year, month, date); // April 1, 1997 - gc.set(Calendar.HOUR_OF_DAY, 23); - gc.set(Calendar.MINUTE, 0); - gc.set(Calendar.SECOND, 0); - gc.set(Calendar.MILLISECOND, 0); + gc.set(HOUR_OF_DAY, 23); + gc.set(MINUTE, 0); + gc.set(SECOND, 0); + gc.set(MILLISECOND, 0); - for (int i = 0; i < 9; i++, gc.add(Calendar.DATE, 1)) { - if (gc.get(Calendar.YEAR) != year || - gc.get(Calendar.MONTH) != month || - gc.get(Calendar.DATE) != (date + i)) + for (int i = 0; i < 9; i++, gc.add(DATE, 1)) { + if (gc.get(YEAR) != year + || gc.get(MONTH) != month + || gc.get(DATE) != (date + i)) { errln("FAIL: Date " + gc.getTime() + " wrong"); + } } } @@ -402,162 +443,172 @@ void dowTest(boolean lenient) { GregorianCalendar cal = new GregorianCalendar(); - cal.set(1997, Calendar.AUGUST, 12); // Wednesday + cal.set(1997, AUGUST, 12); // Wednesday cal.getTime(); // Force update cal.setLenient(lenient); - cal.set(1996, Calendar.DECEMBER, 1); // Set the date to be December 1, 1996 - int dow = cal.get(Calendar.DAY_OF_WEEK); - int min = cal.getMinimum(Calendar.DAY_OF_WEEK); - int max = cal.getMaximum(Calendar.DAY_OF_WEEK); - if (dow < min || dow > max) errln("FAIL: Day of week " + dow + " out of range"); - if (dow != Calendar.SUNDAY) { + cal.set(1996, DECEMBER, 1); // Set the date to be December 1, 1996 + int dow = cal.get(DAY_OF_WEEK); + int min = cal.getMinimum(DAY_OF_WEEK); + int max = cal.getMaximum(DAY_OF_WEEK); + if (dow < min || dow > max) { + errln("FAIL: Day of week " + dow + " out of range"); + } + if (dow != SUNDAY) { errln("FAIL2: Day of week should be SUNDAY; is " + dow + ": " + cal.getTime()); } - if (min != Calendar.SUNDAY || max != Calendar.SATURDAY) errln("FAIL: Min/max bad"); + if (min != SUNDAY || max != SATURDAY) { + errln("FAIL: Min/max bad"); + } } // Verify that the clone method produces distinct objects with no // unintentionally shared fields. public void TestClonesUnique908() { Calendar c = Calendar.getInstance(); - Calendar d = (Calendar)c.clone(); - c.set(Calendar.MILLISECOND, 123); - d.set(Calendar.MILLISECOND, 456); - if (c.get(Calendar.MILLISECOND) != 123 || - d.get(Calendar.MILLISECOND) != 456) { + Calendar d = (Calendar) c.clone(); + c.set(MILLISECOND, 123); + d.set(MILLISECOND, 456); + if (c.get(MILLISECOND) != 123 + || d.get(MILLISECOND) != 456) { errln("FAIL: Clones share fields"); } } // Verify effect of Gregorian cutoff value + @SuppressWarnings("deprecation") public void TestGregorianChange768() { boolean b; GregorianCalendar c = new GregorianCalendar(); logln("With cutoff " + c.getGregorianChange()); - logln(" isLeapYear(1800) = " + (b=c.isLeapYear(1800))); + logln(" isLeapYear(1800) = " + (b = c.isLeapYear(1800))); logln(" (should be FALSE)"); - if (b != false) errln("FAIL"); + if (b != false) { + errln("FAIL"); + } c.setGregorianChange(new Date(0, 0, 1)); // Jan 1 1900 logln("With cutoff " + c.getGregorianChange()); - logln(" isLeapYear(1800) = " + (b=c.isLeapYear(1800))); + logln(" isLeapYear(1800) = " + (b = c.isLeapYear(1800))); logln(" (should be TRUE)"); - if (b != true) errln("FAIL"); + if (b != true) { + errln("FAIL"); + } } // Test the correct behavior of the disambiguation algorithm. public void TestDisambiguation765() throws Exception { - Locale savedLocale = Locale.getDefault(); - try { - Locale.setDefault(Locale.US); - Calendar c = Calendar.getInstance(); - c.setLenient(false); + Locale savedLocale = Locale.getDefault(); + try { + Locale.setDefault(Locale.US); + Calendar c = Calendar.getInstance(); + c.setLenient(false); - c.clear(); - c.set(Calendar.YEAR, 1997); - c.set(Calendar.MONTH, Calendar.JUNE); - c.set(Calendar.DATE, 3); + c.clear(); + c.set(YEAR, 1997); + c.set(MONTH, JUNE); + c.set(DATE, 3); - verify765("1997 third day of June = ", c, 1997, Calendar.JUNE, 3); + verify765("1997 third day of June = ", c, 1997, JUNE, 3); - c.clear(); - c.set(Calendar.YEAR, 1997); - c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); - c.set(Calendar.MONTH, Calendar.JUNE); - c.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1); - verify765("1997 first Tuesday in June = ", c, 1997, Calendar.JUNE, 3); + c.clear(); + c.set(YEAR, 1997); + c.set(DAY_OF_WEEK, TUESDAY); + c.set(MONTH, JUNE); + c.set(DAY_OF_WEEK_IN_MONTH, 1); + verify765("1997 first Tuesday in June = ", c, 1997, JUNE, 3); - c.setLenient(true); // for 4944795 - c.clear(); - c.set(Calendar.YEAR, 1997); - c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); - c.set(Calendar.MONTH, Calendar.JUNE); - c.set(Calendar.DAY_OF_WEEK_IN_MONTH, -1); - verify765("1997 last Tuesday in June = ", c, 1997, Calendar.JUNE, 24); - - c.setLenient(false); - IllegalArgumentException e = null; - try { + c.setLenient(true); // for 4944795 c.clear(); - c.set(Calendar.YEAR, 1997); - c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); - c.set(Calendar.MONTH, Calendar.JUNE); - c.set(Calendar.DAY_OF_WEEK_IN_MONTH, 0); - c.getTime(); - } - catch (IllegalArgumentException ex) { - e = ex; - } - verify765("1997 zero-th Tuesday in June = ", e); + c.set(YEAR, 1997); + c.set(DAY_OF_WEEK, TUESDAY); + c.set(MONTH, JUNE); + c.set(DAY_OF_WEEK_IN_MONTH, -1); + verify765("1997 last Tuesday in June = ", c, 1997, JUNE, 24); - c.clear(); - c.set(Calendar.YEAR, 1997); - c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); - c.set(Calendar.MONTH, Calendar.JUNE); - c.set(Calendar.WEEK_OF_MONTH, 1); - verify765("1997 Tuesday in week 1 of June = ", c, 1997, Calendar.JUNE, 3); + c.setLenient(false); + IllegalArgumentException e = null; + try { + c.clear(); + c.set(YEAR, 1997); + c.set(DAY_OF_WEEK, TUESDAY); + c.set(MONTH, JUNE); + c.set(DAY_OF_WEEK_IN_MONTH, 0); + c.getTime(); + } catch (IllegalArgumentException ex) { + e = ex; + } + verify765("1997 zero-th Tuesday in June = ", e); - c.clear(); - c.set(Calendar.YEAR, 1997); - c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); - c.set(Calendar.MONTH, Calendar.JUNE); - c.set(Calendar.WEEK_OF_MONTH, 4); - verify765("1997 Tuesday in week 4 of June = ", c, 1997, Calendar.JUNE, 24); - - try { c.clear(); - c.set(Calendar.YEAR, 1997); - c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); - c.set(Calendar.MONTH, Calendar.JUNE); - c.set(Calendar.WEEK_OF_MONTH, 1); - verify765("1997 Tuesday in week 0 of June = ", c, 1997, Calendar.JUNE, 3); - } - catch (IllegalArgumentException ex) { - errln("FAIL: Exception seen: " + ex.getMessage()); - // ex.printStackTrace(log); - } + c.set(YEAR, 1997); + c.set(DAY_OF_WEEK, TUESDAY); + c.set(MONTH, JUNE); + c.set(WEEK_OF_MONTH, 1); + verify765("1997 Tuesday in week 1 of June = ", c, 1997, JUNE, 3); - c.clear(); - c.set(Calendar.YEAR, 1997); - c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); - c.set(Calendar.WEEK_OF_YEAR, 2); - verify765("1997 Tuesday in week 2 of year = ", c, 1997, Calendar.JANUARY, 7); + c.clear(); + c.set(YEAR, 1997); + c.set(DAY_OF_WEEK, TUESDAY); + c.set(MONTH, JUNE); + c.set(WEEK_OF_MONTH, 4); + verify765("1997 Tuesday in week 4 of June = ", c, 1997, JUNE, 24); - c.clear(); - c.set(Calendar.YEAR, 1997); - c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); - c.set(Calendar.WEEK_OF_YEAR, 10); - verify765("1997 Tuesday in week 10 of year = ", c, 1997, Calendar.MARCH, 4); + try { + c.clear(); + c.set(YEAR, 1997); + c.set(DAY_OF_WEEK, TUESDAY); + c.set(MONTH, JUNE); + c.set(WEEK_OF_MONTH, 1); + verify765("1997 Tuesday in week 0 of June = ", c, 1997, JUNE, 3); + } catch (IllegalArgumentException ex) { + errln("FAIL: Exception seen: " + ex.getMessage()); + // ex.printStackTrace(log); + } - try { c.clear(); - c.set(Calendar.YEAR, 1997); - c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); - c.set(Calendar.WEEK_OF_YEAR, 0); - verify765("1997 Tuesday in week 0 of year = ", c, 1996, Calendar.DECEMBER, 24); - throw new Exception("Fail: WEEK_OF_YEAR 0 should be illegal"); - } - catch (IllegalArgumentException ex) {} - } - finally { - Locale.setDefault(savedLocale); - } - } - void verify765(String msg, Calendar c, int year, int month, int day) { - if (c.get(Calendar.YEAR) == year && - c.get(Calendar.MONTH) == month && - c.get(Calendar.DATE) == day) { - logln("PASS: " + msg + c.getTime()); - } - else { - errln("FAIL: " + msg + c.getTime() + - "; expected " + - year + "/" + (month+1) + "/" + day); + c.set(YEAR, 1997); + c.set(DAY_OF_WEEK, TUESDAY); + c.set(WEEK_OF_YEAR, 2); + verify765("1997 Tuesday in week 2 of year = ", c, 1997, JANUARY, 7); + + c.clear(); + c.set(YEAR, 1997); + c.set(DAY_OF_WEEK, TUESDAY); + c.set(WEEK_OF_YEAR, 10); + verify765("1997 Tuesday in week 10 of year = ", c, 1997, MARCH, 4); + + try { + c.clear(); + c.set(YEAR, 1997); + c.set(DAY_OF_WEEK, TUESDAY); + c.set(WEEK_OF_YEAR, 0); + verify765("1997 Tuesday in week 0 of year = ", c, 1996, DECEMBER, 24); + throw new Exception("Fail: WEEK_OF_YEAR 0 should be illegal"); + } catch (IllegalArgumentException ex) { + } + } finally { + Locale.setDefault(savedLocale); } } + + void verify765(String msg, Calendar c, int year, int month, int day) { + if (c.get(YEAR) == year + && c.get(MONTH) == month + && c.get(DATE) == day) { + logln("PASS: " + msg + c.getTime()); + } else { + errln("FAIL: " + msg + c.getTime() + + "; expected " + + year + "/" + (month + 1) + "/" + day); + } + } + // Called when e expected to be non-null void verify765(String msg, IllegalArgumentException e) { - if (e == null) errln("FAIL: No IllegalArgumentException for " + msg); - else logln("PASS: " + msg + "IllegalArgument as expected"); + if (e == null) { + errln("FAIL: No IllegalArgumentException for " + msg); + } else { + logln("PASS: " + msg + "IllegalArgument as expected"); + } } // Test the behavior of GMT vs. local time @@ -588,106 +639,112 @@ Date date; Calendar gmtcal = Calendar.getInstance(); gmtcal.setTimeZone(TimeZone.getTimeZone("Africa/Casablanca")); - gmtcal.set(yr, mo-1, dt, hr, mn, sc); - gmtcal.set(Calendar.MILLISECOND, 0); + gmtcal.set(yr, mo - 1, dt, hr, mn, sc); + gmtcal.set(MILLISECOND, 0); date = gmtcal.getTime(); - logln("date = "+date); + logln("date = " + date); Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); cal.setTime(date); - int offset = cal.getTimeZone().getOffset(cal.get(Calendar.ERA), - cal.get(Calendar.YEAR), - cal.get(Calendar.MONTH), - cal.get(Calendar.DATE), - cal.get(Calendar.DAY_OF_WEEK), - cal.get(Calendar.MILLISECOND)); + int offset = cal.getTimeZone().getOffset(cal.get(ERA), + cal.get(YEAR), + cal.get(MONTH), + cal.get(DATE), + cal.get(DAY_OF_WEEK), + cal.get(MILLISECOND)); - logln("offset for "+date+"= "+(offset/1000/60/60.0) + "hr"); + logln("offset for " + date + "= " + (offset / 1000 / 60 / 60.0) + "hr"); - int utc = ((cal.get(Calendar.HOUR_OF_DAY) * 60 + - cal.get(Calendar.MINUTE)) * 60 + - cal.get(Calendar.SECOND)) * 1000 + - cal.get(Calendar.MILLISECOND) - offset; + int utc = ((cal.get(HOUR_OF_DAY) * 60 + + cal.get(MINUTE)) * 60 + + cal.get(SECOND)) * 1000 + + cal.get(MILLISECOND) - offset; int expected = ((hr * 60 + mn) * 60 + sc) * 1000; - if (utc != expected) - errln("FAIL: Discrepancy of " + - (utc - expected) + " millis = " + - ((utc-expected)/1000/60/60.0) + " hr"); + if (utc != expected) { + errln("FAIL: Discrepancy of " + + (utc - expected) + " millis = " + + ((utc - expected) / 1000 / 60 / 60.0) + " hr"); + } } // Verify that add and set work regardless of the order in which // they are called. public void TestAddSetOrder621() { + @SuppressWarnings("deprecation") Date d = new Date(97, 4, 14, 13, 23, 45); - Calendar cal = Calendar.getInstance (); - cal.setTime (d); - cal.add (Calendar.DATE, -5); - cal.set (Calendar.HOUR_OF_DAY, 0); - cal.set (Calendar.MINUTE, 0); - cal.set (Calendar.SECOND, 0); + Calendar cal = Calendar.getInstance(); + cal.setTime(d); + cal.add(DATE, -5); + cal.set(HOUR_OF_DAY, 0); + cal.set(MINUTE, 0); + cal.set(SECOND, 0); // ma feb 03 00:00:00 GMT+00:00 1997 - String s = cal.getTime ().toString (); + String s = cal.getTime().toString(); - cal = Calendar.getInstance (); - cal.setTime (d); - cal.set (Calendar.HOUR_OF_DAY, 0); - cal.set (Calendar.MINUTE, 0); - cal.set (Calendar.SECOND, 0); - cal.add (Calendar.DATE, -5); + cal = Calendar.getInstance(); + cal.setTime(d); + cal.set(HOUR_OF_DAY, 0); + cal.set(MINUTE, 0); + cal.set(SECOND, 0); + cal.add(DATE, -5); // ma feb 03 13:11:06 GMT+00:00 1997 - String s2 = cal.getTime ().toString (); + String s2 = cal.getTime().toString(); - if (s.equals(s2)) + if (s.equals(s2)) { logln("Pass: " + s + " == " + s2); - else + } else { errln("FAIL: " + s + " != " + s2); + } } // Verify that add works. public void TestAdd520() { - int y = 1997, m = Calendar.FEBRUARY, d = 1; - GregorianCalendar temp = new GregorianCalendar( y, m, d ); + int y = 1997, m = FEBRUARY, d = 1; + GregorianCalendar temp = new GregorianCalendar(y, m, d); check520(temp, y, m, d); - temp.add( temp.YEAR, 1 ); + temp.add(YEAR, 1); y++; check520(temp, y, m, d); - temp.add( temp.MONTH, 1 ); + temp.add(MONTH, 1); m++; check520(temp, y, m, d); - temp.add( temp.DATE, 1 ); + temp.add(DATE, 1); d++; check520(temp, y, m, d); - temp.add( temp.DATE, 2 ); + temp.add(DATE, 2); d += 2; check520(temp, y, m, d); - temp.add( temp.DATE, 28 ); - d = 1; ++m; + temp.add(DATE, 28); + d = 1; + ++m; check520(temp, y, m, d); } + void check520(Calendar c, int y, int m, int d) { - if (c.get(Calendar.YEAR) != y || - c.get(Calendar.MONTH) != m || - c.get(Calendar.DATE) != d) { - errln("FAILURE: Expected YEAR/MONTH/DATE of " + - y + "/" + (m+1) + "/" + d + - "; got " + - c.get(Calendar.YEAR) + "/" + - (c.get(Calendar.MONTH)+1) + "/" + - c.get(Calendar.DATE)); + if (c.get(YEAR) != y + || c.get(MONTH) != m + || c.get(DATE) != d) { + errln("FAILURE: Expected YEAR/MONTH/DATE of " + + y + "/" + (m + 1) + "/" + d + + "; got " + + c.get(YEAR) + "/" + + (c.get(MONTH) + 1) + "/" + + c.get(DATE)); + } else { + logln("Confirmed: " + + y + "/" + (m + 1) + "/" + d); } - else logln("Confirmed: " + - y + "/" + (m+1) + "/" + d); } // Verify that setting fields works. This test fails when an exception is thrown. @@ -697,18 +754,18 @@ GregorianCalendar g2 = new GregorianCalendar(); // At this point UTC value is set, various fields are not. // Now set to noon. - g2.set(Calendar.HOUR, 12); - g2.set(Calendar.MINUTE, 0); - g2.set(Calendar.SECOND, 0); + g2.set(HOUR, 12); + g2.set(MINUTE, 0); + g2.set(SECOND, 0); // At this point the object thinks UTC is NOT set, but fields are set. // The following line will result in IllegalArgumentException because // it thinks the YEAR is set and it is NOT. - if (g2.equals(g)) + if (g2.equals(g)) { logln("Same"); - else + } else { logln("Different"); - } - catch (IllegalArgumentException e) { + } + } catch (IllegalArgumentException e) { errln("Unexpected exception seen: " + e); } } @@ -729,28 +786,28 @@ FileInputStream in = new FileInputStream(FILENAME); ObjectInputStream t = new ObjectInputStream(in); - String pre = (String)t.readObject(); - Calendar c = (Calendar)t.readObject(); - String post = (String)t.readObject(); + String pre = (String) t.readObject(); + Calendar c = (Calendar) t.readObject(); + String post = (String) t.readObject(); in.close(); - ok = pre.equals(PREFIX) && - post.equals(POSTFIX) && - cal.equals(c); + ok = pre.equals(PREFIX) + && post.equals(POSTFIX) + && cal.equals(c); File fl = new File(FILENAME); fl.delete(); - } - catch (IOException e) { + } catch (IOException e) { errln("FAIL: Exception received:"); // e.printStackTrace(log); - } - catch (ClassNotFoundException e) { + } catch (ClassNotFoundException e) { errln("FAIL: Exception received:"); // e.printStackTrace(log); } - if (!ok) errln("Serialization of Calendar object failed."); + if (!ok) { + errln("Serialization of Calendar object failed."); + } } static final String PREFIX = "abc"; static final String POSTFIX = "def"; @@ -758,14 +815,16 @@ // Try to zero out the seconds field public void TestSecondsZero121() { - Calendar cal = new GregorianCalendar(); + Calendar cal = new GregorianCalendar(); // Initialize with current date/time cal.setTime(new Date()); // Round down to minute - cal.set(Calendar.SECOND, 0); - Date d = cal.getTime(); + cal.set(SECOND, 0); + Date d = cal.getTime(); String s = d.toString(); - if (s.indexOf(":00 ") < 0) errln("Expected to see :00 in " + s); + if (s.indexOf(":00 ") < 0) { + errln("Expected to see :00 in " + s); + } } // Try various sequences of add, set, and get method calls. @@ -777,15 +836,17 @@ // - Addition uses millis which are still *now* // { - Calendar calendar = new GregorianCalendar( ) ; - calendar.set( 1993, Calendar.JANUARY, 4 ) ; - logln( "1A) " + value( calendar ) ) ; - calendar.add( Calendar.DATE, 1 ) ; + Calendar calendar = new GregorianCalendar(); + calendar.set(1993, JANUARY, 4); + logln("1A) " + value(calendar)); + calendar.add(DATE, 1); String v = value(calendar); - logln( "1B) " + v ); - logln( "--) 1993/0/5" ) ; - if (!v.equals(EXPECTED_0610)) errln("Expected " + EXPECTED_0610 + - "; saw " + v); + logln("1B) " + v); + logln("--) 1993/0/5"); + if (!v.equals(EXPECTED_0610)) { + errln("Expected " + EXPECTED_0610 + + "; saw " + v); + } } // @@ -793,16 +854,17 @@ // - Upon initialization calendar fields set, millis = 0 // - Addition uses millis which are still 1970, 0, 1 // - { - Calendar calendar = new GregorianCalendar( 1993, Calendar.JANUARY, 4 ) ; - logln( "2A) " + value( calendar ) ) ; - calendar.add( Calendar.DATE, 1 ) ; + Calendar calendar = new GregorianCalendar(1993, JANUARY, 4); + logln("2A) " + value(calendar)); + calendar.add(DATE, 1); String v = value(calendar); - logln( "2B) " + v ); - logln( "--) 1993/0/5" ) ; - if (!v.equals(EXPECTED_0610)) errln("Expected " + EXPECTED_0610 + - "; saw " + v); + logln("2B) " + v); + logln("--) 1993/0/5"); + if (!v.equals(EXPECTED_0610)) { + errln("Expected " + EXPECTED_0610 + + "; saw " + v); + } } // @@ -811,102 +873,99 @@ // - getTime( ) is called which forces the millis to be set // - Addition uses millis which are correct // - { - Calendar calendar = new GregorianCalendar( 1993, Calendar.JANUARY, 4 ) ; - logln( "3A) " + value( calendar ) ) ; - calendar.getTime( ) ; - calendar.add( Calendar.DATE, 1 ) ; + Calendar calendar = new GregorianCalendar(1993, JANUARY, 4); + logln("3A) " + value(calendar)); + calendar.getTime(); + calendar.add(DATE, 1); String v = value(calendar); - logln( "3B) " + v ) ; - logln( "--) 1993/0/5" ) ; - if (!v.equals(EXPECTED_0610)) errln("Expected " + EXPECTED_0610 + - "; saw " + v); + logln("3B) " + v); + logln("--) 1993/0/5"); + if (!v.equals(EXPECTED_0610)) { + errln("Expected " + EXPECTED_0610 + + "; saw " + v); + } } } - static String value( Calendar calendar ) { - return( calendar.get( Calendar.YEAR ) + "/" + - calendar.get( Calendar.MONTH ) + "/" + - calendar.get( Calendar.DATE ) ) ; + static String value(Calendar calendar) { + return (calendar.get(YEAR) + "/" + + calendar.get(MONTH) + "/" + + calendar.get(DATE)); } static String EXPECTED_0610 = "1993/0/5"; // Test that certain fields on a certain date are as expected. public void TestFields060() { int year = 1997; - int month = java.util.Calendar.OCTOBER; //october + int month = OCTOBER; //october int dDate = 22; //DAYOFWEEK should return 3 for Wednesday GregorianCalendar calendar = null; - calendar = new GregorianCalendar( year, month, dDate); - for (int i = 0; i < EXPECTED_FIELDS.length; ) { + calendar = new GregorianCalendar(year, month, dDate); + for (int i = 0; i < EXPECTED_FIELDS.length;) { int field = EXPECTED_FIELDS[i++]; int expected = EXPECTED_FIELDS[i++]; if (calendar.get(field) != expected) { - errln("Expected field " + field + " to have value " + expected + - "; received " + calendar.get(field) + " instead"); + errln("Expected field " + field + " to have value " + expected + + "; received " + calendar.get(field) + " instead"); } } } - static int EXPECTED_FIELDS[] = { - Calendar.YEAR, 1997, - Calendar.MONTH, Calendar.OCTOBER, - Calendar.DAY_OF_MONTH, 22, - Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY, - Calendar.DAY_OF_WEEK_IN_MONTH, 4, - Calendar.DAY_OF_YEAR, 295 - }; + static int[] EXPECTED_FIELDS = { + YEAR, 1997, + MONTH, OCTOBER, + DAY_OF_MONTH, 22, + DAY_OF_WEEK, WEDNESDAY, + DAY_OF_WEEK_IN_MONTH, 4, + DAY_OF_YEAR, 295}; static final String[] calendarFieldNames = { - /* 0 */ "ERA", - /* 1 */ "YEAR", - /* 2 */ "MONTH", - /* 3 */ "WEEK_OF_YEAR", - /* 4 */ "WEEK_OF_MONTH", - /* 5 */ "DAY_OF_MONTH", - /* 6 */ "DAY_OF_YEAR", - /* 7 */ "DAY_OF_WEEK", - /* 8 */ "DAY_OF_WEEK_IN_MONTH", - /* 9 */ "AM_PM", - /* 10 */ "HOUR", - /* 11 */ "HOUR_OF_DAY", - /* 12 */ "MINUTE", - /* 13 */ "SECOND", - /* 14 */ "MILLISECOND", - /* 15 */ "ZONE_OFFSET", - /* 16 */ "DST_OFFSET" - }; + /* 0 */ "ERA", + /* 1 */ "YEAR", + /* 2 */ "MONTH", + /* 3 */ "WEEK_OF_YEAR", + /* 4 */ "WEEK_OF_MONTH", + /* 5 */ "DAY_OF_MONTH", + /* 6 */ "DAY_OF_YEAR", + /* 7 */ "DAY_OF_WEEK", + /* 8 */ "DAY_OF_WEEK_IN_MONTH", + /* 9 */ "AM_PM", + /* 10 */ "HOUR", + /* 11 */ "HOUR_OF_DAY", + /* 12 */ "MINUTE", + /* 13 */ "SECOND", + /* 14 */ "MILLISECOND", + /* 15 */ "ZONE_OFFSET", + /* 16 */ "DST_OFFSET"}; // Verify that the fields are as expected (mostly zero) at the epoch start. // Note that we adjust for the default timezone to get most things to zero. public void TestEpochStartFields() { String[][] lt = { - {"en", "US", "US/Pacific"}, /* First day = 1, Minimum day = 1 */ - {"en", "US", "America/Anchorage"}, /* First day = 1, Minimum day = 1 */ - {"en", "TO", "Pacific/Tongatapu"}, /* First day = 1, Minimum day = 1 */ - {"en", "MH", "Pacific/Majuro"}, /* First day = 1, Minimum day = 1 */ - {"ja", "JP", "Asia/Tokyo"}, /* First day = 1, Minimum day = 1 */ - {"iw", "IL", "Asia/Jerusalem"}, /* First day = 1, Minimum day = 1 */ - {"hi", "IN", "Asia/Jakarta"}, /* First day = 1, Minimum day = 1 */ - {"en", "GB", "Europe/London"}, /* First day = 2, Minimum day = 1 */ - {"en", "GB", "GMT"}, /* First day = 2, Minimum day = 1 */ - {"de", "DE", "Europe/Berlin"}, /* First day = 2, Minimum day = 4 */ - {"ar", "EG", "Africa/Cairo"}, /* First day = 7, Minimum day = 1 */ - }; + {"en", "US", "US/Pacific"}, /* First day = 1, Minimum day = 1 */ + {"en", "US", "America/Anchorage"}, /* First day = 1, Minimum day = 1 */ + {"en", "TO", "Pacific/Tongatapu"}, /* First day = 1, Minimum day = 1 */ + {"en", "MH", "Pacific/Majuro"}, /* First day = 1, Minimum day = 1 */ + {"ja", "JP", "Asia/Tokyo"}, /* First day = 1, Minimum day = 1 */ + {"iw", "IL", "Asia/Jerusalem"}, /* First day = 1, Minimum day = 1 */ + {"hi", "IN", "Asia/Jakarta"}, /* First day = 1, Minimum day = 1 */ + {"en", "GB", "Europe/London"}, /* First day = 2, Minimum day = 1 */ + {"en", "GB", "GMT"}, /* First day = 2, Minimum day = 1 */ + {"de", "DE", "Europe/Berlin"}, /* First day = 2, Minimum day = 4 */ + {"ar", "EG", "Africa/Cairo"}}; /* First day = 7, Minimum day = 1 */ int[][] goldenData = { - {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, -28800000, 0}, - {1, 1969, 11, 1, 5, 31, 365, 4, 5, 1, 11, 23, 0, 0, 0, -36000000, 0}, - {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 46800000, 0}, - {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 43200000, 0}, - {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 32400000, 0}, - {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 7200000, 0}, - {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 25200000, 0}, - {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 1, 1, 0, 0, 0, 3600000, 0}, - {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 3600000, 0}, - {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 7200000, 0}, - }; + {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, -28800000, 0}, + {1, 1969, 11, 1, 5, 31, 365, 4, 5, 1, 11, 23, 0, 0, 0, -36000000, 0}, + {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 46800000, 0}, + {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 43200000, 0}, + {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 32400000, 0}, + {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 7200000, 0}, + {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 25200000, 0}, + {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 1, 1, 0, 0, 0, 3600000, 0}, + {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0}, + {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 3600000, 0}, + {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 7200000, 0}}; Locale savedLocale = Locale.getDefault(); TimeZone savedTimeZone = TimeZone.getDefault(); @@ -927,19 +986,18 @@ boolean err = false; for (int i = 0; i < calendarFieldNames.length; ++i) { if ((val = c.get(i)) != EPOCH_FIELDS[i]) { - errln("Wrong value: " + val + - " for field(" + calendarFieldNames[i] + - "), expected: " + EPOCH_FIELDS[i]); + errln("Wrong value: " + val + + " for field(" + calendarFieldNames[i] + + "), expected: " + EPOCH_FIELDS[i]); err = true; } } if (err) { - errln("Failed: \n\tDate=" + d + "\n\tTimeZone=" + z + - "\n\tLocale=" + l + "\n\tCalendar=" + c); + errln("Failed: \n\tDate=" + d + "\n\tTimeZone=" + z + + "\n\tLocale=" + l + "\n\tCalendar=" + c); } } - } - finally { + } finally { Locale.setDefault(savedLocale); TimeZone.setDefault(savedTimeZone); } @@ -948,125 +1006,146 @@ // Verify that as you add days to the calendar (e.g., 24 day periods), // the day of the week shifts in the expected pattern. public void TestDOWProgression() { - Calendar cal = - new GregorianCalendar(1972, Calendar.OCTOBER, 26); + Calendar cal + = new GregorianCalendar(1972, OCTOBER, 26); marchByDelta(cal, 24); // Last parameter must be != 0 modulo 7 } // Supply a delta which is not a multiple of 7. void marchByDelta(Calendar cal, int delta) { - Calendar cur = (Calendar)cal.clone(); - int initialDOW = cur.get(Calendar.DAY_OF_WEEK); + Calendar cur = (Calendar) cal.clone(); + int initialDOW = cur.get(DAY_OF_WEEK); int DOW, newDOW = initialDOW; do { DOW = newDOW; logln("DOW = " + DOW + " " + cur.getTime()); - cur.add(Calendar.DAY_OF_WEEK, delta); - newDOW = cur.get(Calendar.DAY_OF_WEEK); + cur.add(DAY_OF_WEEK, delta); + newDOW = cur.get(DAY_OF_WEEK); int expectedDOW = 1 + (DOW + delta - 1) % 7; if (newDOW != expectedDOW) { - errln("Day of week should be " + expectedDOW + - " instead of " + newDOW + " on " + cur.getTime()); + errln("Day of week should be " + expectedDOW + + " instead of " + newDOW + " on " + cur.getTime()); return; } - } - while (newDOW != initialDOW); + } while (newDOW != initialDOW); } public void TestActualMinMax() { - Calendar cal = new GregorianCalendar(1967, Calendar.MARCH, 10); - cal.setFirstDayOfWeek(Calendar.SUNDAY); + Calendar cal = new GregorianCalendar(1967, MARCH, 10); + cal.setFirstDayOfWeek(SUNDAY); cal.setMinimalDaysInFirstWeek(3); - if (cal.getActualMinimum(Calendar.DAY_OF_MONTH) != 1) - errln("Actual minimum date for 3/10/1967 should have been 1; got " + - cal.getActualMinimum(Calendar.DAY_OF_MONTH)); - if (cal.getActualMaximum(Calendar.DAY_OF_MONTH) != 31) - errln("Actual maximum date for 3/10/1967 should have been 31; got " + - cal.getActualMaximum(Calendar.DAY_OF_MONTH)); + if (cal.getActualMinimum(DAY_OF_MONTH) != 1) { + errln("Actual minimum date for 3/10/1967 should have been 1; got " + + cal.getActualMinimum(DAY_OF_MONTH)); + } + if (cal.getActualMaximum(DAY_OF_MONTH) != 31) { + errln("Actual maximum date for 3/10/1967 should have been 31; got " + + cal.getActualMaximum(DAY_OF_MONTH)); + } - cal.set(Calendar.MONTH, Calendar.FEBRUARY); - if (cal.getActualMaximum(Calendar.DAY_OF_MONTH) != 28) - errln("Actual maximum date for 2/10/1967 should have been 28; got " + - cal.getActualMaximum(Calendar.DAY_OF_MONTH)); - if (cal.getActualMaximum(Calendar.DAY_OF_YEAR) != 365) - errln("Number of days in 1967 should have been 365; got " + - cal.getActualMaximum(Calendar.DAY_OF_YEAR)); + cal.set(MONTH, FEBRUARY); + if (cal.getActualMaximum(DAY_OF_MONTH) != 28) { + errln("Actual maximum date for 2/10/1967 should have been 28; got " + + cal.getActualMaximum(DAY_OF_MONTH)); + } + if (cal.getActualMaximum(DAY_OF_YEAR) != 365) { + errln("Number of days in 1967 should have been 365; got " + + cal.getActualMaximum(DAY_OF_YEAR)); + } - cal.set(Calendar.YEAR, 1968); - if (cal.getActualMaximum(Calendar.DAY_OF_MONTH) != 29) - errln("Actual maximum date for 2/10/1968 should have been 29; got " + - cal.getActualMaximum(Calendar.DAY_OF_MONTH)); - if (cal.getActualMaximum(Calendar.DAY_OF_YEAR) != 366) - errln("Number of days in 1968 should have been 366; got " + - cal.getActualMaximum(Calendar.DAY_OF_YEAR)); + cal.set(YEAR, 1968); + if (cal.getActualMaximum(DAY_OF_MONTH) != 29) { + errln("Actual maximum date for 2/10/1968 should have been 29; got " + + cal.getActualMaximum(DAY_OF_MONTH)); + } + if (cal.getActualMaximum(DAY_OF_YEAR) != 366) { + errln("Number of days in 1968 should have been 366; got " + + cal.getActualMaximum(DAY_OF_YEAR)); + } // Using week settings of SUNDAY/3 (see above) - if (cal.getActualMaximum(Calendar.WEEK_OF_YEAR) != 52) - errln("Number of weeks in 1968 should have been 52; got " + - cal.getActualMaximum(Calendar.WEEK_OF_YEAR)); + if (cal.getActualMaximum(WEEK_OF_YEAR) != 52) { + errln("Number of weeks in 1968 should have been 52; got " + + cal.getActualMaximum(WEEK_OF_YEAR)); + } - cal.set(Calendar.YEAR, 1976); + cal.set(YEAR, 1976); // Using week settings of SUNDAY/3 (see above) - if (cal.getActualMaximum(Calendar.WEEK_OF_YEAR) != 53) - errln("Number of weeks in 1976 should have been 53; got " + - cal.getActualMaximum(Calendar.WEEK_OF_YEAR)); + if (cal.getActualMaximum(WEEK_OF_YEAR) != 53) { + errln("Number of weeks in 1976 should have been 53; got " + + cal.getActualMaximum(WEEK_OF_YEAR)); + } } public void TestRoll() { - Calendar cal = new GregorianCalendar(1997, Calendar.JANUARY, 31); + Calendar cal = new GregorianCalendar(1997, JANUARY, 31); - int[] dayValues = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31 }; + int[] dayValues = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31}; for (int i = 0; i < dayValues.length; i++) { - Calendar cal2 = (Calendar)cal.clone(); - cal2.roll(Calendar.MONTH, i); - if (cal2.get(Calendar.DAY_OF_MONTH) != dayValues[i]) + Calendar cal2 = (Calendar) cal.clone(); + cal2.roll(MONTH, i); + if (cal2.get(DAY_OF_MONTH) != dayValues[i]) { errln("Rolling the month in 1/31/1997 up by " + i + " should have yielded " - + ((i + 1) % 12) + "/" + dayValues[i] + "/1997, but actually yielded " - + ((i + 1) % 12) + "/" + cal2.get(Calendar.DAY_OF_MONTH) + "/1997."); + + ((i + 1) % 12) + "/" + dayValues[i] + "/1997, but actually yielded " + + ((i + 1) % 12) + "/" + cal2.get(DAY_OF_MONTH) + "/1997."); + } } - cal.set(1996, Calendar.FEBRUARY, 29); + cal.set(1996, FEBRUARY, 29); - int[] monthValues = { 1, 2, 2, 2, 1, 2, 2, 2, 1, 2 }; - int[] dayValues2 = { 29, 1, 1, 1, 29, 1, 1, 1, 29, 1 }; + int[] monthValues = {1, 2, 2, 2, 1, 2, 2, 2, 1, 2}; + int[] dayValues2 = {29, 1, 1, 1, 29, 1, 1, 1, 29, 1}; for (int i = 0; i < dayValues2.length; i++) { - Calendar cal2 = (Calendar)cal.clone(); - cal2.roll(Calendar.YEAR, i); - if (cal2.get(Calendar.DAY_OF_MONTH) != dayValues2[i] || cal2.get(Calendar.MONTH) - != monthValues[i]) + Calendar cal2 = (Calendar) cal.clone(); + cal2.roll(YEAR, i); + if (cal2.get(DAY_OF_MONTH) != dayValues2[i] || cal2.get(MONTH) + != monthValues[i]) { errln("Rolling the year in 2/29/1996 up by " + i + " should have yielded " - + (monthValues[i] + 1) + "/" + dayValues2[i] + "/" - + (1996 + i) + ", but actually yielded " - + (cal2.get(Calendar.MONTH) + 1) + "/" + - cal2.get(Calendar.DAY_OF_MONTH) + "/" + (1996 + i) + "."); + + (monthValues[i] + 1) + "/" + dayValues2[i] + "/" + + (1996 + i) + ", but actually yielded " + + (cal2.get(MONTH) + 1) + "/" + + cal2.get(DAY_OF_MONTH) + "/" + (1996 + i) + "."); + } } // Test rolling hour of day - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.roll(Calendar.HOUR_OF_DAY, -2); - int f = cal.get(Calendar.HOUR_OF_DAY); - if (f != 22) errln("Rolling HOUR_OF_DAY=0 delta=-2 gave " + f + " Wanted 22"); - cal.roll(Calendar.HOUR_OF_DAY, 5); - f = cal.get(Calendar.HOUR_OF_DAY); - if (f != 3) errln("Rolling HOUR_OF_DAY=22 delta=5 gave " + f + " Wanted 3"); - cal.roll(Calendar.HOUR_OF_DAY, 21); - f = cal.get(Calendar.HOUR_OF_DAY); - if (f != 0) errln("Rolling HOUR_OF_DAY=3 delta=21 gave " + f + " Wanted 0"); + cal.set(HOUR_OF_DAY, 0); + cal.roll(HOUR_OF_DAY, -2); + int f = cal.get(HOUR_OF_DAY); + if (f != 22) { + errln("Rolling HOUR_OF_DAY=0 delta=-2 gave " + f + " Wanted 22"); + } + cal.roll(HOUR_OF_DAY, 5); + f = cal.get(HOUR_OF_DAY); + if (f != 3) { + errln("Rolling HOUR_OF_DAY=22 delta=5 gave " + f + " Wanted 3"); + } + cal.roll(HOUR_OF_DAY, 21); + f = cal.get(HOUR_OF_DAY); + if (f != 0) { + errln("Rolling HOUR_OF_DAY=3 delta=21 gave " + f + " Wanted 0"); + } // Test rolling hour - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.roll(Calendar.HOUR, -2); - f = cal.get(Calendar.HOUR); - if (f != 10) errln("Rolling HOUR=0 delta=-2 gave " + f + " Wanted 10"); - cal.roll(Calendar.HOUR, 5); - f = cal.get(Calendar.HOUR); - if (f != 3) errln("Rolling HOUR=10 delta=5 gave " + f + " Wanted 3"); - cal.roll(Calendar.HOUR, 9); - f = cal.get(Calendar.HOUR); - if (f != 0) errln("Rolling HOUR=3 delta=9 gave " + f + " Wanted 0"); + cal.set(HOUR_OF_DAY, 0); + cal.roll(HOUR, -2); + f = cal.get(HOUR); + if (f != 10) { + errln("Rolling HOUR=0 delta=-2 gave " + f + " Wanted 10"); + } + cal.roll(HOUR, 5); + f = cal.get(HOUR); + if (f != 3) { + errln("Rolling HOUR=10 delta=5 gave " + f + " Wanted 3"); + } + cal.roll(HOUR, 9); + f = cal.get(HOUR); + if (f != 0) { + errln("Rolling HOUR=3 delta=9 gave " + f + " Wanted 0"); + } } /* @@ -1081,19 +1160,18 @@ TimeZone.setDefault(TimeZone.getTimeZone("PST")); Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, 2001); - cal.set(Calendar.MONTH, Calendar.OCTOBER); - cal.set(Calendar.WEEK_OF_YEAR, 4); - cal.set(Calendar.DAY_OF_WEEK, 2); + cal.set(YEAR, 2001); + cal.set(MONTH, OCTOBER); + cal.set(WEEK_OF_YEAR, 4); + cal.set(DAY_OF_WEEK, 2); - if (cal.get(Calendar.YEAR) != 2001 || - cal.get(Calendar.MONTH) != Calendar.JANUARY || - cal.get(Calendar.DATE) != 22 || - cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { + if (cal.get(YEAR) != 2001 + || cal.get(MONTH) != JANUARY + || cal.get(DATE) != 22 + || cal.get(DAY_OF_WEEK) != MONDAY) { errln("Failed : got " + cal.getTime() + ", expected Mon Jan 22, 2001"); } - } - finally { + } finally { Locale.setDefault(savedLocale); TimeZone.setDefault(savedTimeZone); }
--- a/jdk/test/java/util/Calendar/CalendarTypeTest.java Mon Nov 21 15:04:37 2016 -0800 +++ b/jdk/test/java/util/Calendar/CalendarTypeTest.java Tue Nov 22 11:46:06 2016 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,9 +27,13 @@ * @summary Unit test for calendar types */ -import java.util.*; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.Set; public class CalendarTypeTest { + // Calendar types supported in JRE static Locale[] locales = new Locale[] { Locale.US, @@ -37,23 +41,20 @@ new Locale("th", "TH"), Locale.forLanguageTag("en-US-u-ca-buddhist"), new Locale("ja", "JP", "JP"), - Locale.forLanguageTag("en-US-u-ca-japanese"), - }; + Locale.forLanguageTag("en-US-u-ca-japanese")}; static final String[] TYPES = new String[] { "gregory", "buddhist", - "japanese", - }; + "japanese"}; static final String[] ALIASES = new String[] { "gregorian", - "iso8601", - }; + "iso8601"}; public static void main(String[] args) { for (int i = 0; i < locales.length; i++) { Calendar cal = Calendar.getInstance(locales[i]); String type = cal.getCalendarType(); - checkValue("bad calendar type", type, TYPES[i/2]); + checkValue("bad calendar type", type, TYPES[i / 2]); } GregorianCalendar gcal = new GregorianCalendar(); @@ -88,10 +89,13 @@ }