# HG changeset patch # User jwilhelm # Date 1417432097 -3600 # Node ID 5bec79a6bbcaaf411c85aae0dd710a0b904e3fc1 # Parent c8bb28d304187d3b2e16a80668fe7e34fd79806e# Parent a5647c0449230cbbb19850f1d10acd4133428aad Merge diff -r a5647c044923 -r 5bec79a6bbca jdk/make/gensrc/GensrcProperties.gmk --- a/jdk/make/gensrc/GensrcProperties.gmk Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/make/gensrc/GensrcProperties.gmk Mon Dec 01 12:08:17 2014 +0100 @@ -58,13 +58,15 @@ $1_CLASS := $3 # Convert .../src//share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties - # to .../langtools/gensrc//com/sun/tools/javac/resources/javac_zh_CN.java + # to .../support/gensrc//com/sun/tools/javac/resources/javac_zh_CN.java # Strip away prefix and suffix, leaving for example only: # "/share/classes/com/sun/tools/javac/resources/javac_zh_CN" $1_JAVAS := $$(patsubst $(JDK_TOPDIR)/src/%, \ $(JDK_OUTPUTDIR)/gensrc/%, \ $$(patsubst %.properties, %.java, \ - $$(subst /share/classes,, $$($1_SRCS)))) + $$(subst /$(OPENJDK_TARGET_OS)/classes,, \ + $$(subst /$(OPENJDK_TARGET_OS_TYPE)/classes,, \ + $$(subst /share/classes,, $$($1_SRCS)))))) # Generate the package dirs for the to be generated java files. Sort to remove # duplicates. diff -r a5647c044923 -r 5bec79a6bbca jdk/make/launcher/Launcher-jdk.runtime.gmk --- a/jdk/make/launcher/Launcher-jdk.runtime.gmk Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/make/launcher/Launcher-jdk.runtime.gmk Mon Dec 01 12:08:17 2014 +0100 @@ -77,7 +77,7 @@ EXE_OUT_OPTION := -Fe # With the current way unpack200 is built, debug symbols aren't supported # anyway. - UNPACKEXE_DEBUG_SYMBOLS := + UNPACKEXE_DEBUG_SYMBOLS := false endif # The linker on older SuSE distros (e.g. on SLES 10) complains with: diff -r a5647c044923 -r 5bec79a6bbca jdk/make/lib/LibCommon.gmk --- a/jdk/make/lib/LibCommon.gmk Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/make/lib/LibCommon.gmk Mon Dec 01 12:08:17 2014 +0100 @@ -45,15 +45,17 @@ # elegant solution to this. WIN_JAVA_LIB := $(JDK_OUTPUTDIR)/objs/libjava/java.lib -# Use this variable to set DEBUG_SYMBOLS true on windows for all libraries, but -# not on other platforms. -ifeq ($(OPENJDK_TARGET_OS), windows) +ifdef OPENJDK + # Build everything with debugging on OpenJDK DEBUG_ALL_BINARIES := true -endif - -# Build everything with debugging on OpenJDK -ifdef OPENJDK - DEBUG_ALL_BINARIES := true +else + # Use this variable to set DEBUG_SYMBOLS true on windows for all libraries, but + # not on other platforms. + ifeq ($(OPENJDK_TARGET_OS), windows) + DEBUG_ALL_BINARIES := true + else + DEBUG_ALL_BINARIES := false + endif endif ################################################################################ diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.base/share/classes/java/lang/Thread.java --- a/jdk/src/java.base/share/classes/java/lang/Thread.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.base/share/classes/java/lang/Thread.java Mon Dec 01 12:08:17 2014 +0100 @@ -145,7 +145,7 @@ registerNatives(); } - private volatile char name[]; + private volatile String name; private int priority; private Thread threadQ; private long eetop; @@ -366,7 +366,7 @@ throw new NullPointerException("name cannot be null"); } - this.name = name.toCharArray(); + this.name = name; Thread parent = currentThread(); SecurityManager security = System.getSecurityManager(); @@ -1119,7 +1119,11 @@ */ public final synchronized void setName(String name) { checkAccess(); - this.name = name.toCharArray(); + if (name == null) { + throw new NullPointerException("name cannot be null"); + } + + this.name = name; if (threadStatus != 0) { setNativeName(name); } @@ -1132,7 +1136,7 @@ * @see #setName(String) */ public final String getName() { - return new String(name, true); + return name; } /** diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java --- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java Mon Dec 01 12:08:17 2014 +0100 @@ -867,15 +867,11 @@ MethodType postSpreadType = asSpreaderChecks(arrayType, arrayLength); int arity = type().parameterCount(); int spreadArgPos = arity - arrayLength; - if (USE_LAMBDA_FORM_EDITOR) { - MethodHandle afterSpread = this.asType(postSpreadType); - BoundMethodHandle mh = afterSpread.rebind(); - LambdaForm lform = mh.editor().spreadArgumentsForm(1 + spreadArgPos, arrayType, arrayLength); - MethodType preSpreadType = postSpreadType.replaceParameterTypes(spreadArgPos, arity, arrayType); - return mh.copyWith(preSpreadType, lform); - } else { - return MethodHandleImpl.makeSpreadArguments(this, arrayType, spreadArgPos, arrayLength); - } + MethodHandle afterSpread = this.asType(postSpreadType); + BoundMethodHandle mh = afterSpread.rebind(); + LambdaForm lform = mh.editor().spreadArgumentsForm(1 + spreadArgPos, arrayType, arrayLength); + MethodType preSpreadType = postSpreadType.replaceParameterTypes(spreadArgPos, arity, arrayType); + return mh.copyWith(preSpreadType, lform); } /** @@ -996,23 +992,15 @@ public MethodHandle asCollector(Class arrayType, int arrayLength) { asCollectorChecks(arrayType, arrayLength); int collectArgPos = type().parameterCount() - 1; - if (USE_LAMBDA_FORM_EDITOR) { - BoundMethodHandle mh = rebind(); - MethodType resultType = type().asCollectorType(arrayType, arrayLength); - MethodHandle newArray = MethodHandleImpl.varargsArray(arrayType, arrayLength); - LambdaForm lform = mh.editor().collectArgumentArrayForm(1 + collectArgPos, newArray); - if (lform != null) { - return mh.copyWith(resultType, lform); - } - lform = mh.editor().collectArgumentsForm(1 + collectArgPos, newArray.type().basicType()); - return mh.copyWithExtendL(resultType, lform, newArray); - } else { - MethodHandle target = this; - if (arrayType != type().parameterType(collectArgPos)) - target = MethodHandleImpl.makePairwiseConvert(this, type().changeParameterType(collectArgPos, arrayType), true); - MethodHandle collector = MethodHandleImpl.varargsArray(arrayType, arrayLength); - return MethodHandles.collectArguments(target, collectArgPos, collector); + BoundMethodHandle mh = rebind(); + MethodType resultType = type().asCollectorType(arrayType, arrayLength); + MethodHandle newArray = MethodHandleImpl.varargsArray(arrayType, arrayLength); + LambdaForm lform = mh.editor().collectArgumentArrayForm(1 + collectArgPos, newArray); + if (lform != null) { + return mh.copyWith(resultType, lform); } + lform = mh.editor().collectArgumentsForm(1 + collectArgPos, newArray.type().basicType()); + return mh.copyWithExtendL(resultType, lform, newArray); } /** diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java --- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java Mon Dec 01 12:08:17 2014 +0100 @@ -191,11 +191,7 @@ MethodType dstType = target.type(); if (srcType == dstType) return target; - if (USE_LAMBDA_FORM_EDITOR) { - return makePairwiseConvertByEditor(target, srcType, strict, monobox); - } else { - return makePairwiseConvertIndirect(target, srcType, strict, monobox); - } + return makePairwiseConvertByEditor(target, srcType, strict, monobox); } private static int countNonNull(Object[] array) { diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java --- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java Mon Dec 01 12:08:17 2014 +0100 @@ -45,23 +45,21 @@ static final boolean DUMP_CLASS_FILES; static final boolean TRACE_INTERPRETER; static final boolean TRACE_METHOD_LINKAGE; - static final boolean USE_LAMBDA_FORM_EDITOR; static final int COMPILE_THRESHOLD; static final int DONT_INLINE_THRESHOLD; static final int PROFILE_LEVEL; static { - final Object[] values = new Object[8]; + final Object[] values = new Object[7]; AccessController.doPrivileged(new PrivilegedAction() { public Void run() { values[0] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DEBUG_NAMES"); values[1] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DUMP_CLASS_FILES"); values[2] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_INTERPRETER"); values[3] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE"); - values[4] = Boolean.getBoolean("java.lang.invoke.MethodHandle.USE_LF_EDITOR"); - values[5] = Integer.getInteger("java.lang.invoke.MethodHandle.COMPILE_THRESHOLD", 30); - values[6] = Integer.getInteger("java.lang.invoke.MethodHandle.DONT_INLINE_THRESHOLD", 30); - values[7] = Integer.getInteger("java.lang.invoke.MethodHandle.PROFILE_LEVEL", 0); + values[4] = Integer.getInteger("java.lang.invoke.MethodHandle.COMPILE_THRESHOLD", 0); + values[5] = Integer.getInteger("java.lang.invoke.MethodHandle.DONT_INLINE_THRESHOLD", 30); + values[6] = Integer.getInteger("java.lang.invoke.MethodHandle.PROFILE_LEVEL", 0); return null; } }); @@ -69,10 +67,9 @@ DUMP_CLASS_FILES = (Boolean) values[1]; TRACE_INTERPRETER = (Boolean) values[2]; TRACE_METHOD_LINKAGE = (Boolean) values[3]; - USE_LAMBDA_FORM_EDITOR = (Boolean) values[4]; - COMPILE_THRESHOLD = (Integer) values[5]; - DONT_INLINE_THRESHOLD = (Integer) values[6]; - PROFILE_LEVEL = (Integer) values[7]; + COMPILE_THRESHOLD = (Integer) values[4]; + DONT_INLINE_THRESHOLD = (Integer) values[5]; + PROFILE_LEVEL = (Integer) values[6]; } /** Tell if any of the debugging switches are turned on. diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java --- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java Mon Dec 01 12:08:17 2014 +0100 @@ -2103,115 +2103,65 @@ reorder = reorder.clone(); // get a private copy MethodType oldType = target.type(); permuteArgumentChecks(reorder, newType, oldType); - if (USE_LAMBDA_FORM_EDITOR) { - // first detect dropped arguments and handle them separately - int[] originalReorder = reorder; - BoundMethodHandle result = target.rebind(); - LambdaForm form = result.form; - int newArity = newType.parameterCount(); - // Normalize the reordering into a real permutation, - // by removing duplicates and adding dropped elements. - // This somewhat improves lambda form caching, as well - // as simplifying the transform by breaking it up into steps. - for (int ddIdx; (ddIdx = findFirstDupOrDrop(reorder, newArity)) != 0; ) { - if (ddIdx > 0) { - // We found a duplicated entry at reorder[ddIdx]. - // Example: (x,y,z)->asList(x,y,z) - // permuted by [1*,0,1] => (a0,a1)=>asList(a1,a0,a1) - // permuted by [0,1,0*] => (a0,a1)=>asList(a0,a1,a0) - // The starred element corresponds to the argument - // deleted by the dupArgumentForm transform. - int srcPos = ddIdx, dstPos = srcPos, dupVal = reorder[srcPos]; - boolean killFirst = false; - for (int val; (val = reorder[--dstPos]) != dupVal; ) { - // Set killFirst if the dup is larger than an intervening position. - // This will remove at least one inversion from the permutation. - if (dupVal > val) killFirst = true; - } - if (!killFirst) { - srcPos = dstPos; - dstPos = ddIdx; - } - form = form.editor().dupArgumentForm(1 + srcPos, 1 + dstPos); - assert (reorder[srcPos] == reorder[dstPos]); - oldType = oldType.dropParameterTypes(dstPos, dstPos + 1); - // contract the reordering by removing the element at dstPos - int tailPos = dstPos + 1; - System.arraycopy(reorder, tailPos, reorder, dstPos, reorder.length - tailPos); - reorder = Arrays.copyOf(reorder, reorder.length - 1); - } else { - int dropVal = ~ddIdx, insPos = 0; - while (insPos < reorder.length && reorder[insPos] < dropVal) { - // Find first element of reorder larger than dropVal. - // This is where we will insert the dropVal. - insPos += 1; - } - Class ptype = newType.parameterType(dropVal); - form = form.editor().addArgumentForm(1 + insPos, BasicType.basicType(ptype)); - oldType = oldType.insertParameterTypes(insPos, ptype); - // expand the reordering by inserting an element at insPos - int tailPos = insPos + 1; - reorder = Arrays.copyOf(reorder, reorder.length + 1); - System.arraycopy(reorder, insPos, reorder, tailPos, reorder.length - tailPos); - reorder[insPos] = dropVal; + // first detect dropped arguments and handle them separately + int[] originalReorder = reorder; + BoundMethodHandle result = target.rebind(); + LambdaForm form = result.form; + int newArity = newType.parameterCount(); + // Normalize the reordering into a real permutation, + // by removing duplicates and adding dropped elements. + // This somewhat improves lambda form caching, as well + // as simplifying the transform by breaking it up into steps. + for (int ddIdx; (ddIdx = findFirstDupOrDrop(reorder, newArity)) != 0; ) { + if (ddIdx > 0) { + // We found a duplicated entry at reorder[ddIdx]. + // Example: (x,y,z)->asList(x,y,z) + // permuted by [1*,0,1] => (a0,a1)=>asList(a1,a0,a1) + // permuted by [0,1,0*] => (a0,a1)=>asList(a0,a1,a0) + // The starred element corresponds to the argument + // deleted by the dupArgumentForm transform. + int srcPos = ddIdx, dstPos = srcPos, dupVal = reorder[srcPos]; + boolean killFirst = false; + for (int val; (val = reorder[--dstPos]) != dupVal; ) { + // Set killFirst if the dup is larger than an intervening position. + // This will remove at least one inversion from the permutation. + if (dupVal > val) killFirst = true; } - assert (permuteArgumentChecks(reorder, newType, oldType)); + if (!killFirst) { + srcPos = dstPos; + dstPos = ddIdx; + } + form = form.editor().dupArgumentForm(1 + srcPos, 1 + dstPos); + assert (reorder[srcPos] == reorder[dstPos]); + oldType = oldType.dropParameterTypes(dstPos, dstPos + 1); + // contract the reordering by removing the element at dstPos + int tailPos = dstPos + 1; + System.arraycopy(reorder, tailPos, reorder, dstPos, reorder.length - tailPos); + reorder = Arrays.copyOf(reorder, reorder.length - 1); + } else { + int dropVal = ~ddIdx, insPos = 0; + while (insPos < reorder.length && reorder[insPos] < dropVal) { + // Find first element of reorder larger than dropVal. + // This is where we will insert the dropVal. + insPos += 1; + } + Class ptype = newType.parameterType(dropVal); + form = form.editor().addArgumentForm(1 + insPos, BasicType.basicType(ptype)); + oldType = oldType.insertParameterTypes(insPos, ptype); + // expand the reordering by inserting an element at insPos + int tailPos = insPos + 1; + reorder = Arrays.copyOf(reorder, reorder.length + 1); + System.arraycopy(reorder, insPos, reorder, tailPos, reorder.length - tailPos); + reorder[insPos] = dropVal; } - assert (reorder.length == newArity); // a perfect permutation - // Note: This may cache too many distinct LFs. Consider backing off to varargs code. - form = form.editor().permuteArgumentsForm(1, reorder); - if (newType == result.type() && form == result.internalForm()) - return result; - return result.copyWith(newType, form); - } else { - // first detect dropped arguments and handle them separately - MethodHandle originalTarget = target; - int newArity = newType.parameterCount(); - for (int dropIdx; (dropIdx = findFirstDrop(reorder, newArity)) >= 0; ) { - // dropIdx is missing from reorder; add it in at the end - int oldArity = reorder.length; - target = dropArguments(target, oldArity, newType.parameterType(dropIdx)); - reorder = Arrays.copyOf(reorder, oldArity + 1); - reorder[oldArity] = dropIdx; - } - assert(target == originalTarget || permuteArgumentChecks(reorder, newType, target.type())); - // Note: This may cache too many distinct LFs. Consider backing off to varargs code. - BoundMethodHandle result = target.rebind(); - LambdaForm form = result.form.permuteArguments(1, reorder, basicTypes(newType.parameterList())); - return result.copyWith(newType, form); + assert (permuteArgumentChecks(reorder, newType, oldType)); } - } - - /** Return the first value in [0..newArity-1] that is not present in reorder. */ - private static int findFirstDrop(int[] reorder, int newArity) { - final int BIT_LIMIT = 63; // max number of bits in bit mask - if (newArity < BIT_LIMIT) { - long mask = 0; - for (int arg : reorder) { - assert(arg < newArity); - mask |= (1L << arg); - } - if (mask == (1L << newArity) - 1) { - assert(Long.numberOfTrailingZeros(Long.lowestOneBit(~mask)) == newArity); - return -1; - } - // find first zero - long zeroBit = Long.lowestOneBit(~mask); - int zeroPos = Long.numberOfTrailingZeros(zeroBit); - assert(zeroPos < newArity); - return zeroPos; - } else { - BitSet mask = new BitSet(newArity); - for (int arg : reorder) { - assert (arg < newArity); - mask.set(arg); - } - int zeroPos = mask.nextClearBit(0); - assert(zeroPos <= newArity); - if (zeroPos == newArity) - return -1; - return zeroPos; - } + assert (reorder.length == newArity); // a perfect permutation + // Note: This may cache too many distinct LFs. Consider backing off to varargs code. + form = form.editor().permuteArgumentsForm(1, reorder); + if (newType == result.type() && form == result.internalForm()) + return result; + return result.copyWith(newType, form); } /** @@ -2502,13 +2452,9 @@ if (dropped == 0) return target; BoundMethodHandle result = target.rebind(); LambdaForm lform = result.form; - if (USE_LAMBDA_FORM_EDITOR) { - int insertFormArg = 1 + pos; - for (Class ptype : valueTypes) { - lform = lform.editor().addArgumentForm(insertFormArg++, BasicType.basicType(ptype)); - } - } else { - lform = lform.addArguments(pos, valueTypes); + int insertFormArg = 1 + pos; + for (Class ptype : valueTypes) { + lform = lform.editor().addArgumentForm(insertFormArg++, BasicType.basicType(ptype)); } result = result.copyWith(newType, lform); return result; @@ -2659,18 +2605,14 @@ /*non-public*/ static MethodHandle filterArgument(MethodHandle target, int pos, MethodHandle filter) { filterArgumentChecks(target, pos, filter); - if (USE_LAMBDA_FORM_EDITOR) { - MethodType targetType = target.type(); - MethodType filterType = filter.type(); - BoundMethodHandle result = target.rebind(); - Class newParamType = filterType.parameterType(0); - LambdaForm lform = result.editor().filterArgumentForm(1 + pos, BasicType.basicType(newParamType)); - MethodType newType = targetType.changeParameterType(pos, newParamType); - result = result.copyWithExtendL(newType, lform, filter); - return result; - } else { - return MethodHandleImpl.makeCollectArguments(target, filter, pos, false); - } + MethodType targetType = target.type(); + MethodType filterType = filter.type(); + BoundMethodHandle result = target.rebind(); + Class newParamType = filterType.parameterType(0); + LambdaForm lform = result.editor().filterArgumentForm(1 + pos, BasicType.basicType(newParamType)); + MethodType newType = targetType.changeParameterType(pos, newParamType); + result = result.copyWithExtendL(newType, lform, filter); + return result; } private static void filterArgumentsCheckArity(MethodHandle target, int pos, MethodHandle[] filters) { @@ -2797,21 +2739,17 @@ public static MethodHandle collectArguments(MethodHandle target, int pos, MethodHandle filter) { MethodType newType = collectArgumentsChecks(target, pos, filter); - if (USE_LAMBDA_FORM_EDITOR) { - MethodType collectorType = filter.type(); - BoundMethodHandle result = target.rebind(); - LambdaForm lform; - if (collectorType.returnType().isArray() && filter.intrinsicName() == Intrinsic.NEW_ARRAY) { - lform = result.editor().collectArgumentArrayForm(1 + pos, filter); - if (lform != null) { - return result.copyWith(newType, lform); - } + MethodType collectorType = filter.type(); + BoundMethodHandle result = target.rebind(); + LambdaForm lform; + if (collectorType.returnType().isArray() && filter.intrinsicName() == Intrinsic.NEW_ARRAY) { + lform = result.editor().collectArgumentArrayForm(1 + pos, filter); + if (lform != null) { + return result.copyWith(newType, lform); } - lform = result.editor().collectArgumentsForm(1 + pos, collectorType.basicType()); - return result.copyWithExtendL(newType, lform, filter); - } else { - return MethodHandleImpl.makeCollectArguments(target, filter, pos, false); } + lform = result.editor().collectArgumentsForm(1 + pos, collectorType.basicType()); + return result.copyWithExtendL(newType, lform, filter); } private static MethodType collectArgumentsChecks(MethodHandle target, int pos, MethodHandle filter) throws RuntimeException { @@ -2890,16 +2828,12 @@ MethodType targetType = target.type(); MethodType filterType = filter.type(); filterReturnValueChecks(targetType, filterType); - if (USE_LAMBDA_FORM_EDITOR) { - BoundMethodHandle result = target.rebind(); - BasicType rtype = BasicType.basicType(filterType.returnType()); - LambdaForm lform = result.editor().filterReturnForm(rtype, false); - MethodType newType = targetType.changeReturnType(filterType.returnType()); - result = result.copyWithExtendL(newType, lform, filter); - return result; - } else { - return MethodHandleImpl.makeCollectArguments(filter, target, 0, false); - } + BoundMethodHandle result = target.rebind(); + BasicType rtype = BasicType.basicType(filterType.returnType()); + LambdaForm lform = result.editor().filterReturnForm(rtype, false); + MethodType newType = targetType.changeReturnType(filterType.returnType()); + result = result.copyWithExtendL(newType, lform, filter); + return result; } private static void filterReturnValueChecks(MethodType targetType, MethodType filterType) throws RuntimeException { @@ -2993,19 +2927,15 @@ MethodType targetType = target.type(); MethodType combinerType = combiner.type(); Class rtype = foldArgumentChecks(foldPos, targetType, combinerType); - if (USE_LAMBDA_FORM_EDITOR) { - BoundMethodHandle result = target.rebind(); - boolean dropResult = (rtype == void.class); - // Note: This may cache too many distinct LFs. Consider backing off to varargs code. - LambdaForm lform = result.editor().foldArgumentsForm(1 + foldPos, dropResult, combinerType.basicType()); - MethodType newType = targetType; - if (!dropResult) - newType = newType.dropParameterTypes(foldPos, foldPos + 1); - result = result.copyWithExtendL(newType, lform, combiner); - return result; - } else { - return MethodHandleImpl.makeCollectArguments(target, combiner, foldPos, true); - } + BoundMethodHandle result = target.rebind(); + boolean dropResult = (rtype == void.class); + // Note: This may cache too many distinct LFs. Consider backing off to varargs code. + LambdaForm lform = result.editor().foldArgumentsForm(1 + foldPos, dropResult, combinerType.basicType()); + MethodType newType = targetType; + if (!dropResult) + newType = newType.dropParameterTypes(foldPos, foldPos + 1); + result = result.copyWithExtendL(newType, lform, combiner); + return result; } private static Class foldArgumentChecks(int foldPos, MethodType targetType, MethodType combinerType) { diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.base/share/classes/java/nio/channels/spi/AbstractInterruptibleChannel.java --- a/jdk/src/java.base/share/classes/java/nio/channels/spi/AbstractInterruptibleChannel.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.base/share/classes/java/nio/channels/spi/AbstractInterruptibleChannel.java Mon Dec 01 12:08:17 2014 +0100 @@ -198,7 +198,7 @@ blockedOn(null); Thread interrupted = this.interrupted; if (interrupted != null && interrupted == Thread.currentThread()) { - interrupted = null; + this.interrupted = null; throw new ClosedByInterruptException(); } if (!completed && !open) diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.base/share/classes/java/security/KeyStore.java --- a/jdk/src/java.base/share/classes/java/security/KeyStore.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.base/share/classes/java/security/KeyStore.java Mon Dec 01 12:08:17 2014 +0100 @@ -416,7 +416,8 @@ /** * Retrieves the attributes associated with an entry. - *

+ * + * @implSpec * The default implementation returns an empty {@code Set}. * * @return an unmodifiable {@code Set} of attributes, possibly empty diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.base/share/classes/java/security/Principal.java --- a/jdk/src/java.base/share/classes/java/security/Principal.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.base/share/classes/java/security/Principal.java Mon Dec 01 12:08:17 2014 +0100 @@ -74,7 +74,8 @@ /** * Returns true if the specified subject is implied by this principal. * - *

The default implementation of this method returns true if + * @implSpec + * The default implementation of this method returns true if * {@code subject} is non-null and contains at least one principal that * is equal to this principal. * diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.base/share/classes/java/text/AttributedString.java --- a/jdk/src/java.base/share/classes/java/text/AttributedString.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.base/share/classes/java/text/AttributedString.java Mon Dec 01 12:08:17 2014 +0100 @@ -48,21 +48,18 @@ */ public class AttributedString { - - // since there are no vectors of int, we have to use arrays. - // We allocate them in chunks of 10 elements so we don't have to allocate all the time. - private static final int ARRAY_SIZE_INCREMENT = 10; - // field holding the text String text; - // fields holding run attribute information - // run attributes are organized by run - int runArraySize; // current size of the arrays - int runCount; // actual number of runs, <= runArraySize - int runStarts[]; // start index for each run - Vector runAttributes[]; // vector of attribute keys for each run - Vector runAttributeValues[]; // parallel vector of attribute values for each run + // Fields holding run attribute information. + // Run attributes are organized by run. + // Arrays are always of equal lengths (the current capacity). + // Since there are no vectors of int, we have to use arrays. + private static final int INITIAL_CAPACITY = 10; + int runCount; // actual number of runs, <= current capacity + int[] runStarts; // start index for each run + Vector[] runAttributes; // vector of attribute keys for each run + Vector[] runAttributeValues; // parallel vector of attribute values for each run /** * Constructs an AttributedString instance with the given @@ -416,18 +413,17 @@ private final void createRunAttributeDataVectors() { // use temporary variables so things remain consistent in case of an exception - int newRunStarts[] = new int[ARRAY_SIZE_INCREMENT]; + int[] newRunStarts = new int[INITIAL_CAPACITY]; @SuppressWarnings("unchecked") - Vector newRunAttributes[] = (Vector[]) new Vector[ARRAY_SIZE_INCREMENT]; + Vector[] newRunAttributes = (Vector[]) new Vector[INITIAL_CAPACITY]; @SuppressWarnings("unchecked") - Vector newRunAttributeValues[] = (Vector[]) new Vector[ARRAY_SIZE_INCREMENT]; + Vector[] newRunAttributeValues = (Vector[]) new Vector[INITIAL_CAPACITY]; runStarts = newRunStarts; runAttributes = newRunAttributes; runAttributeValues = newRunAttributeValues; - runArraySize = ARRAY_SIZE_INCREMENT; runCount = 1; // assume initial run starting at index 0 } @@ -465,25 +461,22 @@ // we'll have to break up a run // first, make sure we have enough space in our arrays - if (runCount == runArraySize) { - int newArraySize = runArraySize + ARRAY_SIZE_INCREMENT; - int newRunStarts[] = new int[newArraySize]; - - @SuppressWarnings("unchecked") - Vector newRunAttributes[] = (Vector[]) new Vector[newArraySize]; + int currentCapacity = runStarts.length; + if (runCount == currentCapacity) { + // We need to resize - we grow capacity by 25%. + int newCapacity = currentCapacity + (currentCapacity >> 2); - @SuppressWarnings("unchecked") - Vector newRunAttributeValues[] = (Vector[]) new Vector[newArraySize]; + // use temporary variables so things remain consistent in case of an exception + int[] newRunStarts = + Arrays.copyOf(runStarts, newCapacity); + Vector[] newRunAttributes = + Arrays.copyOf(runAttributes, newCapacity); + Vector[] newRunAttributeValues = + Arrays.copyOf(runAttributeValues, newCapacity); - for (int i = 0; i < runArraySize; i++) { - newRunStarts[i] = runStarts[i]; - newRunAttributes[i] = runAttributes[i]; - newRunAttributeValues[i] = runAttributeValues[i]; - } runStarts = newRunStarts; runAttributes = newRunAttributes; runAttributeValues = newRunAttributeValues; - runArraySize = newArraySize; } // make copies of the attribute information of the old run that the new one used to be part of diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.base/share/classes/javax/security/auth/Destroyable.java --- a/jdk/src/java.base/share/classes/javax/security/auth/Destroyable.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.base/share/classes/javax/security/auth/Destroyable.java Mon Dec 01 12:08:17 2014 +0100 @@ -41,7 +41,7 @@ * on this {@code Object} will result in an * {@code IllegalStateException} being thrown. * - *

+ * @implSpec * The default implementation throws {@code DestroyFailedException}. * * @exception DestroyFailedException if the destroy operation fails.

@@ -56,7 +56,7 @@ /** * Determine if this {@code Object} has been destroyed. * - *

+ * @implSpec * The default implementation returns false. * * @return true if this {@code Object} has been destroyed, diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.desktop/share/classes/META-INF/services/sun.datatransfer.DesktopDatatransferService --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/src/java.desktop/share/classes/META-INF/services/sun.datatransfer.DesktopDatatransferService Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,1 @@ +sun.awt.datatransfer.DesktopDatatransferServiceImpl diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.desktop/share/classes/java/awt/Window.java --- a/jdk/src/java.desktop/share/classes/java/awt/Window.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.desktop/share/classes/java/awt/Window.java Mon Dec 01 12:08:17 2014 +0100 @@ -2254,7 +2254,18 @@ } firePropertyChange("alwaysOnTop", oldAlwaysOnTop, alwaysOnTop); } - for (WeakReference ref : ownedWindowList) { + setOwnedWindowsAlwaysOnTop(alwaysOnTop); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + private void setOwnedWindowsAlwaysOnTop(boolean alwaysOnTop) { + WeakReference[] ownedWindowArray; + synchronized (ownedWindowList) { + ownedWindowArray = new WeakReference[ownedWindowList.size()]; + ownedWindowList.copyInto(ownedWindowArray); + } + + for (WeakReference ref : ownedWindowArray) { Window window = ref.get(); if (window != null) { try { diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java Mon Dec 01 12:08:17 2014 +0100 @@ -31,16 +31,14 @@ import javax.accessibility.AccessibleContext; import javax.swing.*; import javax.swing.plaf.*; -import javax.swing.border.*; import javax.swing.event.InternalFrameEvent; -import java.util.EventListener; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; -import java.beans.VetoableChangeListener; import java.beans.PropertyVetoException; import sun.swing.DefaultLookup; -import sun.swing.UIAction; + +import static sun.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY; /** * The class that manages a basic title bar @@ -215,6 +213,12 @@ createButtons(); addSubComponents(); + updateProperties(); + } + + private void updateProperties() { + final Object aaTextInfo = frame.getClientProperty(AA_TEXT_PROPERTY_KEY); + putClientProperty(AA_TEXT_PROPERTY_KEY, aaTextInfo); } /** diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTransferable.java --- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTransferable.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTransferable.java Mon Dec 01 12:08:17 2014 +0100 @@ -24,6 +24,8 @@ */ package javax.swing.plaf.basic; +import sun.datatransfer.DataFlavorUtil; + import java.io.*; import java.awt.datatransfer.*; import javax.swing.plaf.UIResource; @@ -145,7 +147,7 @@ } else if (Reader.class.equals(flavor.getRepresentationClass())) { return new StringReader(data); } else if (InputStream.class.equals(flavor.getRepresentationClass())) { - return new StringBufferInputStream(data); + return createInputStream(flavor, data); } // fall through to unsupported } else if (isPlainFlavor(flavor)) { @@ -156,7 +158,7 @@ } else if (Reader.class.equals(flavor.getRepresentationClass())) { return new StringReader(data); } else if (InputStream.class.equals(flavor.getRepresentationClass())) { - return new StringBufferInputStream(data); + return createInputStream(flavor, data); } // fall through to unsupported @@ -168,6 +170,15 @@ throw new UnsupportedFlavorException(flavor); } + private InputStream createInputStream(DataFlavor flavor, String data) + throws IOException, UnsupportedFlavorException { + String cs = DataFlavorUtil.getTextCharset(flavor); + if (cs == null) { + throw new UnsupportedFlavorException(flavor); + } + return new ByteArrayInputStream(data.getBytes(cs)); + } + // --- richer subclass flavors ---------------------------------------------- protected boolean isRicherFlavor(DataFlavor flavor) { diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.desktop/share/classes/sun/awt/datatransfer/META-INF/services/sun.datatransfer.DesktopDatatransferService --- a/jdk/src/java.desktop/share/classes/sun/awt/datatransfer/META-INF/services/sun.datatransfer.DesktopDatatransferService Mon Nov 24 20:00:44 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -sun.awt.datatransfer.DesktopDatatransferServiceImpl diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.logging/share/classes/java/util/logging/LogManager.java --- a/jdk/src/java.logging/share/classes/java/util/logging/LogManager.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.logging/share/classes/java/util/logging/LogManager.java Mon Dec 01 12:08:17 2014 +0100 @@ -31,6 +31,7 @@ import java.security.*; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; +import java.util.concurrent.CopyOnWriteArrayList; import sun.misc.JavaAWTAccess; import sun.misc.SharedSecrets; @@ -100,6 +101,19 @@ * Note that these Handlers may be created lazily, when they are * first used. * + *

  • A property "<logger>.handlers.ensureCloseOnReset". This defines a + * a boolean value. If "<logger>.handlers" is not defined or is empty, + * this property is ignored. Otherwise it defaults to {@code true}. When the + * value is {@code true}, the handlers associated with the logger are guaranteed + * to be closed on {@linkplain #reset} and shutdown. This can be turned off + * by explicitly setting "<logger>.handlers.ensureCloseOnReset=false" in + * the configuration. Note that turning this property off causes the risk of + * introducing a resource leak, as the logger may get garbage collected before + * {@code reset()} is called, thus preventing its handlers from being closed + * on {@code reset()}. In that case it is the responsibility of the application + * to ensure that the handlers are closed before the logger is garbage + * collected. + * *
  • A property "<logger>.useParentHandlers". This defines a boolean * value. By default every logger calls its parent in addition to * handling the logging message itself, this often result in messages @@ -169,6 +183,33 @@ // True if JVM death is imminent and the exit hook has been called. private boolean deathImminent; + // This list contains the loggers for which some handlers have been + // explicitly configured in the configuration file. + // It prevents these loggers from being arbitrarily garbage collected. + private static final class CloseOnReset { + private final Logger logger; + private CloseOnReset(Logger ref) { + this.logger = Objects.requireNonNull(ref); + } + @Override + public boolean equals(Object other) { + return (other instanceof CloseOnReset) && ((CloseOnReset)other).logger == logger; + } + @Override + public int hashCode() { + return System.identityHashCode(logger); + } + public Logger get() { + return logger; + } + public static CloseOnReset create(Logger logger) { + return new CloseOnReset(logger); + } + } + private final CopyOnWriteArrayList closeOnResetLoggers = + new CopyOnWriteArrayList<>(); + + private final Map listeners = Collections.synchronizedMap(new IdentityHashMap<>()); @@ -204,7 +245,6 @@ }); } - // This private class is used as a shutdown hook. // It does a "reset" to close all open handlers. private class Cleaner extends Thread { @@ -875,30 +915,39 @@ @Override public Object run() { String names[] = parseClassNames(handlersPropertyName); - for (String word : names) { + final boolean ensureCloseOnReset = names.length > 0 + && getBooleanProperty(handlersPropertyName + ".ensureCloseOnReset",true); + + int count = 0; + for (String type : names) { try { - Class clz = ClassLoader.getSystemClassLoader().loadClass(word); + Class clz = ClassLoader.getSystemClassLoader().loadClass(type); Handler hdl = (Handler) clz.newInstance(); // Check if there is a property defining the // this handler's level. - String levs = getProperty(word + ".level"); + String levs = getProperty(type + ".level"); if (levs != null) { Level l = Level.findLevel(levs); if (l != null) { hdl.setLevel(l); } else { // Probably a bad level. Drop through. - System.err.println("Can't set level for " + word); + System.err.println("Can't set level for " + type); } } // Add this Handler to the logger logger.addHandler(hdl); + if (++count == 1 && ensureCloseOnReset) { + // add this logger to the closeOnResetLoggers list. + closeOnResetLoggers.addIfAbsent(CloseOnReset.create(logger)); + } } catch (Exception ex) { - System.err.println("Can't load log handler \"" + word + "\""); + System.err.println("Can't load log handler \"" + type + "\""); System.err.println("" + ex); ex.printStackTrace(); } } + return null; } }); @@ -1233,8 +1282,15 @@ public void reset() throws SecurityException { checkPermission(); + List persistent; synchronized (this) { props = new Properties(); + // make sure we keep the loggers persistent until reset is done. + // Those are the loggers for which we previously created a + // handler from the configuration, and we need to prevent them + // from being gc'ed until those handlers are closed. + persistent = new ArrayList<>(closeOnResetLoggers); + closeOnResetLoggers.clear(); // Since we are doing a reset we no longer want to initialize // the global handlers, if they haven't been initialized yet. initializedGlobalHandlers = true; @@ -1249,6 +1305,7 @@ } } } + persistent.clear(); } // Private method to reset an individual target logger. diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.management/share/classes/sun/management/jmxremote/ConnectorBootstrap.java --- a/jdk/src/java.management/share/classes/sun/management/jmxremote/ConnectorBootstrap.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.management/share/classes/sun/management/jmxremote/ConnectorBootstrap.java Mon Dec 01 12:08:17 2014 +0100 @@ -767,7 +767,7 @@ JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs); connServer.start(); } catch (IOException e) { - if (connServer == null) { + if (connServer == null || connServer.getAddress() == null) { throw new AgentConfigurationError(CONNECTOR_SERVER_IO_ERROR, e, url.toString()); } else { diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/EncryptionKey.java --- a/jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/EncryptionKey.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/EncryptionKey.java Mon Dec 01 12:08:17 2014 +0100 @@ -158,6 +158,11 @@ return destroyed; } + /** + * Returns an informative textual representation of this {@code EncryptionKey}. + * + * @return an informative textual representation of this {@code EncryptionKey}. + */ @Override public String toString() { if (destroyed) { @@ -166,6 +171,11 @@ return "key " + key.toString(); } + /** + * Returns a hash code for this {@code EncryptionKey}. + * + * @return a hash code for this {@code EncryptionKey}. + */ @Override public int hashCode() { int result = 17; @@ -177,15 +187,17 @@ } /** - * Compares the specified Object with this key for equality. - * Returns true if the given object is also a + * Compares the specified object with this key for equality. + * Returns true if the given object is also an * {@code EncryptionKey} and the two - * {@code EncryptionKey} instances are equivalent. + * {@code EncryptionKey} instances are equivalent. More formally two + * {@code EncryptionKey} instances are equal if they have equal key types + * and key material. + * A destroyed {@code EncryptionKey} object is only equal to itself. * - * @param other the Object to compare to - * @return true if the specified object is equal to this EncryptionKey, - * false otherwise. NOTE: Returns false if either of the EncryptionKey - * objects has been destroyed. + * @param other the object to compare to + * @return true if the specified object is equal to this + * {@code EncryptionKey}, false otherwise. */ @Override public boolean equals(Object other) { diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosCredMessage.java --- a/jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosCredMessage.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosCredMessage.java Mon Dec 01 12:08:17 2014 +0100 @@ -130,6 +130,11 @@ return destroyed; } + /** + * Returns an informative textual representation of this {@code KerberosCredMessage}. + * + * @return an informative textual representation of this {@code KerberosCredMessage}. + */ @Override public String toString() { if (destroyed) { @@ -140,6 +145,11 @@ } } + /** + * Returns a hash code for this {@code KerberosCredMessage}. + * + * @return a hash code for this {@code KerberosCredMessage}. + */ @Override public int hashCode() { if (isDestroyed()) { @@ -149,6 +159,19 @@ } } + /** + * Compares the specified object with this {@code KerberosCredMessage} + * for equality. Returns true if the given object is also a + * {@code KerberosCredMessage} and the two {@code KerberosCredMessage} + * instances are equivalent. More formally two {@code KerberosCredMessage} + * instances are equal if they have equal sender, recipient, and encoded + * KRB_CRED messages. + * A destroyed {@code KerberosCredMessage} object is only equal to itself. + * + * @param other the object to compare to + * @return true if the specified object is equal to this + * {@code KerberosCredMessage}, false otherwise. + */ @Override public boolean equals(Object other) { if (other == this) { diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosKey.java --- a/jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosKey.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosKey.java Mon Dec 01 12:08:17 2014 +0100 @@ -61,10 +61,10 @@ * * It might be necessary for the application to be granted a * {@link javax.security.auth.PrivateCredentialPermission - * PrivateCredentialPermission} if it needs to access the KerberosKey + * PrivateCredentialPermission} if it needs to access the {@code KerberosKey} * instance from a Subject. This permission is not needed when the * application depends on the default JGSS Kerberos mechanism to access the - * KerberosKey. In that case, however, the application will need an + * {@code KerberosKey}. In that case, however, the application will need an * appropriate * {@link javax.security.auth.kerberos.ServicePermission ServicePermission}.

    * @@ -113,9 +113,9 @@ private transient boolean destroyed = false; /** - * Constructs a KerberosKey from the given bytes when the key type and - * key version number are known. This can be used when reading the secret - * key information from a Kerberos "keytab". + * Constructs a {@code KerberosKey} from the given bytes when the key type + * and key version number are known. This can be used when reading the + * secret key information from a Kerberos "keytab". * * @param principal the principal that this secret key belongs to * @param keyBytes the key material for the secret key @@ -133,9 +133,9 @@ } /** - * Constructs a KerberosKey from a principal's password using the specified - * algorithm name. The algorithm name (case insensitive) should be provided - * as the encryption type string defined on the IANA + * Constructs a {@code KerberosKey} from a principal's password using the + * specified algorithm name. The algorithm name (case insensitive) should + * be provided as the encryption type string defined on the IANA * Kerberos Encryption Type Numbers * page. The version number of the key generated will be 0. * @@ -261,6 +261,11 @@ return destroyed; } + /** + * Returns an informative textual representation of this {@code KerberosKey}. + * + * @return an informative textual representation of this {@code KerberosKey}. + */ public String toString() { if (destroyed) { return "Destroyed KerberosKey"; @@ -271,9 +276,9 @@ } /** - * Returns a hashcode for this KerberosKey. + * Returns a hash code for this {@code KerberosKey}. * - * @return a hashCode() for the {@code KerberosKey} + * @return a hash code for this {@code KerberosKey}. * @since 1.6 */ public int hashCode() { @@ -290,15 +295,15 @@ } /** - * Compares the specified Object with this KerberosKey for equality. - * Returns true if the given object is also a + * Compares the specified object with this {@code KerberosKey} for + * equality. Returns true if the given object is also a * {@code KerberosKey} and the two * {@code KerberosKey} instances are equivalent. + * A destroyed {@code KerberosKey} object is only equal to itself. * - * @param other the Object to compare to - * @return true if the specified object is equal to this KerberosKey, - * false otherwise. NOTE: Returns false if either of the KerberosKey - * objects has been destroyed. + * @param other the object to compare to + * @return true if the specified object is equal to this {@code KerberosKey}, + * false otherwise. * @since 1.6 */ public boolean equals(Object other) { diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosPrincipal.java --- a/jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosPrincipal.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosPrincipal.java Mon Dec 01 12:08:17 2014 +0100 @@ -88,8 +88,8 @@ /** - * Constructs a KerberosPrincipal from the provided string input. The - * name type for this principal defaults to + * Constructs a {@code KerberosPrincipal} from the provided string input. + * The name type for this principal defaults to * {@link #KRB_NT_PRINCIPAL KRB_NT_PRINCIPAL} * This string is assumed to contain a name in the format * that is specified in Section 2.1.1. (Kerberos Principal Name Form) of @@ -127,7 +127,7 @@ } /** - * Constructs a KerberosPrincipal from the provided string and + * Constructs a {@code KerberosPrincipal} from the provided string and * name type input. The string is assumed to contain a name in the * format that is specified in Section 2.1 (Mandatory Name Forms) of * RFC 1964. @@ -137,7 +137,7 @@ * (for example, duke@FOO.COM, is a valid input string for the * name type, KRB_NT_PRINCIPAL where duke * represents a principal, and FOO.COM represents a realm). - + * *

    If the input name does not contain a realm, the default realm * is used. The default realm can be specified either in a Kerberos * configuration file or via the java.security.krb5.realm @@ -179,28 +179,28 @@ } /** - * Returns a hashcode for this principal. The hash code is defined to - * be the result of the following calculation: + * Returns a hash code for this {@code KerberosPrincipal}. The hash code + * is defined to be the result of the following calculation: *

    {@code
          *  hashCode = getName().hashCode();
          * }
    * - * @return a hashCode() for the {@code KerberosPrincipal} + * @return a hash code for this {@code KerberosPrincipal}. */ public int hashCode() { return getName().hashCode(); } /** - * Compares the specified Object with this Principal for equality. + * Compares the specified object with this principal for equality. * Returns true if the given object is also a * {@code KerberosPrincipal} and the two * {@code KerberosPrincipal} instances are equivalent. * More formally two {@code KerberosPrincipal} instances are equal * if the values returned by {@code getName()} are equal. * - * @param other the Object to compare to - * @return true if the Object passed in represents the same principal + * @param other the object to compare to + * @return true if the object passed in represents the same principal * as this one, false otherwise. */ public boolean equals(Object other) { @@ -217,11 +217,11 @@ } /** - * Save the KerberosPrincipal object to a stream + * Save the {@code KerberosPrincipal} object to a stream * * @serialData this {@code KerberosPrincipal} is serialized * by writing out the PrincipalName and the - * realm in their DER-encoded form as specified in Section 5.2.2 of + * Realm in their DER-encoded form as specified in Section 5.2.2 of * RFC4120. */ private void writeObject(ObjectOutputStream oos) @@ -268,7 +268,7 @@ } /** - * Returns the name type of the KerberosPrincipal. Valid name types + * Returns the name type of the {@code KerberosPrincipal}. Valid name types * are specified in Section 6.2 of * RFC4120. * @@ -278,7 +278,11 @@ return nameType; } - // Inherits javadocs from Object + /** + * Returns an informative textual representation of this {@code KerberosPrincipal}. + * + * @return an informative textual representation of this {@code KerberosPrincipal}. + */ public String toString() { return getName(); } diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosTicket.java --- a/jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosTicket.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KerberosTicket.java Mon Dec 01 12:08:17 2014 +0100 @@ -53,10 +53,10 @@ * * It might be necessary for the application to be granted a * {@link javax.security.auth.PrivateCredentialPermission - * PrivateCredentialPermission} if it needs to access a KerberosTicket - * instance from a Subject. This permission is not needed when the + * PrivateCredentialPermission} if it needs to access a {@code KerberosTicket} + * instance from a {@code Subject}. This permission is not needed when the * application depends on the default JGSS Kerberos mechanism to access the - * KerberosTicket. In that case, however, the application will need an + * {@code KerberosTicket}. In that case, however, the application will need an * appropriate * {@link javax.security.auth.kerberos.ServicePermission ServicePermission}. *

    @@ -193,7 +193,7 @@ private transient boolean destroyed = false; /** - * Constructs a KerberosTicket using credentials information that a + * Constructs a {@code KerberosTicket} using credentials information that a * client either receives from a KDC or reads from a cache. * * @param asn1Encoding the ASN.1 encoding of the ticket as defined by @@ -565,8 +565,8 @@ try { krb5Creds = new sun.security.krb5.Credentials(asn1Encoding, - client.toString(), - server.toString(), + client.getName(), + server.getName(), sessionKey.getEncoded(), sessionKey.getKeyType(), flags, @@ -644,6 +644,11 @@ return destroyed; } + /** + * Returns an informative textual representation of this {@code KerberosTicket}. + * + * @return an informative textual representation of this {@code KerberosTicket}. + */ public String toString() { if (destroyed) { return "Destroyed KerberosTicket"; @@ -677,9 +682,9 @@ } /** - * Returns a hashcode for this KerberosTicket. + * Returns a hash code for this {@code KerberosTicket}. * - * @return a hashCode() for the {@code KerberosTicket} + * @return a hash code for this {@code KerberosTicket}. * @since 1.6 */ public int hashCode() { @@ -714,15 +719,15 @@ } /** - * Compares the specified Object with this KerberosTicket for equality. + * Compares the specified object with this {@code KerberosTicket} for equality. * Returns true if the given object is also a * {@code KerberosTicket} and the two * {@code KerberosTicket} instances are equivalent. + * A destroyed {@code KerberosTicket} object is only equal to itself. * - * @param other the Object to compare to - * @return true if the specified object is equal to this KerberosTicket, - * false otherwise. NOTE: Returns false if either of the KerberosTicket - * objects has been destroyed. + * @param other the object to compare to + * @return true if the specified object is equal to this {@code KerberosTicket}, + * false otherwise. * @since 1.6 */ public boolean equals(Object other) { diff -r a5647c044923 -r 5bec79a6bbca jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KeyTab.java --- a/jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KeyTab.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/src/java.security.jgss/share/classes/javax/security/auth/kerberos/KeyTab.java Mon Dec 01 12:08:17 2014 +0100 @@ -58,10 +58,10 @@ *

    * It might be necessary for the application to be granted a * {@link javax.security.auth.PrivateCredentialPermission - * PrivateCredentialPermission} if it needs to access the KeyTab - * instance from a Subject. This permission is not needed when the + * PrivateCredentialPermission} if it needs to access the {@code KeyTab} + * instance from a {@code Subject}. This permission is not needed when the * application depends on the default JGSS Kerberos mechanism to access the - * KeyTab. In that case, however, the application will need an appropriate + * {@code KeyTab}. In that case, however, the application will need an appropriate * {@link javax.security.auth.kerberos.ServicePermission ServicePermission}. *

    * The keytab file format is described at @@ -249,7 +249,7 @@ * could potentially be expired. *

    * If there is any error (say, I/O error or format error) - * during the reading process of the KeyTab file, a saved result should be + * during the reading process of the keytab file, a saved result should be * returned. If there is no saved result (say, this is the first time this * method is called, or, all previous read attempts failed), an empty array * should be returned. This can make sure the result is not drastically @@ -316,6 +316,11 @@ return !takeSnapshot().isMissing(); } + /** + * Returns an informative textual representation of this {@code KeyTab}. + * + * @return an informative textual representation of this {@code KeyTab}. + */ public String toString() { String s = (file == null) ? "Default keytab" : file.toString(); if (!bound) return s; @@ -324,22 +329,22 @@ } /** - * Returns a hashcode for this KeyTab. + * Returns a hash code for this {@code KeyTab}. * - * @return a hashCode() for the {@code KeyTab} + * @return a hash code for this {@code KeyTab}. */ public int hashCode() { return Objects.hash(file, princ, bound); } /** - * Compares the specified Object with this KeyTab for equality. + * Compares the specified object with this {@code KeyTab} for equality. * Returns true if the given object is also a * {@code KeyTab} and the two * {@code KeyTab} instances are equivalent. * - * @param other the Object to compare to - * @return true if the specified object is equal to this KeyTab + * @param other the object to compare to + * @return true if the specified object is equal to this {@code KeyTab} */ public boolean equals(Object other) { if (other == this) @@ -359,9 +364,9 @@ * Returns the service principal this {@code KeyTab} object * is bound to. Returns {@code null} if it's not bound. *

    - * Please note the deprecated constructors create a KeyTab object bound for - * some unknown principal. In this case, this method also returns null. - * User can call {@link #isBound()} to verify this case. + * Please note the deprecated constructors create a {@code KeyTab} object + * bound for some unknown principal. In this case, this method also returns + * null. User can call {@link #isBound()} to verify this case. * @return the service principal * @since 1.8 */ diff -r a5647c044923 -r 5bec79a6bbca jdk/test/ProblemList.txt --- a/jdk/test/ProblemList.txt Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/ProblemList.txt Mon Dec 01 12:08:17 2014 +0100 @@ -319,6 +319,9 @@ # 6456333 sun/tools/jps/TestJpsJarRelative.java generic-all +# 6734748 +sun/tools/jinfo/JInfoRunningProcessFlagTest.java generic-all + # 8057732 sun/jvmstat/monitor/MonitoredVm/MonitorVmStartTerminate.java generic-all diff -r a5647c044923 -r 5bec79a6bbca jdk/test/TEST.groups --- a/jdk/test/TEST.groups Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/TEST.groups Mon Dec 01 12:08:17 2014 +0100 @@ -290,6 +290,65 @@ :jdk_sound \ :jdk_imageio +############################################################################### +# +# Serviceability sanity groups +# +# These groups specify a subset of Serviceability tests that are supposed to +# guard against breakage of Serviceability features by other component teams. +# They are added to the "hotspot" testset in JPRT so that they will run on all +# full-forest pushes through JPRT. +# + +jdk_svc_sanity = \ + :jdk_management_sanity \ + :jdk_instrument_sanity \ + :jdk_jmx_sanity \ + :jdk_jdi_sanity \ + :svc_tools_sanity + +jdk_management_sanity = + +jdk_instrument_sanity = + +jdk_jmx_sanity = + +jdk_jdi_sanity = \ + com/sun/jdi/AcceptTimeout.java \ + com/sun/jdi/AccessSpecifierTest.java \ + com/sun/jdi/AfterThreadDeathTest.java \ + com/sun/jdi/ArrayRangeTest.java \ + com/sun/jdi/ConstantPoolInfo.java \ + com/sun/jdi/CountFilterTest.java \ + com/sun/jdi/EarlyReturnNegativeTest.java \ + com/sun/jdi/EarlyReturnTest.java \ + com/sun/jdi/FieldWatchpoints.java \ + com/sun/jdi/FramesTest.java \ + com/sun/jdi/InstanceFilter.java \ + com/sun/jdi/InterfaceMethodsTest.java \ + com/sun/jdi/InvokeTest.java \ + com/sun/jdi/LocalVariableEqual.java \ + com/sun/jdi/LocationTest.java \ + com/sun/jdi/ModificationWatchpoints.java \ + com/sun/jdi/MonitorEventTest.java \ + com/sun/jdi/MonitorFrameInfo.java \ + com/sun/jdi/NullThreadGroupNameTest.java \ + com/sun/jdi/PopAndStepTest.java \ + com/sun/jdi/PopAsynchronousTest.java \ + com/sun/jdi/ProcessAttachTest.java \ + com/sun/jdi/ReferrersTest.java \ + com/sun/jdi/RequestReflectionTest.java \ + com/sun/jdi/ResumeOneThreadTest.java \ + com/sun/jdi/RunToExit.java \ + com/sun/jdi/SourceNameFilterTest.java \ + com/sun/jdi/VarargsTest.java \ + com/sun/jdi/Vars.java \ + com/sun/jdi/redefineMethod/RedefineTest.java \ + com/sun/jdi/sde/MangleTest.java \ + com/sun/jdi/sde/TemperatureTableTest.java + +svc_tools_sanity = + ############################# # # Stable test groups diff -r a5647c044923 -r 5bec79a6bbca jdk/test/com/sun/awt/Translucency/WindowOpacity.java --- a/jdk/test/com/sun/awt/Translucency/WindowOpacity.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/com/sun/awt/Translucency/WindowOpacity.java Mon Dec 01 12:08:17 2014 +0100 @@ -33,15 +33,12 @@ import java.awt.event.*; import com.sun.awt.AWTUtilities; -import sun.awt.SunToolkit; public class WindowOpacity { //*** test-writer defined static variables go here *** - private static void realSync() { - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); - } + private static Robot robot; private static void init() @@ -60,6 +57,12 @@ System.out.println("Either the Toolkit or the native system does not support controlling the window opacity level."); pass(); } + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException ("Unexpected failure"); + } boolean passed; @@ -137,7 +140,7 @@ f.setBounds(100, 100, 300, 200); f.setVisible(true); - realSync(); + robot.waitForIdle(); curOpacity = AWTUtilities.getWindowOpacity(f); if (curOpacity < 0.75f || curOpacity > 0.75f) { @@ -147,7 +150,7 @@ AWTUtilities.setWindowOpacity(f, 0.5f); - realSync(); + robot.waitForIdle(); curOpacity = AWTUtilities.getWindowOpacity(f); if (curOpacity < 0.5f || curOpacity > 0.5f) { diff -r a5647c044923 -r 5bec79a6bbca jdk/test/com/sun/java/swing/plaf/windows/8016551/bug8016551.java --- a/jdk/test/com/sun/java/swing/plaf/windows/8016551/bug8016551.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/com/sun/java/swing/plaf/windows/8016551/bug8016551.java Mon Dec 01 12:08:17 2014 +0100 @@ -30,8 +30,7 @@ import javax.swing.*; import java.awt.Graphics; -import java.awt.Toolkit; -import sun.awt.SunToolkit; +import java.awt.Robot; public class bug8016551 { private static volatile RuntimeException exception = null; @@ -64,8 +63,8 @@ } }); - SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit(); - tk.realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); if (exception != null) { throw exception; diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Component/CompEventOnHiddenComponent/CompEventOnHiddenComponent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Component/CompEventOnHiddenComponent/CompEventOnHiddenComponent.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,441 @@ +/* + * Copyright (c) 2006, 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 6383903 + @summary REGRESSION: componentMoved is now getting called for some hidden components + @author andrei.dmitriev: area=awt.component + @run main CompEventOnHiddenComponent +*/ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +public class CompEventOnHiddenComponent +{ + transient static boolean moved = false; + transient static boolean resized = false; + + transient static boolean ancestor_moved = false; + transient static boolean ancestor_resized = false; + static String passed = ""; + + private static void init() + { + String[] instructions = + { + "This is an AUTOMATIC test, simply wait until it is done.", + "The result (passed or failed) will be shown in the", + "message window below." + }; + Sysout.createDialog( ); + Sysout.printInstructions( instructions ); + + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } + + EventQueue.invokeLater(new Runnable(){ + public void run(){ + JFrame f = new JFrame("JFrame"); + JButton b = new JButton("JButton"); + f.add(b); + new JOptionPane(). + createInternalFrame(b, "Test"). + addComponentListener(new ComponentAdapter() { + public void componentMoved(ComponentEvent e) { + moved = true; + System.out.println(e); + } + public void componentResized(ComponentEvent e) { + resized = true; + System.out.println(e); + } + }); + } + }); + + robot.waitForIdle(); + + if (moved || resized){ + passed = "Hidden component got COMPONENT_MOVED or COMPONENT_RESIZED event"; + } else { + System.out.println("Stage 1 passed."); + } + + EventQueue.invokeLater(new Runnable() { + public void run() { + JFrame parentWindow = new JFrame("JFrame 1"); + JButton component = new JButton("JButton 1");; + JButton smallButton = new JButton("Small Button"); + + + smallButton.addHierarchyBoundsListener(new HierarchyBoundsAdapter() { + public void ancestorMoved(HierarchyEvent e) { + ancestor_moved = true; + System.out.println("SMALL COMPONENT >>>>>"+e); + } + public void ancestorResized(HierarchyEvent e) { + ancestor_resized = true; + System.out.println("SMALL COMPONENT >>>>>"+e); + } + }); + + + parentWindow.add(component); + component.add(smallButton); + + component.setSize(100, 100); + component.setLocation(100, 100); + + } + }); + + robot.waitForIdle(); + + if (!ancestor_resized || !ancestor_moved){ + passed = "Hidden component didn't get ANCESTOR event"; + } else { + System.out.println("Stage 2 passed."); + } + + robot.waitForIdle(); + + if (passed.equals("")){ + CompEventOnHiddenComponent.pass(); + } else { + CompEventOnHiddenComponent.fail(passed); + } + + }//End init() + + + + /***************************************************** + * Standard Test Machinery Section + * DO NOT modify anything in this section -- it's a + * standard chunk of code which has all of the + * synchronisation necessary for the test harness. + * By keeping it the same in all tests, it is easier + * to read and understand someone else's test, as + * well as insuring that all tests behave correctly + * with the test harness. + * There is a section following this for test- + * classes + ******************************************************/ + private static boolean theTestPassed = false; + private static boolean testGeneratedInterrupt = false; + private static String failureMessage = ""; + + private static Thread mainThread = null; + + private static int sleepTime = 300000; + + // Not sure about what happens if multiple of this test are + // instantiated in the same VM. Being static (and using + // static vars), it aint gonna work. Not worrying about + // it for now. + public static void main( String args[] ) throws InterruptedException + { + mainThread = Thread.currentThread(); + try + { + init(); + } + catch( TestPassedException e ) + { + //The test passed, so just return from main and harness will + // interepret this return as a pass + return; + } + //At this point, neither test pass nor test fail has been + // called -- either would have thrown an exception and ended the + // test, so we know we have multiple threads. + + //Test involves other threads, so sleep and wait for them to + // called pass() or fail() + try + { + Thread.sleep( sleepTime ); + //Timed out, so fail the test + throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" ); + } + catch (InterruptedException e) + { + //The test harness may have interrupted the test. If so, rethrow the exception + // so that the harness gets it and deals with it. + if( ! testGeneratedInterrupt ) throw e; + + //reset flag in case hit this code more than once for some reason (just safety) + testGeneratedInterrupt = false; + + if ( theTestPassed == false ) + { + throw new RuntimeException( failureMessage ); + } + } + + }//main + + public static synchronized void setTimeoutTo( int seconds ) + { + sleepTime = seconds * 1000; + } + + public static synchronized void pass() + { + Sysout.println( "The test passed." ); + Sysout.println( "The test is over, hit Ctl-C to stop Java VM" ); + //first check if this is executing in main thread + if ( mainThread == Thread.currentThread() ) + { + //Still in the main thread, so set the flag just for kicks, + // and throw a test passed exception which will be caught + // and end the test. + theTestPassed = true; + throw new TestPassedException(); + } + theTestPassed = true; + testGeneratedInterrupt = true; + mainThread.interrupt(); + }//pass() + + public static synchronized void fail() + { + //test writer didn't specify why test failed, so give generic + fail( "it just plain failed! :-)" ); + } + + public static synchronized void fail( String whyFailed ) + { + Sysout.println( "The test failed: " + whyFailed ); + Sysout.println( "The test is over, hit Ctl-C to stop Java VM" ); + //check if this called from main thread + if ( mainThread == Thread.currentThread() ) + { + //If main thread, fail now 'cause not sleeping + throw new RuntimeException( whyFailed ); + } + theTestPassed = false; + testGeneratedInterrupt = true; + failureMessage = whyFailed; + mainThread.interrupt(); + }//fail() + +}// class CompEventOnHiddenComponent + +//This exception is used to exit from any level of call nesting +// when it's determined that the test has passed, and immediately +// end the test. +class TestPassedException extends RuntimeException +{ +} + +//*********** End Standard Test Machinery Section ********** + + +//************ Begin classes defined for the test **************** + +// if want to make listeners, here is the recommended place for them, then instantiate +// them in init() + +/* Example of a class which may be written as part of a test +class NewClass implements anInterface + { + static int newVar = 0; + + public void eventDispatched(AWTEvent e) + { + //Counting events to see if we get enough + eventCount++; + + if( eventCount == 20 ) + { + //got enough events, so pass + + CompEventOnHiddenComponent.pass(); + } + else if( tries == 20 ) + { + //tried too many times without getting enough events so fail + + CompEventOnHiddenComponent.fail(); + } + + }// eventDispatched() + + }// NewClass class + +*/ + + +//************** End classes defined for the test ******************* + + + + +/**************************************************** + Standard Test Machinery + DO NOT modify anything below -- it's a standard + chunk of code whose purpose is to make user + interaction uniform, and thereby make it simpler + to read and understand someone else's test. + ****************************************************/ + +/** + This is part of the standard test machinery. + It creates a dialog (with the instructions), and is the interface + for sending text messages to the user. + To print the instructions, send an array of strings to Sysout.createDialog + WithInstructions method. Put one line of instructions per array entry. + To display a message for the tester to see, simply call Sysout.println + with the string to be displayed. + This mimics System.out.println but works within the test harness as well + as standalone. + */ + +class Sysout +{ + private static TestDialog dialog; + + public static void createDialogWithInstructions( String[] instructions ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + dialog.printInstructions( instructions ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + public static void createDialog( ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + String[] defInstr = { "Instructions will appear here. ", "" } ; + dialog.printInstructions( defInstr ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + + public static void printInstructions( String[] instructions ) + { + dialog.printInstructions( instructions ); + } + + + public static void println( String messageIn ) + { + dialog.displayMessage( messageIn ); + System.out.println(messageIn); + } + +}// Sysout class + +/** + This is part of the standard test machinery. It provides a place for the + test instructions to be displayed, and a place for interactive messages + to the user to be displayed. + To have the test instructions displayed, see Sysout. + To have a message to the user be displayed, see Sysout. + Do not call anything in this dialog directly. + */ +class TestDialog extends Dialog +{ + + TextArea instructionsText; + TextArea messageText; + int maxStringLength = 80; + + //DO NOT call this directly, go through Sysout + public TestDialog( Frame frame, String name ) + { + super( frame, name ); + int scrollBoth = TextArea.SCROLLBARS_BOTH; + instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); + add( "North", instructionsText ); + + messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); + add("Center", messageText); + + pack(); + + setVisible(true); + }// TestDialog() + + //DO NOT call this directly, go through Sysout + public void printInstructions( String[] instructions ) + { + //Clear out any current instructions + instructionsText.setText( "" ); + + //Go down array of instruction strings + + String printStr, remainingStr; + for( int i=0; i < instructions.length; i++ ) + { + //chop up each into pieces maxSringLength long + remainingStr = instructions[ i ]; + while( remainingStr.length() > 0 ) + { + //if longer than max then chop off first max chars to print + if( remainingStr.length() >= maxStringLength ) + { + //Try to chop on a word boundary + int posOfSpace = remainingStr. + lastIndexOf( ' ', maxStringLength - 1 ); + + if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; + + printStr = remainingStr.substring( 0, posOfSpace + 1 ); + remainingStr = remainingStr.substring( posOfSpace + 1 ); + } + //else just print + else + { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append( printStr + "\n" ); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage( String messageIn ) + { + messageText.append( messageIn + "\n" ); + System.out.println(messageIn); + } + +}// TestDialog class diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Component/NoUpdateUponShow/NoUpdateUponShow.java --- a/jdk/test/java/awt/Component/NoUpdateUponShow/NoUpdateUponShow.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Component/NoUpdateUponShow/NoUpdateUponShow.java Mon Dec 01 12:08:17 2014 +0100 @@ -36,7 +36,6 @@ */ import java.awt.*; -import sun.awt.SunToolkit; public class NoUpdateUponShow { @@ -70,7 +69,13 @@ }); f.setVisible(true); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + try { + Robot robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } if (wasUpdate) { fail(" Unexpected update. "); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Component/PaintAll/PaintAll.java --- a/jdk/test/java/awt/Component/PaintAll/PaintAll.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Component/PaintAll/PaintAll.java Mon Dec 01 12:08:17 2014 +0100 @@ -21,8 +21,6 @@ * questions. */ -import sun.awt.SunToolkit; - import java.awt.Button; import java.awt.Canvas; import java.awt.Checkbox; @@ -48,6 +46,8 @@ @bug 6596915 @summary Test Component.paintAll() method @author sergey.bylokhov@oracle.com: area=awt.component + @library ../../../../lib/testlibrary/ + @build ExtendedRobot @run main PaintAll */ public class PaintAll { @@ -66,6 +66,7 @@ private static volatile boolean scrollPanePainted; private static volatile boolean textAreaPainted; private static volatile boolean textFieldPainted; + private static ExtendedRobot robot = null; private static final Button buttonStub = new Button() { @Override @@ -283,11 +284,15 @@ } private static void sleep() { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); - try { - Thread.sleep(500L); - } catch (InterruptedException ignored) { + if(robot == null) { + try { + robot = new ExtendedRobot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } } + robot.waitForIdle(500); } private static void fail(final String message) { diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Focus/ModalBlockedStealsFocusTest/ModalBlockedStealsFocusTest.java --- a/jdk/test/java/awt/Focus/ModalBlockedStealsFocusTest/ModalBlockedStealsFocusTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Focus/ModalBlockedStealsFocusTest/ModalBlockedStealsFocusTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -34,11 +34,9 @@ import java.applet.Applet; import java.util.concurrent.atomic.AtomicBoolean; import java.lang.reflect.InvocationTargetException; -import sun.awt.SunToolkit; import test.java.awt.regtesthelpers.Util; public class ModalBlockedStealsFocusTest extends Applet { - SunToolkit toolkit = (SunToolkit)Toolkit.getDefaultToolkit(); Frame frame = new Frame("Blocked Frame"); Dialog dialog = new Dialog(frame, "Modal Dialog", Dialog.ModalityType.TOOLKIT_MODAL); AtomicBoolean lostFocus = new AtomicBoolean(false); @@ -85,7 +83,13 @@ }).start(); Util.waitTillShown(dialog); - toolkit.realSync(); + try { + Robot robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } // Test 1. Show a modal blocked frame, check that it doesn't steal focus. diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Focus/WindowInitialFocusTest/WindowInitialFocusTest.java --- a/jdk/test/java/awt/Focus/WindowInitialFocusTest/WindowInitialFocusTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Focus/WindowInitialFocusTest/WindowInitialFocusTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -33,7 +33,6 @@ import java.awt.event.*; import java.applet.Applet; import java.util.concurrent.atomic.AtomicBoolean; -import sun.awt.SunToolkit; import test.java.awt.regtesthelpers.Util; public class WindowInitialFocusTest extends Applet { @@ -41,7 +40,7 @@ Window window = new Window(frame); Button button = new Button("button"); AtomicBoolean focused = new AtomicBoolean(false); - SunToolkit toolkit = (SunToolkit)Toolkit.getDefaultToolkit(); + Robot robot; public static void main(String[] args) { WindowInitialFocusTest app = new WindowInitialFocusTest(); @@ -75,12 +74,18 @@ }}); frame.setVisible(true); - toolkit.realSync(); + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } + robot.waitForIdle(); // Test 1. Show the window, check that it become focused. window.setVisible(true); - toolkit.realSync(); + robot.waitForIdle(); if (!Util.waitForCondition(focused, 2000L)) { throw new TestFailedException("the window didn't get focused on its showing!"); @@ -89,13 +94,13 @@ // Test 2. Show unfocusable window, check that it doesn't become focused. window.setVisible(false); - toolkit.realSync(); + robot.waitForIdle(); window.setFocusableWindowState(false); focused.set(false); window.setVisible(true); - toolkit.realSync(); + robot.waitForIdle(); if (Util.waitForCondition(focused, 2000L)) { throw new TestFailedException("the unfocusable window got focused on its showing!"); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Frame/ExceptionOnSetExtendedStateTest/ExceptionOnSetExtendedStateTest.java --- a/jdk/test/java/awt/Frame/ExceptionOnSetExtendedStateTest/ExceptionOnSetExtendedStateTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Frame/ExceptionOnSetExtendedStateTest/ExceptionOnSetExtendedStateTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -30,11 +30,8 @@ import java.awt.*; -import sun.awt.SunToolkit; - public class ExceptionOnSetExtendedStateTest { private static final int[] frameStates = { Frame.NORMAL, Frame.ICONIFIED, Frame.MAXIMIZED_BOTH }; - private static final SunToolkit toolkit = (SunToolkit)Toolkit.getDefaultToolkit(); private static boolean validatePlatform() { String osName = System.getProperty("os.name"); @@ -53,7 +50,13 @@ frame.setSize(200, 200); frame.setUndecorated(!decoratedFrame); frame.setVisible(true); - toolkit.realSync(); + try { + Robot robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } frame.setExtendedState(oldState); sleep(1000); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Frame/FrameSize/TestFrameSize.java --- a/jdk/test/java/awt/Frame/FrameSize/TestFrameSize.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Frame/FrameSize/TestFrameSize.java Mon Dec 01 12:08:17 2014 +0100 @@ -77,7 +77,13 @@ mainWindow.setVisible(true); - ((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + try { + Robot robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure."); + } Dimension clientSize2 = getClientSize(mainWindow); System.out.println("Client size after showing: " + clientSize2); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Frame/MaximizedByPlatform/MaximizedByPlatform.java --- a/jdk/test/java/awt/Frame/MaximizedByPlatform/MaximizedByPlatform.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Frame/MaximizedByPlatform/MaximizedByPlatform.java Mon Dec 01 12:08:17 2014 +0100 @@ -25,11 +25,12 @@ * @bug 8026143 * @summary [macosx] Maximized state could be inconsistent between peer and frame * @author Petr Pchelko + * @library ../../../../lib/testlibrary + * @build jdk.testlibrary.OSInfo * @run main MaximizedByPlatform */ -import sun.awt.OSInfo; -import sun.awt.SunToolkit; +import jdk.testlibrary.OSInfo; import java.awt.*; @@ -43,6 +44,13 @@ return; } + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } availableScreenBounds = getAvailableScreenBounds(); // Test 1. The maximized state is set in setBounds @@ -51,12 +59,12 @@ frame.setBounds(100, 100, 100, 100); frame.setVisible(true); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); frame.setBounds(availableScreenBounds.x, availableScreenBounds.y, availableScreenBounds.width, availableScreenBounds.height); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) { throw new RuntimeException("Maximized state was not set for frame in setBounds"); @@ -73,7 +81,7 @@ availableScreenBounds.width + 100, availableScreenBounds.height); frame.setVisible(true); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) { throw new RuntimeException("Maximized state was not set for frame in setVisible"); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Frame/MaximizedToMaximized/MaximizedToMaximized.java --- a/jdk/test/java/awt/Frame/MaximizedToMaximized/MaximizedToMaximized.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Frame/MaximizedToMaximized/MaximizedToMaximized.java Mon Dec 01 12:08:17 2014 +0100 @@ -28,7 +28,7 @@ import java.awt.Insets; import java.awt.Rectangle; import java.awt.Toolkit; -import sun.awt.SunToolkit; +import java.awt.Robot; /** * @test @@ -65,7 +65,8 @@ Rectangle frameBounds = frame.getBounds(); frame.setExtendedState(Frame.MAXIMIZED_BOTH); - ((SunToolkit) toolkit).realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); Rectangle maximizedFrameBounds = frame.getBounds(); if (maximizedFrameBounds.width < frameBounds.width diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Frame/SlideNotResizableTest/SlideNotResizableTest.java --- a/jdk/test/java/awt/Frame/SlideNotResizableTest/SlideNotResizableTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Frame/SlideNotResizableTest/SlideNotResizableTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -21,8 +21,6 @@ * questions. */ -import sun.awt.SunToolkit; - import java.awt.*; import java.awt.Dimension; import java.awt.Point; @@ -62,8 +60,9 @@ } } - private static void sync() throws InterruptedException { - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + private static void sync() throws Exception { + Robot robot = new Robot(); + robot.waitForIdle(); Thread.sleep(1000); } } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java --- a/jdk/test/java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java Mon Dec 01 12:08:17 2014 +0100 @@ -34,10 +34,17 @@ import static java.awt.GraphicsDevice.WindowTranslucency.*; -import sun.awt.SunToolkit; public class TranslucentWindow { public static void main(String args[]) { + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); @@ -47,10 +54,10 @@ // First, check it can be made fullscreen window without any effects applied gd.setFullScreenWindow(f); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); gd.setFullScreenWindow(null); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); // Second, check if it applying any effects doesn't prevent the window // from going into the fullscreen mode @@ -64,7 +71,7 @@ f.setBackground(new Color(0, 0, 0, 128)); } gd.setFullScreenWindow(f); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); // Third, make sure all the effects are unset when entering the fullscreen mode if (f.getShape() != null) { diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java --- a/jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java Mon Dec 01 12:08:17 2014 +0100 @@ -27,16 +27,17 @@ import java.awt.Frame; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; -import java.awt.Toolkit; - -import sun.awt.SunToolkit; /** * @test * @bug 8019587 * @author Sergey Bylokhov + * @library ../../../lib/testlibrary/ + * @build ExtendedRobot + * @run main IncorrectDisplayModeExitFullscreen */ public class IncorrectDisplayModeExitFullscreen { + static ExtendedRobot robot; public static void main(final String[] args) { @@ -64,6 +65,13 @@ return; } + try { + robot = new ExtendedRobot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } + final Frame frame = new Frame(); frame.setBackground(Color.GREEN); frame.setUndecorated(true); @@ -85,10 +93,6 @@ } } private static void sleep() { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); - try { - Thread.sleep(1500); - } catch (InterruptedException ignored) { - } + robot.waitForIdle(1500); } } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/GridBagLayout/GridBagLayoutIpadXYTest/GridBagLayoutIpadXYTest.java --- a/jdk/test/java/awt/GridBagLayout/GridBagLayoutIpadXYTest/GridBagLayoutIpadXYTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/GridBagLayout/GridBagLayoutIpadXYTest/GridBagLayoutIpadXYTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -71,7 +71,14 @@ frame.pack(); frame.setVisible(true); - ((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + Robot robot; + try { + robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } Dimension minSize = jtf.getMinimumSize(); if ( minSize.width + customIpadx != jtf.getSize().width || diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/List/ListPeer/R2303044ListSelection.java --- a/jdk/test/java/awt/List/ListPeer/R2303044ListSelection.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/List/ListPeer/R2303044ListSelection.java Mon Dec 01 12:08:17 2014 +0100 @@ -21,12 +21,10 @@ * questions. */ -import sun.awt.SunToolkit; - import java.awt.Frame; import java.awt.HeadlessException; import java.awt.List; -import java.awt.Toolkit; +import java.awt.Robot; /** * @test @@ -57,9 +55,11 @@ private static void sleep() { try { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); Thread.sleep(1000); - } catch (final InterruptedException ignored) { + } catch (final Exception ignored) { + ignored.printStackTrace(); } } } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/List/SingleModeDeselect/SingleModeDeselect.java --- a/jdk/test/java/awt/List/SingleModeDeselect/SingleModeDeselect.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/List/SingleModeDeselect/SingleModeDeselect.java Mon Dec 01 12:08:17 2014 +0100 @@ -30,7 +30,6 @@ */ import java.awt.*; -import sun.awt.SunToolkit; public class SingleModeDeselect { @@ -50,7 +49,13 @@ list.select(0); list.deselect(1); - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); + try { + Robot robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } if (list.getSelectedIndex() != 0){ throw new RuntimeException("Test failed: List.getSelectedIndex() returns "+list.getSelectedIndex()); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Paint/ExposeOnEDT.java --- a/jdk/test/java/awt/Paint/ExposeOnEDT.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Paint/ExposeOnEDT.java Mon Dec 01 12:08:17 2014 +0100 @@ -22,18 +22,19 @@ */ -import sun.awt.SunToolkit; - import java.awt.*; /** * @test * @bug 7090424 * @author Sergey Bylokhov + * @library ../../../lib/testlibrary/ + * @build ExtendedRobot * @run main ExposeOnEDT */ public final class ExposeOnEDT { + private static ExtendedRobot robot = null; private static final Button buttonStub = new Button() { @Override public void paint(final Graphics g) { @@ -275,11 +276,15 @@ } private static void sleep() { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); - try { - Thread.sleep(1000L); - } catch (InterruptedException ignored) { + if(robot == null) { + try { + robot = new ExtendedRobot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } } + robot.waitForIdle(1000); } private static void fail(final String message) { diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/ScrollPane/ScrollPanePreferredSize/ScrollPanePreferredSize.java --- a/jdk/test/java/awt/ScrollPane/ScrollPanePreferredSize/ScrollPanePreferredSize.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/ScrollPane/ScrollPanePreferredSize/ScrollPanePreferredSize.java Mon Dec 01 12:08:17 2014 +0100 @@ -26,12 +26,13 @@ import java.awt.ScrollPane; import java.awt.Toolkit; -import sun.awt.SunToolkit; - /** * @test * @bug 7124213 * @author Sergey Bylokhov + * @library ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @run main ScrollPanePreferredSize */ public final class ScrollPanePreferredSize { @@ -54,10 +55,12 @@ } private static void sleep() { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); try { - Thread.sleep(500L); - } catch (InterruptedException ignored) { + ExtendedRobot robot = new ExtendedRobot(); + robot.waitForIdle(500); + } catch (Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); } } } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/TextArea/DisposeTest/TestDispose.java --- a/jdk/test/java/awt/TextArea/DisposeTest/TestDispose.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/TextArea/DisposeTest/TestDispose.java Mon Dec 01 12:08:17 2014 +0100 @@ -35,14 +35,12 @@ import java.awt.FlowLayout; import java.awt.Frame; import java.awt.TextArea; -import java.awt.Toolkit; +import java.awt.Robot; import java.lang.reflect.InvocationTargetException; import javax.swing.JFrame; import javax.swing.SwingUtilities; -import sun.awt.SunToolkit; - public class TestDispose { public static Frame frame = null; @@ -51,7 +49,14 @@ public void testDispose() throws InvocationTargetException, InterruptedException { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } + SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -69,7 +74,7 @@ frame.setVisible(true); } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -77,7 +82,7 @@ frame.dispose(); } }); - toolkit.realSync(); + robot.waitForIdle(); } public static void main(String[] args) throws Exception{ diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java --- a/jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java Mon Dec 01 12:08:17 2014 +0100 @@ -34,7 +34,7 @@ import java.awt.FlowLayout; import java.awt.TextArea; -import java.awt.Toolkit; +import java.awt.Robot; import java.lang.reflect.Field; import javax.swing.JFrame; @@ -42,7 +42,6 @@ import javax.swing.SwingUtilities; import javax.swing.text.DefaultCaret; -import sun.awt.SunToolkit; public class bug7129742 { @@ -51,7 +50,7 @@ public static boolean fastreturn = false; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -88,7 +87,7 @@ } } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/TextArea/TextAreaTwicePack/TextAreaTwicePack.java --- a/jdk/test/java/awt/TextArea/TextAreaTwicePack/TextAreaTwicePack.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/TextArea/TextAreaTwicePack/TextAreaTwicePack.java Mon Dec 01 12:08:17 2014 +0100 @@ -24,9 +24,8 @@ import java.awt.Dimension; import java.awt.Frame; import java.awt.TextArea; -import java.awt.Toolkit; +import java.awt.Robot; -import sun.awt.SunToolkit; /** * @test @@ -55,10 +54,12 @@ } private static void sleep() { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); try { + Robot robot = new Robot(); + robot.waitForIdle(); Thread.sleep(500L); - } catch (InterruptedException ignored) { + } catch (Exception ignored) { + ignored.printStackTrace(); } } } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/TextField/DisposeTest/TestDispose.java --- a/jdk/test/java/awt/TextField/DisposeTest/TestDispose.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/TextField/DisposeTest/TestDispose.java Mon Dec 01 12:08:17 2014 +0100 @@ -35,14 +35,12 @@ import java.awt.FlowLayout; import java.awt.Frame; import java.awt.TextField; -import java.awt.Toolkit; +import java.awt.Robot; import java.lang.reflect.InvocationTargetException; import javax.swing.JFrame; import javax.swing.SwingUtilities; -import sun.awt.SunToolkit; - public class TestDispose { public static Frame frame = null; @@ -51,7 +49,13 @@ public void testDispose() throws InvocationTargetException, InterruptedException { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -69,7 +73,7 @@ frame.setVisible(true); } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -77,7 +81,7 @@ frame.dispose(); } }); - toolkit.realSync(); + robot.waitForIdle(); } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java --- a/jdk/test/java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/TrayIcon/PopupMenuLeakTest/PopupMenuLeakTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -26,12 +26,13 @@ @bug 8007220 @summary Reference to the popup leaks after the TrayIcon is removed @author Petr Pchelko + @library ../../../../lib/testlibrary/ + @build ExtendedRobot @run main/othervm -Xmx50m PopupMenuLeakTest */ import java.awt.*; import javax.swing.SwingUtilities; -import sun.awt.SunToolkit; import java.awt.image.BufferedImage; import java.lang.ref.WeakReference; @@ -42,8 +43,10 @@ static final AtomicReference> iconWeakReference = new AtomicReference<>(); static final AtomicReference> popupWeakReference = new AtomicReference<>(); + static ExtendedRobot robot; public static void main(String[] args) throws Exception { + robot = new ExtendedRobot(); SwingUtilities.invokeAndWait(PopupMenuLeakTest::createSystemTrayIcon); sleep(); // To make the test automatic we explicitly call addNotify on a popup to create the peer @@ -141,9 +144,6 @@ } private static void sleep() { - ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); - try { - Thread.sleep(100); - } catch (InterruptedException ignored) { } + robot.waitForIdle(100); } } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Window/8027025/Test8027025.java --- a/jdk/test/java/awt/Window/8027025/Test8027025.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Window/8027025/Test8027025.java Mon Dec 01 12:08:17 2014 +0100 @@ -28,8 +28,6 @@ * @run main Test8027025 */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.util.concurrent.atomic.AtomicReference; @@ -49,7 +47,8 @@ window.setVisible(true); }); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); AtomicReference point = new AtomicReference<>(); SwingUtilities.invokeAndWait(() -> point.set(window.getLocationOnScreen())); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Window/AlwaysOnTop/AlwaysOnTopFieldTest.java --- a/jdk/test/java/awt/Window/AlwaysOnTop/AlwaysOnTopFieldTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Window/AlwaysOnTop/AlwaysOnTopFieldTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -22,9 +22,8 @@ */ import java.awt.Dialog; import java.awt.Frame; -import java.awt.Toolkit; +import java.awt.Robot; import java.awt.Window; -import sun.awt.SunToolkit; /** * @test * @bug 7081594 @@ -35,19 +34,25 @@ public class AlwaysOnTopFieldTest { public static void main(String[] args) { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } Window window = new Frame("Window 1"); window.setSize(200, 200); window.setAlwaysOnTop(true); window.setVisible(true); - toolkit.realSync(); + robot.waitForIdle(); Dialog dialog = new Dialog(window, "Owned dialog 1"); dialog.setSize(200, 200); dialog.setLocation(100, 100); dialog.setVisible(true); - toolkit.realSync(); + robot.waitForIdle(); try { if (!window.isAlwaysOnTop()) { @@ -64,17 +69,17 @@ window = new Frame("Window 2"); window.setSize(200, 200); window.setVisible(true); - toolkit.realSync(); + robot.waitForIdle(); dialog = new Dialog(window, "Owned dialog 2"); dialog.setSize(200, 200); dialog.setLocation(100, 100); dialog.setVisible(true); - toolkit.realSync(); + robot.waitForIdle(); window.setAlwaysOnTop(true); - toolkit.realSync(); + robot.waitForIdle(); try { if (!window.isAlwaysOnTop()) { diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Window/AlwaysOnTop/SyncAlwaysOnTopFieldTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Window/AlwaysOnTop/SyncAlwaysOnTopFieldTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2014, 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.awt.Window; + +/** + * @test + * @bug 8064468 + * @author Alexander Scherbatiy + * @summary ownedWindowList access requires synchronization in + * Window.setAlwaysOnTop() method + * @run main SyncAlwaysOnTopFieldTest + */ +public class SyncAlwaysOnTopFieldTest { + + private static final int WINDOWS_COUNT = 200; + private static final int STEPS_COUNT = 20; + + public static void main(String[] args) throws Exception { + final Window rootWindow = createWindow(null); + + new Thread(() -> { + for (int i = 0; i < WINDOWS_COUNT; i++) { + createWindow(rootWindow); + } + }).start(); + + boolean alwaysOnTop = true; + for (int i = 0; i < STEPS_COUNT; i++) { + Thread.sleep(10); + rootWindow.setAlwaysOnTop(alwaysOnTop); + alwaysOnTop = !alwaysOnTop; + } + } + + private static Window createWindow(Window parent) { + Window window = new Window(parent); + window.setSize(200, 200); + window.setVisible(true); + return window; + } +} \ No newline at end of file diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Window/GetWindowsTest/GetWindowsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Window/GetWindowsTest/GetWindowsTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2005, 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 6322270 + @summary Test for new API introduced in the fix for 6322270: Window.getWindows(), +Window.getOwnerlessWindows() and Frame.getFrames() + @author artem.ananiev: area=awt.toplevel + @run main GetWindowsTest +*/ + +import java.awt.*; +import java.awt.event.*; + +import java.util.*; + +public class GetWindowsTest +{ + private static Vector frames = new Vector(); + private static Vector windows = new Vector(); + private static Vector ownerless = new Vector(); + + private static void init() + { + Frame f1 = new Frame("F1"); + f1.setBounds(100, 100, 100, 100); + f1.setVisible(true); + addToWindowsList(f1); + + Dialog d1 = new Dialog(f1, "D1", Dialog.ModalityType.MODELESS); + d1.setBounds(120, 120, 100, 100); + d1.setVisible(true); + addToWindowsList(d1); + + Window w1 = new Window(d1); + w1.setBounds(140, 140, 100, 100); + w1.setVisible(true); + addToWindowsList(w1); + + Frame f2 = new Frame("F2"); + f2.setBounds(300, 100, 100, 100); + f2.setVisible(true); + addToWindowsList(f2); + + Window w2 = new Window(f2); + w2.setBounds(320, 120, 100, 100); + w2.setVisible(true); + addToWindowsList(w2); + + Dialog d2 = new Dialog(f2, "D2", Dialog.ModalityType.MODELESS); + d2.setBounds(340, 140, 100, 100); + d2.setVisible(true); + addToWindowsList(d2); + + Dialog d3 = new Dialog((Frame)null, "D3", Dialog.ModalityType.MODELESS); + d3.setBounds(500, 100, 100, 100); + d3.setVisible(true); + addToWindowsList(d3); + + Dialog d4 = new Dialog(d3, "D4", Dialog.ModalityType.MODELESS); + d4.setBounds(520, 120, 100, 100); + d4.setVisible(true); + addToWindowsList(d4); + + Window w3 = new Window((Frame)null); + w3.setBounds(700, 100, 100, 100); + w3.setVisible(true); + addToWindowsList(w3); + + Window w4 = new Window(w3); + w4.setBounds(720, 120, 100, 100); + w4.setVisible(true); + addToWindowsList(w4); + + try { + Robot robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new Error("Unexpected failure"); + } + + Frame[] fl = Frame.getFrames(); + Vector framesToCheck = new Vector(); + for (Frame f : fl) + { + framesToCheck.add(f); + } + checkWindowsList(frames, framesToCheck, "Frame.getFrames()"); + + Window[] wl = Window.getWindows(); + Vector windowsToCheck = new Vector(); + for (Window w : wl) + { + windowsToCheck.add(w); + } + checkWindowsList(windows, windowsToCheck, "Window.getWindows()"); + + Window[] ol = Window.getOwnerlessWindows(); + Vector ownerlessToCheck = new Vector(); + for (Window o : ol) + { + ownerlessToCheck.add(o); + } + checkWindowsList(ownerless, ownerlessToCheck, "Window.getOwnerlessWindows()"); + + GetWindowsTest.pass(); + } + + private static void addToWindowsList(Window w) + { + if (w instanceof Frame) + { + frames.add(w); + } + windows.add(w); + if (w.getOwner() == null) + { + ownerless.add(w); + } + } + + private static void checkWindowsList(Vector wl1, Vector wl2, String methodName) + { + if ((wl1.size() != wl2.size()) || + !wl1.containsAll(wl2) || + !wl2.containsAll(wl1)) + { + fail("Test FAILED: method " + methodName + " returns incorrect list of windows"); + } + } + +/***************************************************** + * Standard Test Machinery Section + * DO NOT modify anything in this section -- it's a + * standard chunk of code which has all of the + * synchronisation necessary for the test harness. + * By keeping it the same in all tests, it is easier + * to read and understand someone else's test, as + * well as insuring that all tests behave correctly + * with the test harness. + * There is a section following this for test- + * classes + ******************************************************/ + + private static boolean theTestPassed = false; + private static boolean testGeneratedInterrupt = false; + private static String failureMessage = ""; + + private static Thread mainThread = null; + + private static int sleepTime = 300000; + + // Not sure about what happens if multiple of this test are + // instantiated in the same VM. Being static (and using + // static vars), it aint gonna work. Not worrying about + // it for now. + public static void main( String args[] ) throws InterruptedException + { + mainThread = Thread.currentThread(); + try + { + init(); + } + catch( TestPassedException e ) + { + //The test passed, so just return from main and harness will + // interepret this return as a pass + return; + } + //At this point, neither test pass nor test fail has been + // called -- either would have thrown an exception and ended the + // test, so we know we have multiple threads. + + //Test involves other threads, so sleep and wait for them to + // called pass() or fail() + try + { + Thread.sleep( sleepTime ); + //Timed out, so fail the test + throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" ); + } + catch (InterruptedException e) + { + //The test harness may have interrupted the test. If so, rethrow the exception + // so that the harness gets it and deals with it. + if( ! testGeneratedInterrupt ) throw e; + + //reset flag in case hit this code more than once for some reason (just safety) + testGeneratedInterrupt = false; + + if ( theTestPassed == false ) + { + throw new RuntimeException( failureMessage ); + } + } + } + + public static synchronized void setTimeoutTo( int seconds ) + { + sleepTime = seconds * 1000; + } + + public static synchronized void pass() + { + //first check if this is executing in main thread + if ( mainThread == Thread.currentThread() ) + { + //Still in the main thread, so set the flag just for kicks, + // and throw a test passed exception which will be caught + // and end the test. + theTestPassed = true; + throw new TestPassedException(); + } + theTestPassed = true; + testGeneratedInterrupt = true; + mainThread.interrupt(); + } + + public static synchronized void fail() + { + //test writer didn't specify why test failed, so give generic + fail( "it just plain failed! :-)" ); + } + + public static synchronized void fail( String whyFailed ) + { + //check if this called from main thread + if ( mainThread == Thread.currentThread() ) + { + //If main thread, fail now 'cause not sleeping + throw new RuntimeException( whyFailed ); + } + theTestPassed = false; + testGeneratedInterrupt = true; + failureMessage = whyFailed; + mainThread.interrupt(); + } +} + +//This exception is used to exit from any level of call nesting +// when it's determined that the test has passed, and immediately +// end the test. +class TestPassedException extends RuntimeException +{ +} + +//*********** End Standard Test Machinery Section ********** diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Window/HandleWindowDestroyTest/HandleWindowDestroyTest.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Window/HandleWindowDestroyTest/HandleWindowDestroyTest.html Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,23 @@ + + + + + + + +

    HandleWindowDestroyTest
    Bug ID: 6260648

    + +

    This is an AUTOMATIC test, simply wait for completion

    + + + + + diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Window/HandleWindowDestroyTest/HandleWindowDestroyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/Window/HandleWindowDestroyTest/HandleWindowDestroyTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2005, 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 6260648 + @summary Tests that WINDOW_DESTROY event can be handled by overriding handleEvent(). Also, +tests that handleEvent() is not called by AWT if any listener is added to the component +(i. e. when post-1.1 events schema is used) + @author artem.ananiev: area=awt.event + @run applet HandleWindowDestroyTest.html +*/ + +import java.applet.*; + +import java.awt.*; +import java.awt.event.*; + +public class HandleWindowDestroyTest extends Applet +{ + private volatile boolean handleEventCalled; + + public void start () + { + setSize (200,200); + setVisible(true); + validate(); + + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } + + Frame f = new Frame("Frame") + { + public boolean handleEvent(Event e) + { + if (e.id == Event.WINDOW_DESTROY) + { + handleEventCalled = true; + } + return super.handleEvent(e); + } + }; + f.setBounds(100, 100, 100, 100); + f.setVisible(true); + robot.waitForIdle(); + + handleEventCalled = false; + Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(f, Event.WINDOW_DESTROY)); + robot.waitForIdle(); + + if (!handleEventCalled) + { + throw new RuntimeException("Test FAILED: handleEvent() is not called"); + } + + f.addWindowListener(new WindowAdapter() + { + }); + + handleEventCalled = false; + Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(f, Event.WINDOW_DESTROY)); + robot.waitForIdle(); + + if (handleEventCalled) + { + throw new RuntimeException("Test FAILED: handleEvent() is called event with a listener added"); + } + } +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/Window/OwnedWindowsSerialization/OwnedWindowsSerialization.java --- a/jdk/test/java/awt/Window/OwnedWindowsSerialization/OwnedWindowsSerialization.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/Window/OwnedWindowsSerialization/OwnedWindowsSerialization.java Mon Dec 01 12:08:17 2014 +0100 @@ -21,8 +21,6 @@ * questions. */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.io.ByteArrayInputStream; @@ -54,7 +52,8 @@ subDialog = new Dialog(dialog, SUBDIALOG_LABEL); }); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); if (!topFrame.isAlwaysOnTop() || !dialog.isAlwaysOnTop() || !subDialog.isAlwaysOnTop()) { throw new RuntimeException("TEST FAILED: AlwaysOnTop was not set properly"); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,276 @@ +/* + * Copyright (c) 2005, 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 5025858 + @summary Tests that after programmatically moving or resizing a component, +corresponding ComponentEvents are generated only once + @author artem.ananiev: area=awt.event + @run main/manual MovedResizedTwiceTest +*/ + +import java.awt.*; +import java.awt.event.*; + +/* + IMPORTANT: this test is made manual as some window managers may generate + strange events and that would lead to the test to fail. However, on most + popular platforms (windows, linux w/ KDE or GNOME, solaris w/ CDE or + GNOME) it usually passes successfully. +*/ + +public class MovedResizedTwiceTest +{ + private static volatile int componentMovedCount; + private static volatile int componentResizedCount; + + private static volatile int rightX, rightY; + + private static volatile boolean failed = false; + + private static void init() + { + componentMovedCount = componentResizedCount = 0; + + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Cannot create Robot: failure"); + } + + Frame f = new Frame("Frame F"); + f.setLayout(null); + f.setBounds(100, 100, 100, 100); + f.add(new Button("Button")); + + f.setVisible(true); + robot.waitForIdle(); + + ComponentListener cl = new ComponentAdapter() + { + public void componentMoved(ComponentEvent e) + { + componentMovedCount++; + Component c = (Component)e.getSource(); + if (!(c instanceof Window)) + { + return; + } + Point p = c.getLocationOnScreen(); + if ((p.x != rightX) || (p.y != rightY)) + { + System.err.println("Error: wrong location on screen after COMPONENT_MOVED"); + System.err.println("Location on screen is (" + p.x + ", " + p.y + ") against right location (" + rightX + ", " + rightY + ")"); + failed = true; + } + } + public void componentResized(ComponentEvent e) + { + componentResizedCount++; + } + }; + + f.addComponentListener(cl); + + componentResizedCount = componentMovedCount = 0; + rightX = 100; + rightY = 100; + f.setSize(200, 200); + robot.waitForIdle(); + checkResized("setSize", f); + + componentResizedCount = componentMovedCount = 0; + rightX = 200; + rightY = 200; + f.setLocation(200, 200); + robot.waitForIdle(); + checkMoved("setLocation", f); + + componentResizedCount = componentMovedCount = 0; + rightX = 150; + rightY = 150; + f.setBounds(150, 150, 100, 100); + robot.waitForIdle(); + checkResized("setBounds", f); + checkMoved("setBounds", f); + + Button b = new Button("B"); + b.setBounds(10, 10, 40, 40); + f.add(b); + robot.waitForIdle(); + + b.addComponentListener(cl); + + componentResizedCount = componentMovedCount = 0; + b.setBounds(20, 20, 50, 50); + robot.waitForIdle(); + checkMoved("setBounds", b); + checkResized("setBounds", b); + f.remove(b); + + Component c = new Component() {}; + c.setBounds(10, 10, 40, 40); + f.add(c); + robot.waitForIdle(); + + c.addComponentListener(cl); + + componentResizedCount = componentMovedCount = 0; + c.setBounds(20, 20, 50, 50); + robot.waitForIdle(); + checkMoved("setBounds", c); + checkResized("setBounds", c); + f.remove(c); + + if (failed) + { + MovedResizedTwiceTest.fail("Test FAILED"); + } + else + { + MovedResizedTwiceTest.pass(); + } + } + + private static void checkResized(String methodName, Component c) + { + String failMessage = null; + if (componentResizedCount == 1) + { + return; + } + else if (componentResizedCount == 0) + { + failMessage = "Test FAILED: COMPONENT_RESIZED is not sent after call to " + methodName + "()"; + } + else + { + failMessage = "Test FAILED: COMPONENT_RESIZED is sent " + componentResizedCount + " + times after call to " + methodName + "()"; + } + System.err.println("Failed component: " + c); + MovedResizedTwiceTest.fail(failMessage); + } + + private static void checkMoved(String methodName, Component c) + { + String failMessage = null; + if (componentMovedCount == 1) + { + return; + } + if (componentMovedCount == 0) + { + failMessage = "Test FAILED: COMPONENT_MOVED is not sent after call to " + methodName + "()"; + } + else + { + failMessage = "Test FAILED: COMPONENT_MOVED is sent " + componentMovedCount + " times after call to " + methodName + "()"; + } + System.err.println("Failed component: " + c); + MovedResizedTwiceTest.fail(failMessage); + } + + private static boolean theTestPassed = false; + private static boolean testGeneratedInterrupt = false; + private static String failureMessage = ""; + + private static Thread mainThread = null; + + private static int sleepTime = 300000; + + public static void main( String args[] ) throws InterruptedException + { + mainThread = Thread.currentThread(); + try + { + init(); + } + catch (TestPassedException e) + { + return; + } + + try + { + Thread.sleep(sleepTime); + throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" ); + } + catch (InterruptedException e) + { + if (!testGeneratedInterrupt) + { + throw e; + } + + testGeneratedInterrupt = false; + + if (!theTestPassed) + { + throw new RuntimeException( failureMessage ); + } + } + } + + public static synchronized void setTimeoutTo(int seconds) + { + sleepTime = seconds * 1000; + } + + public static synchronized void pass() + { + if (mainThread == Thread.currentThread()) + { + theTestPassed = true; + throw new TestPassedException(); + } + theTestPassed = true; + testGeneratedInterrupt = true; + mainThread.interrupt(); + } + + public static synchronized void fail() + { + fail("it just plain failed! :-)"); + } + + public static synchronized void fail(String whyFailed) + { + if (mainThread == Thread.currentThread()) + { + throw new RuntimeException(whyFailed); + } + theTestPassed = false; + testGeneratedInterrupt = true; + failureMessage = whyFailed; + mainThread.interrupt(); + } +} + +class TestPassedException extends RuntimeException +{ +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest.java --- a/jdk/test/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -30,7 +30,6 @@ */ import java.awt.*; import java.awt.event.*; -import sun.awt.SunToolkit; public class TextEventSequenceTest { @@ -48,43 +47,50 @@ } private static void test(String test) { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } createAndShowGUI(test); - toolkit.realSync(); + robot.waitForIdle(); initCounts(); t.setText("Hello "); - toolkit.realSync(); + robot.waitForIdle(); t.append("World! !"); - toolkit.realSync(); + robot.waitForIdle(); t.insert("from Roger Pham", 13); - toolkit.realSync(); + robot.waitForIdle(); t.replaceRange("Java Duke", 18, 28); - toolkit.realSync(); + robot.waitForIdle(); checkCounts(0, 4); initCounts(); t.setText(""); - toolkit.realSync(); + robot.waitForIdle(); t.setText(""); - toolkit.realSync(); + robot.waitForIdle(); t.setText(""); - toolkit.realSync(); + robot.waitForIdle(); checkCounts(1, 0); initCounts(); tf.setText("Hello There!"); - toolkit.realSync(); + robot.waitForIdle(); checkCounts(0, 1); initCounts(); tf.setText(""); - toolkit.realSync(); + robot.waitForIdle(); tf.setText(""); - toolkit.realSync(); + robot.waitForIdle(); tf.setText(""); - toolkit.realSync(); + robot.waitForIdle(); checkCounts(1, 0); f.dispose(); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/geom/AffineTransform/TestInvertMethods.java --- a/jdk/test/java/awt/geom/AffineTransform/TestInvertMethods.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/geom/AffineTransform/TestInvertMethods.java Mon Dec 01 12:08:17 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2014, 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 @@ -23,7 +23,7 @@ /** * @test - * @bug 4987374 + * @bug 4987374 8062163 * @summary Unit test for inversion methods: * * AffineTransform.createInverse(); @@ -188,6 +188,8 @@ double m11 = at.getScaleY(); double m02 = at.getTranslateX(); double m12 = at.getTranslateY(); + if (Math.abs(m00-1.0) < 1E-10) m00 = 1.0; + if (Math.abs(m11-1.0) < 1E-10) m11 = 1.0; if (Math.abs(m02) < 1E-10) m02 = 0.0; if (Math.abs(m12) < 1E-10) m12 = 0.0; if (Math.abs(m01) < 1E-15) m01 = 0.0; @@ -273,7 +275,7 @@ int inc = full ? 10 : 45; for (int i = -720; i <= 720; i += inc) { AffineTransform at2 = new AffineTransform(init); - at2.rotate(Math.toRadians(i)); + at2.rotate(i / 180.0 * Math.PI); if (verbose) System.out.println("*Rotate("+i+") = "+at2); next.test(at2, full); } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeCrashTest.java --- a/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeCrashTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeCrashTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -26,26 +26,25 @@ @bug 8041490 @summary tests that the WarningWindow's surface is invalidated on dispose @author Petr Pchelko - @run main/othervm WarningWindowDisposeCrashTest + @run main/othervm/policy=policy -Djava.security.manager WarningWindowDisposeCrashTest */ -import sun.applet.AppletSecurity; -import sun.awt.SunToolkit; import java.awt.*; public class WarningWindowDisposeCrashTest { public static void main(String[] args) throws Exception { - System.setSecurityManager(new AppletSecurity() { - @Override - public void checkPackageAccess (String s){ - } - }); - Frame f = new Frame(); f.setVisible(true); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + Robot robot; + try{ + robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Cannot create Robot"); + } Thread.sleep(1000); f.dispose(); // If the bug is present VM could crash after this call diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeTest.java --- a/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -31,12 +31,11 @@ @run main WarningWindowDisposeTest */ -import sun.applet.AppletSecurity; -import sun.awt.SunToolkit; - import java.awt.*; import java.awt.Toolkit; import java.util.concurrent.atomic.AtomicBoolean; +import java.security.Permission; +import java.io.File; import test.java.awt.regtesthelpers.process.ProcessCommunicator; import test.java.awt.regtesthelpers.process.ProcessResults; @@ -57,7 +56,9 @@ }, "TimeoutThread").start(); String classpath = System.getProperty("java.class.path"); - ProcessResults pres = ProcessCommunicator.executeChildProcess(TestApplication.class, classpath, new String[0]); + String policyPath = System.getProperty("test.src")+File.separatorChar+"policy"; + System.out.println("policyPath in main: "+policyPath); + ProcessResults pres = ProcessCommunicator.executeChildProcess(TestApplication.class, classpath+" -Djava.security.manager -Djava.security.policy="+policyPath, new String[0]); passed.set(true); if (pres.getStdErr() != null && pres.getStdErr().length() > 0) { System.err.println("========= Child VM System.err ========"); @@ -74,14 +75,16 @@ public static class TestApplication { public static void main(String[] args) throws Exception { - System.setSecurityManager(new AppletSecurity() { - @Override - public void checkPackageAccess (String s){ - } - }); + Robot robot; + try{ + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Cannot create Robot"); + } Frame f = new Frame("Test frame"); f.setVisible(true); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); Thread.sleep(500); f.setVisible(false); f.dispose(); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/awt/security/WarningWindowDisposeTest/policy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/security/WarningWindowDisposeTest/policy Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,3 @@ +grant { + permission java.awt.AWTPermission "createRobot"; +}; diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/lang/invoke/LFCaching/LFGarbageCollectedTest.java --- a/jdk/test/java/lang/invoke/LFCaching/LFGarbageCollectedTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/lang/invoke/LFCaching/LFGarbageCollectedTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -31,7 +31,7 @@ * @build TestMethods * @build LambdaFormTestCase * @build LFGarbageCollectedTest - * @run main/othervm/timeout=600 -Djava.lang.invoke.MethodHandle.USE_LF_EDITOR=true -DtestLimit=150 LFGarbageCollectedTest + * @run main/othervm LFGarbageCollectedTest */ import java.lang.invoke.MethodHandle; diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/lang/invoke/LFCaching/LFMultiThreadCachingTest.java --- a/jdk/test/java/lang/invoke/LFCaching/LFMultiThreadCachingTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/lang/invoke/LFCaching/LFMultiThreadCachingTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -31,7 +31,7 @@ * @build LambdaFormTestCase * @build LFCachingTestCase * @build LFMultiThreadCachingTest - * @run main/othervm/timeout=300 -Djava.lang.invoke.MethodHandle.USE_LF_EDITOR=true LFMultiThreadCachingTest + * @run main/othervm LFMultiThreadCachingTest */ import java.lang.invoke.MethodHandle; diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java --- a/jdk/test/java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -31,7 +31,7 @@ * @build LambdaFormTestCase * @build LFCachingTestCase * @build LFSingleThreadCachingTest - * @run main/othervm/timeout=300 -Djava.lang.invoke.MethodHandle.USE_LF_EDITOR=true LFSingleThreadCachingTest + * @run main/othervm LFSingleThreadCachingTest */ import java.lang.invoke.MethodHandle; diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/lang/invoke/LFCaching/LambdaFormTestCase.java --- a/jdk/test/java/lang/invoke/LFCaching/LambdaFormTestCase.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/java/lang/invoke/LFCaching/LambdaFormTestCase.java Mon Dec 01 12:08:17 2014 +0100 @@ -27,6 +27,7 @@ import java.lang.reflect.Method; import java.util.Collection; import java.util.function.Function; +import jdk.testlibrary.Utils; /** * Lambda forms caching test case class. Contains all necessary test routines to @@ -41,6 +42,7 @@ private final static String INTERNAL_FORM_METHOD_NAME = "internalForm"; private static final double ITERATIONS_TO_CODE_CACHE_SIZE_RATIO = 45 / (128.0 * 1024 * 1024); + private static final long TIMEOUT = Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT); /** * Reflection link to {@code j.l.i.MethodHandle.internalForm} method. It is @@ -120,6 +122,7 @@ System.out.printf("Number of iterations is set to %d (%d cases)%n", iterations, iterations * testCaseNum); System.out.flush(); + long startTime = System.currentTimeMillis(); for (long i = 0; i < iterations; i++) { System.err.println(String.format("Iteration %d:", i)); for (TestMethods testMethod : testMethods) { @@ -137,6 +140,14 @@ } testCounter++; } + long passedTime = System.currentTimeMillis() - startTime; + long avgIterTime = passedTime / (i + 1); + long remainTime = TIMEOUT - passedTime; + if (avgIterTime > 2 * remainTime) { + System.err.printf("Stopping iterations because of lack of time.%n" + + "Increase timeout factor for more iterations.%n"); + break; + } } if (!passed) { throw new Error(String.format("%d of %d test cases FAILED! %n" diff -r a5647c044923 -r 5bec79a6bbca jdk/test/java/util/logging/LogManager/Configuration/ParentLoggerWithHandlerGC.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/logging/LogManager/Configuration/ParentLoggerWithHandlerGC.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,517 @@ +/* + * Copyright (c) 2014, 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.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FilePermission; +import java.io.IOException; +import java.lang.ref.Reference; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.WeakReference; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Permissions; +import java.security.Policy; +import java.security.ProtectionDomain; +import java.util.Arrays; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.FileHandler; +import java.util.logging.Handler; +import java.util.logging.LogManager; +import java.util.logging.Logger; +import java.util.logging.LoggingPermission; + +/** + * @test + * @bug 8060132 + * @summary tests that FileHandlers configured on abstract nodes in logging.properties + * will be closed by reset(). + * @run main/othervm ParentLoggerWithHandlerGC UNSECURE + * @run main/othervm ParentLoggerWithHandlerGC SECURE + * @author danielfuchs + */ +public class ParentLoggerWithHandlerGC { + + /** + * We will test the handling of abstract logger nodes with file handlers in + * two configurations: + * UNSECURE: No security manager. + * SECURE: With the security manager present - and the required + * permissions granted. + */ + public static enum TestCase { + UNSECURE, SECURE; + public void run(Properties propertyFile) throws Exception { + System.out.println("Running test case: " + name()); + Configure.setUp(this, propertyFile); + test(this.name() + " " + propertyFile.getProperty("test.name"), propertyFile); + } + } + + + private static final String PREFIX = + "FileHandler-" + UUID.randomUUID() + ".log"; + private static final String userDir = System.getProperty("user.dir", "."); + private static final boolean userDirWritable = Files.isWritable(Paths.get(userDir)); + + static enum ConfigMode { DEFAULT, ENSURE_CLOSE_ON_RESET_TRUE, ENSURE_CLOSE_ON_RESET_FALSE } + + private static final List properties; + static { + Properties props1 = new Properties(); + props1.setProperty("test.name", "parent logger with handler"); + props1.setProperty("test.config.mode", ConfigMode.DEFAULT.name()); + props1.setProperty(FileHandler.class.getName() + ".pattern", PREFIX); + props1.setProperty(FileHandler.class.getName() + ".limit", String.valueOf(Integer.MAX_VALUE)); + props1.setProperty(FileHandler.class.getName() + ".level", "ALL"); + props1.setProperty(FileHandler.class.getName() + ".formatter", "java.util.logging.SimpleFormatter"); + props1.setProperty("com.foo.handlers", FileHandler.class.getName()); + props1.setProperty("com.bar.level", "FINEST"); + + Properties props2 = new Properties(); + props2.setProperty("test.name", "parent logger with handler"); + props2.setProperty("test.config.mode", ConfigMode.ENSURE_CLOSE_ON_RESET_TRUE.name()); + props2.setProperty(FileHandler.class.getName() + ".pattern", PREFIX); + props2.setProperty(FileHandler.class.getName() + ".limit", String.valueOf(Integer.MAX_VALUE)); + props2.setProperty(FileHandler.class.getName() + ".level", "ALL"); + props2.setProperty(FileHandler.class.getName() + ".formatter", "java.util.logging.SimpleFormatter"); + props2.setProperty("com.foo.handlers", FileHandler.class.getName()); + props2.setProperty("com.foo.handlers.ensureCloseOnReset", "true"); + props2.setProperty("com.bar.level", "FINEST"); + + Properties props3 = new Properties(); + props3.setProperty("test.name", "parent logger with handler"); + props3.setProperty("test.config.mode", ConfigMode.ENSURE_CLOSE_ON_RESET_FALSE.name()); + props3.setProperty(FileHandler.class.getName() + ".pattern", PREFIX); + props3.setProperty(FileHandler.class.getName() + ".limit", String.valueOf(Integer.MAX_VALUE)); + props3.setProperty(FileHandler.class.getName() + ".level", "ALL"); + props3.setProperty(FileHandler.class.getName() + ".formatter", "java.util.logging.SimpleFormatter"); + props3.setProperty("com.foo.handlers", FileHandler.class.getName()); + props3.setProperty("com.foo.handlers.ensureCloseOnReset", "false"); + props3.setProperty("com.bar.level", "FINEST"); + + properties = Collections.unmodifiableList(Arrays.asList( + props1, props2, props3)); + } + + public static void main(String... args) throws Exception { + + + if (args == null || args.length == 0) { + args = new String[] { + TestCase.UNSECURE.name(), + TestCase.SECURE.name(), + }; + } + + try { + for (String testName : args) { + for (Properties propertyFile : properties) { + TestCase test = TestCase.valueOf(testName); + test.run(propertyFile); + } + } + } finally { + if (userDirWritable) { + Configure.doPrivileged(() -> { + // cleanup - delete files that have been created + try { + Files.list(Paths.get(userDir)) + .filter((f) -> f.toString().contains(PREFIX)) + .forEach((f) -> { + try { + System.out.println("deleting " + f); + Files.delete(f); + } catch(Throwable t) { + System.err.println("Failed to delete " + f + ": " + t); + } + }); + } catch(Throwable t) { + System.err.println("Cleanup failed to list files: " + t); + t.printStackTrace(); + } + }); + } + } + } + + static class Configure { + static Policy policy = null; + static final AtomicBoolean allowAll = new AtomicBoolean(false); + static void setUp(TestCase test, Properties propertyFile) { + switch (test) { + case SECURE: + if (policy == null && System.getSecurityManager() != null) { + throw new IllegalStateException("SecurityManager already set"); + } else if (policy == null) { + policy = new SimplePolicy(TestCase.SECURE, allowAll); + Policy.setPolicy(policy); + System.setSecurityManager(new SecurityManager()); + } + if (System.getSecurityManager() == null) { + throw new IllegalStateException("No SecurityManager."); + } + if (policy == null) { + throw new IllegalStateException("policy not configured"); + } + break; + case UNSECURE: + if (System.getSecurityManager() != null) { + throw new IllegalStateException("SecurityManager already set"); + } + break; + default: + new InternalError("No such testcase: " + test); + } + doPrivileged(() -> { + try { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + propertyFile.store(bytes, propertyFile.getProperty("test.name")); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes.toByteArray()); + LogManager.getLogManager().readConfiguration(bais); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + }); + } + static void doPrivileged(Runnable run) { + allowAll.set(true); + try { + run.run(); + } finally { + allowAll.set(false); + } + } + static T callPrivileged(Callable call) throws Exception { + allowAll.set(true); + try { + return call.call(); + } finally { + allowAll.set(false); + } + } + } + + @FunctionalInterface + public static interface FileHandlerSupplier { + public FileHandler test() throws Exception; + } + + static final class TestAssertException extends RuntimeException { + TestAssertException(String msg) { + super(msg); + } + } + + private static void assertEquals(long expected, long received, String msg) { + if (expected != received) { + throw new TestAssertException("Unexpected result for " + msg + + ".\n\texpected: " + expected + + "\n\tactual: " + received); + } else { + System.out.println("Got expected " + msg + ": " + received); + } + } + + + public static void test(String name, Properties props) throws Exception { + ConfigMode configMode = ConfigMode.valueOf(props.getProperty("test.config.mode")); + System.out.println("\nTesting: " + name + " mode=" + configMode); + if (!userDirWritable) { + throw new RuntimeException("Not writable: "+userDir); + } + switch(configMode) { + case DEFAULT: + case ENSURE_CLOSE_ON_RESET_TRUE: + testCloseOnResetTrue(name, props); break; + case ENSURE_CLOSE_ON_RESET_FALSE: + testCloseOnResetFalse(name, props); break; + default: + throw new RuntimeException("Unknwown mode: " + configMode); + } + } + + + // Test a configuration which has either + // com.foo.handlers.ensureCloseOnReset=true, or where + // com.foo.handlers.ensureCloseOnReset is not specified. + public static void testCloseOnResetTrue(String name, Properties props) + throws Exception { + Logger fooChild = Logger.getLogger("com.foo.child"); + fooChild.info("hello world"); + Logger barChild = Logger.getLogger("com.bar.child"); + barChild.info("hello world"); + + ReferenceQueue queue = new ReferenceQueue(); + WeakReference fooRef = new WeakReference<>(Logger.getLogger("com.foo"), queue); + if (fooRef.get() != fooChild.getParent()) { + throw new RuntimeException("Unexpected parent logger: " + + fooChild.getParent() +"\n\texpected: " + fooRef.get()); + } + WeakReference barRef = new WeakReference<>(Logger.getLogger("com.bar"), queue); + if (barRef.get() != barChild.getParent()) { + throw new RuntimeException("Unexpected parent logger: " + + barChild.getParent() +"\n\texpected: " + barRef.get()); + } + fooChild = barChild = null; + Reference ref2 = null; + while ((ref2 = queue.poll()) == null) { + System.gc(); + Thread.sleep(1000); + } + Throwable failed = null; + try { + do { + if (ref2 != barRef) { + throw new RuntimeException("Unexpected reference: " + + ref2 +"\n\texpected: " + barRef); + } + if (ref2.get() != null) { + throw new RuntimeException("Referent not cleared: " + + ref2.get()); + } + System.out.println("Got barRef"); + System.gc(); + Thread.sleep(1000); + } while( (ref2 = queue.poll()) != null); + System.out.println("Parent logger GCed"); + } catch(Throwable t) { + failed = t; + } finally { + final Throwable suppressed = failed; + Configure.doPrivileged(() -> LogManager.getLogManager().reset()); + Configure.doPrivileged(() -> { + try { + StringBuilder builder = new StringBuilder(); + Files.list(Paths.get(userDir)) + .filter((f) -> f.toString().contains(PREFIX)) + .filter((f) -> f.toString().endsWith(".lck")) + .forEach((f) -> { + builder.append(f.toString()).append('\n'); + }); + if (!builder.toString().isEmpty()) { + throw new RuntimeException("Lock files not cleaned:\n" + + builder.toString()); + } + } catch(RuntimeException | Error x) { + if (suppressed != null) x.addSuppressed(suppressed); + throw x; + } catch(Exception x) { + if (suppressed != null) x.addSuppressed(suppressed); + throw new RuntimeException(x); + } + }); + while ((ref2 = queue.poll()) == null) { + System.gc(); + Thread.sleep(1000); + } + if (ref2 != fooRef) { + throw new RuntimeException("Unexpected reference: " + + ref2 +"\n\texpected: " + fooRef); + } + if (ref2.get() != null) { + throw new RuntimeException("Referent not cleared: " + ref2.get()); + } + System.out.println("Got fooRef after reset()"); + + } + if (failed != null) { + // should rarely happen... + throw new RuntimeException(failed); + } + + } + + private static Handler getHandlerToClose() throws Exception { + return Configure.callPrivileged( + () -> Logger.getLogger("com.foo.child").getParent().getHandlers()[0]); + } + + // Test a configuration which has com.foo.handlers.ensureCloseOnReset=false + public static void testCloseOnResetFalse(String name, Properties props) + throws Exception { + Logger fooChild = Logger.getLogger("com.foo.child"); + fooChild.info("hello world"); + Logger barChild = Logger.getLogger("com.bar.child"); + barChild.info("hello world"); + + Handler toClose = getHandlerToClose(); + + ReferenceQueue queue = new ReferenceQueue(); + WeakReference fooRef = new WeakReference<>(Logger.getLogger("com.foo"), queue); + if (fooRef.get() != fooChild.getParent()) { + throw new RuntimeException("Unexpected parent logger: " + + fooChild.getParent() +"\n\texpected: " + fooRef.get()); + } + WeakReference barRef = new WeakReference<>(Logger.getLogger("com.bar"), queue); + if (barRef.get() != barChild.getParent()) { + throw new RuntimeException("Unexpected parent logger: " + + barChild.getParent() +"\n\texpected: " + barRef.get()); + } + fooChild = barChild = null; + Reference ref2 = null; + Set> expectedRefs = new HashSet<>(Arrays.asList(fooRef, barRef)); + Throwable failed = null; + try { + int l=0; + while (failed == null && !expectedRefs.isEmpty()) { + int max = 60; + while ((ref2 = queue.poll()) == null) { + if (l > 0 && max-- <= 0) { + throw new RuntimeException("Logger #2 not GC'ed!" + + " max too short (max=60) or " + + "com.foo.handlers.ensureCloseOnReset=false" + + " does not work"); + } + System.gc(); + Thread.sleep(1000); + } + do { + if (!expectedRefs.contains(ref2)) { + throw new RuntimeException("Unexpected reference: " + + ref2 +"\n\texpected: " + expectedRefs); + } + if (ref2.get() != null) { + throw new RuntimeException("Referent not cleared: " + + ref2.get()); + } + expectedRefs.remove(ref2); + System.out.println("Got "+ + (ref2 == barRef ? "barRef" + : (ref2 == fooRef ? "fooRef" + : ref2.toString()))); + System.gc(); + Thread.sleep(1000); + System.out.println("Logger #" + (++l) + " GCed"); + } while( (ref2 = queue.poll()) != null); + } + } catch(Throwable t) { + failed = t; + } finally { + final Throwable suppressed = failed; + Configure.doPrivileged(() -> LogManager.getLogManager().reset()); + Configure.doPrivileged(() -> { + try { + toClose.close(); + StringBuilder builder = new StringBuilder(); + Files.list(Paths.get(userDir)) + .filter((f) -> f.toString().contains(PREFIX)) + .filter((f) -> f.toString().endsWith(".lck")) + .forEach((f) -> { + builder.append(f.toString()).append('\n'); + }); + if (!builder.toString().isEmpty()) { + throw new RuntimeException("Lock files not cleaned:\n" + builder.toString()); + } + } catch(RuntimeException | Error x) { + if (suppressed != null) x.addSuppressed(suppressed); + throw x; + } catch(Exception x) { + if (suppressed != null) x.addSuppressed(suppressed); + throw new RuntimeException(x); + } + }); + } + if (failed != null) { + // should rarely happen... + throw new RuntimeException(failed); + } + + } + + + final static class PermissionsBuilder { + final Permissions perms; + public PermissionsBuilder() { + this(new Permissions()); + } + public PermissionsBuilder(Permissions perms) { + this.perms = perms; + } + public PermissionsBuilder add(Permission p) { + perms.add(p); + return this; + } + public PermissionsBuilder addAll(PermissionCollection col) { + if (col != null) { + for (Enumeration e = col.elements(); e.hasMoreElements(); ) { + perms.add(e.nextElement()); + } + } + return this; + } + public Permissions toPermissions() { + final PermissionsBuilder builder = new PermissionsBuilder(); + builder.addAll(perms); + return builder.perms; + } + } + + public static class SimplePolicy extends Policy { + + final Permissions permissions; + final Permissions allPermissions; + final AtomicBoolean allowAll; + public SimplePolicy(TestCase test, AtomicBoolean allowAll) { + this.allowAll = allowAll; + permissions = new Permissions(); + permissions.add(new LoggingPermission("control", null)); + permissions.add(new FilePermission(PREFIX+".lck", "read,write,delete")); + permissions.add(new FilePermission(PREFIX, "read,write")); + + // these are used for configuring the test itself... + allPermissions = new Permissions(); + allPermissions.add(new java.security.AllPermission()); + + } + + @Override + public boolean implies(ProtectionDomain domain, Permission permission) { + if (allowAll.get()) return allPermissions.implies(permission); + return permissions.implies(permission); + } + + @Override + public PermissionCollection getPermissions(CodeSource codesource) { + return new PermissionsBuilder().addAll(allowAll.get() + ? allPermissions : permissions).toPermissions(); + } + + @Override + public PermissionCollection getPermissions(ProtectionDomain domain) { + return new PermissionsBuilder().addAll(allowAll.get() + ? allPermissions : permissions).toPermissions(); + } + } + +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/DataTransfer/8059739/bug8059739.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/DataTransfer/8059739/bug8059739.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2014, 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 8059739 + @summary Dragged and Dropped data is corrupted for two data types + @author Anton Nashatyrev +*/ + +import javax.swing.*; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class bug8059739 { + + private static boolean passed = true; + + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + try { + runTest(); + } catch (Exception e) { + e.printStackTrace(); + passed = false; + } + } + }); + + if (!passed) { + throw new RuntimeException("Test FAILED."); + } else { + System.out.println("Passed."); + } + } + + private static void runTest() throws Exception { + String testString = "my string"; + JTextField tf = new JTextField(testString); + tf.selectAll(); + Clipboard clipboard = new Clipboard("clip"); + tf.getTransferHandler().exportToClipboard(tf, clipboard, TransferHandler.COPY); + DataFlavor[] dfs = clipboard.getAvailableDataFlavors(); + for (DataFlavor df: dfs) { + String charset = df.getParameter("charset"); + if (InputStream.class.isAssignableFrom(df.getRepresentationClass()) && + charset != null) { + BufferedReader br = new BufferedReader(new InputStreamReader( + (InputStream) clipboard.getData(df), charset)); + String s = br.readLine(); + System.out.println("Content: '" + s + "'"); + passed &= s.contains(testString); + } + } + } +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JButton/JButtonPaintNPE/JButtonPaintNPE.java --- a/jdk/test/javax/swing/JButton/JButtonPaintNPE/JButtonPaintNPE.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JButton/JButtonPaintNPE/JButtonPaintNPE.java Mon Dec 01 12:08:17 2014 +0100 @@ -31,12 +31,13 @@ import javax.swing.JFrame; import javax.swing.SwingUtilities; -import sun.awt.SunToolkit; - /** * @test * @bug 8009919 * @author Sergey Bylokhov + * @library ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @run main JButtonPaintNPE */ public final class JButtonPaintNPE { @@ -69,9 +70,11 @@ private static void sleep() { try { - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); - Thread.sleep(1000); - } catch (final InterruptedException ignored) { - } + ExtendedRobot robot = new ExtendedRobot(); + robot.waitForIdle(1000); + }catch(Exception ex) { + ex.printStackTrace(); + throw new Error("Unexpected Failure"); + } } } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JComboBox/6406264/bug6406264.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JComboBox/6406264/bug6406264.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2006, 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 6406264 + @summary Tests that JComboBox's focusable popup can be shown. + @author Mikhail Lapshin + @run main bug6406264 + */ + +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; +import javax.swing.plaf.basic.BasicComboBoxUI; +import javax.swing.plaf.basic.ComboPopup; +import javax.swing.plaf.basic.BasicComboPopup; +import java.awt.*; + +public class bug6406264 extends JComboBox { + + static JFrame frame; + static bug6406264 comboBox; + + public static void main(String[] args) throws Exception { + + Robot robot = new Robot(); + // Setup and show frame + SwingUtilities.invokeAndWait( + new Runnable() { + public void run() { + frame = new JFrame("JComboBox6406264 test"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + comboBox = new bug6406264("One", "Two", "Three"); + frame.getContentPane().add(comboBox); + + frame.setLocationRelativeTo(null); + frame.pack(); + frame.setVisible(true); + } + } + ); + + robot.waitForIdle(); + + // Show popup + SwingUtilities.invokeAndWait( + new Runnable() { + public void run() { + comboBox.showPopup(); + } + }); + robot.waitForIdle(); + + // Check that popup is visible + SwingUtilities.invokeAndWait( + new Runnable() { + public void run() { + if (comboBox.getUI().isPopupVisible(comboBox) == false) + { + throw new RuntimeException("A focusable popup is not visible " + + "in JComboBox!"); + } + } + } + ); + + frame.dispose(); + } + + public bug6406264(Object ... items) { + super(items); + } + + public void updateUI() { + setUI(new CustomComboBoxUI()); + } + + // Use FocusablePopup for our JComboBox + private class CustomComboBoxUI extends BasicComboBoxUI { + protected ComboPopup createPopup() { + return new FocusablePopup(bug6406264.this); + } + } + + // Popup window which can take a focus + private class FocusablePopup extends BasicComboPopup { + public FocusablePopup(JComboBox combo) { + super(combo); + } + + public boolean isFocusable() { + return true; + } + } +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JComboBox/8015300/Test8015300.java --- a/jdk/test/javax/swing/JComboBox/8015300/Test8015300.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JComboBox/8015300/Test8015300.java Mon Dec 01 12:08:17 2014 +0100 @@ -41,10 +41,13 @@ * @bug 8015300 * @summary Tests that editable combobox select all text * @author Sergey Malenkov + * @library ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @run main Test8015300 */ public class Test8015300 { - private static final SunToolkit STK = (SunToolkit) Toolkit.getDefaultToolkit(); + private static final ExtendedRobot robot = createRobot(); private static final String[] ITEMS = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; @@ -113,7 +116,15 @@ combo.setSelectedIndex(index); } }); - STK.realSync(); - Thread.sleep(50L); + robot.waitForIdle(50); + } + private static ExtendedRobot createRobot() { + try { + ExtendedRobot robot = new ExtendedRobot(); + return robot; + }catch(Exception ex) { + ex.printStackTrace(); + throw new Error("Unexpected Failure"); + } } } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JComboBox/ShowPopupAfterHidePopupTest/ShowPopupAfterHidePopupTest.java --- a/jdk/test/javax/swing/JComboBox/ShowPopupAfterHidePopupTest/ShowPopupAfterHidePopupTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JComboBox/ShowPopupAfterHidePopupTest/ShowPopupAfterHidePopupTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -25,6 +25,7 @@ @bug 8006417 @summary JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X @author Anton Litvinov + @run main ShowPopupAfterHidePopupTest */ import java.awt.*; @@ -32,8 +33,6 @@ import javax.swing.*; import javax.swing.plaf.metal.*; -import sun.awt.SunToolkit; - public class ShowPopupAfterHidePopupTest { private static JFrame frame = null; private static JComboBox comboBox = null; @@ -41,6 +40,7 @@ public static void main(String[] args) throws Exception { UIManager.setLookAndFeel(new MetalLookAndFeel()); + Robot robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { @@ -51,8 +51,7 @@ frame.setVisible(true); } }); - final SunToolkit toolkit = (SunToolkit)Toolkit.getDefaultToolkit(); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -62,7 +61,7 @@ comboBox.showPopup(); } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JComponent/6989617/bug6989617.java --- a/jdk/test/javax/swing/JComponent/6989617/bug6989617.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JComponent/6989617/bug6989617.java Mon Dec 01 12:08:17 2014 +0100 @@ -28,8 +28,6 @@ @run main bug6989617 */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; @@ -38,7 +36,7 @@ private static JButton button; public static void main(String... args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { JFrame frame = new JFrame(); @@ -56,14 +54,14 @@ // Testing the panel as a painting origin, // the panel.paintImmediately() must be triggered // when button.repaint() is called - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { panel.resetPaintRectangle(); button.repaint(); } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { Rectangle pr = panel.getPaintRectangle(); @@ -78,7 +76,7 @@ // Testing the panel as NOT a painting origin // the panel.paintImmediately() must NOT be triggered // when button.repaint() is called - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { panel.resetPaintRectangle(); @@ -89,7 +87,7 @@ button.repaint(); } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { if(panel.getPaintRectangle() != null) { diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JEditorPane/4492274/bug4492274.java --- a/jdk/test/javax/swing/JEditorPane/4492274/bug4492274.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JEditorPane/4492274/bug4492274.java Mon Dec 01 12:08:17 2014 +0100 @@ -25,10 +25,9 @@ * @bug 4492274 * @summary Tests if JEditorPane.getPage() correctly returns anchor reference. * @author Denis Sharypov + * @run main bug4492274 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.text.html.HTMLEditorKit; import java.awt.*; @@ -42,8 +41,8 @@ private static JEditorPane jep; public static void main(String args[]) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { @@ -51,7 +50,7 @@ } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -65,7 +64,7 @@ } }); - toolkit.realSync(); + robot.waitForIdle(); if (getPageAnchor() == null) { throw new RuntimeException("JEditorPane.getPage() returns null anchor reference"); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JInternalFrame/4251301/bug4251301.java --- a/jdk/test/javax/swing/JInternalFrame/4251301/bug4251301.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JInternalFrame/4251301/bug4251301.java Mon Dec 01 12:08:17 2014 +0100 @@ -24,6 +24,8 @@ @bug 4251301 @summary Keybinding for show/hide the system menu. @author Andrey Pikalev + @library ../../../../lib/testlibrary + @build jdk.testlibrary.OSInfo @run main/manual bug4251301 */ @@ -32,12 +34,10 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.*; -import sun.awt.OSInfo; -import sun.awt.SunToolkit; +import jdk.testlibrary.OSInfo; public class bug4251301 { - private static final SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); static Test test = new Test(); public static void main(String[] args) throws Exception { if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) { @@ -50,7 +50,8 @@ createAndShowGUI(); } }); - toolkit.realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); test.waitTestResult(); } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JInternalFrame/6647340/bug6647340.java --- a/jdk/test/javax/swing/JInternalFrame/6647340/bug6647340.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JInternalFrame/6647340/bug6647340.java Mon Dec 01 12:08:17 2014 +0100 @@ -26,10 +26,11 @@ * @summary Checks that iconified internal frame follows * the main frame borders properly. * @author Mikhail Lapshin + * @library ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @run main bug6647340 */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; import java.beans.PropertyVetoException; @@ -38,6 +39,7 @@ private JFrame frame; private Point location; private JInternalFrame jif; + private static ExtendedRobot robot = createRobot(); public static void main(String[] args) throws Exception { final bug6647340 test = new bug6647340(); @@ -74,13 +76,13 @@ } private void test() throws Exception { - realSync(); + sync(); test1(); - realSync(); + sync(); check1(); - realSync(); + sync(); test2(); - realSync(); + sync(); check2(); } @@ -101,14 +103,14 @@ setIcon(false); } }); - realSync(); + sync(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { Dimension size = frame.getSize(); frame.setSize(size.width - 100, size.height - 100); } }); - realSync(); + sync(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { setIcon(true); @@ -132,8 +134,17 @@ } } - private static void realSync() { - ((SunToolkit) (Toolkit.getDefaultToolkit())).realSync(); + private static void sync() { + robot.waitForIdle(); + } + private static ExtendedRobot createRobot() { + try { + ExtendedRobot robot = new ExtendedRobot(); + return robot; + }catch(Exception ex) { + ex.printStackTrace(); + throw new Error("Unexpected Failure"); + } } private void setIcon(boolean b) { diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JInternalFrame/6725409/bug6725409.java --- a/jdk/test/javax/swing/JInternalFrame/6725409/bug6725409.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JInternalFrame/6725409/bug6725409.java Mon Dec 01 12:08:17 2014 +0100 @@ -26,6 +26,9 @@ * @summary Checks that JInternalFrame's system menu * can be localized during run-time * @author Mikhail Lapshin + * @library ../../../../lib/testlibrary/ + * @build ExtendedRobot + * @run main bug6725409 */ import javax.swing.*; @@ -36,6 +39,7 @@ private JInternalFrame iFrame; private TestTitlePane testTitlePane; private boolean passed; + private static ExtendedRobot robot = createRobot(); public static void main(String[] args) throws Exception { try { @@ -53,19 +57,19 @@ bug6725409.setupUIStep1(); } }); - realSync(); + sync(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { bug6725409.setupUIStep2(); } }); - realSync(); + sync(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { bug6725409.test(); } }); - realSync(); + sync(); bug6725409.checkResult(); } finally { if (bug6725409.frame != null) { @@ -137,8 +141,17 @@ } } - private static void realSync() { - ((sun.awt.SunToolkit) (Toolkit.getDefaultToolkit())).realSync(); + private static void sync() { + robot.waitForIdle(); + } + private static ExtendedRobot createRobot() { + try { + ExtendedRobot robot = new ExtendedRobot(); + return robot; + }catch(Exception ex) { + ex.printStackTrace(); + throw new Error("Unexpected Failure"); + } } // Extend WindowsInternalFrameTitlePane to get access to systemPopupMenu diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JLayer/6824395/bug6824395.java --- a/jdk/test/javax/swing/JLayer/6824395/bug6824395.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JLayer/6824395/bug6824395.java Mon Dec 01 12:08:17 2014 +0100 @@ -25,11 +25,12 @@ * @test * @summary Checks that JLayer inside JViewport works is correctly laid out * @author Alexander Potochkin + * @library ../../../../lib/testlibrary/ + * @build ExtendedRobot * @run main bug6824395 */ -import sun.awt.SunToolkit; import javax.swing.*; import javax.swing.plaf.LayerUI; @@ -40,7 +41,6 @@ static JScrollPane scrollPane; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { JFrame frame = new JFrame("testing"); @@ -68,7 +68,13 @@ frame.setVisible(true); } }); - toolkit.realSync(); + try { + ExtendedRobot robot = new ExtendedRobot(); + robot.waitForIdle(300); + }catch(Exception ex) { + ex.printStackTrace(); + throw new Error("Unexpected Failure"); + } SwingUtilities.invokeAndWait(new Runnable() { public void run() { if (scrollPane.getViewportBorderBounds().width != scrollPane.getViewport().getView().getWidth()) { diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JPopupMenu/6583251/bug6583251.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JPopupMenu/6583251/bug6583251.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2011, 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 6583251 +@summary One more ClassCastException in Swing with TrayIcon +@author Alexander Potochkin +@run main bug6583251 +*/ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; + +public class bug6583251 { + private static JFrame frame; + private static JPopupMenu menu; + + private static void createGui() { + frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JPanel panel = new JPanel(); + menu = new JPopupMenu(); + menu.add(new JMenuItem("item")); + panel.setComponentPopupMenu(menu); + frame.add(panel); + + frame.setSize(200, 200); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + public static void main(String[] args) throws Exception { + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + createGui(); + } + }); + + Robot robot = new Robot(); + robot.waitForIdle(); + menu.show(frame, 0, 0); + robot.waitForIdle(); + + TrayIcon trayIcon = new TrayIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)); + MouseEvent ev = new MouseEvent( + new JButton(), MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, 0, 0, 1, false); + ev.setSource(trayIcon); + Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(ev); + } +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JPopupMenu/6691503/bug6691503.java --- a/jdk/test/javax/swing/JPopupMenu/6691503/bug6691503.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JPopupMenu/6691503/bug6691503.java Mon Dec 01 12:08:17 2014 +0100 @@ -31,8 +31,6 @@ * @run main bug6691503 */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; @@ -93,7 +91,13 @@ } private void checkResult() { - ((SunToolkit)(Toolkit.getDefaultToolkit())).realSync(); + try { + Robot robot = new Robot(); + robot.waitForIdle(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } if (!isAlwaysOnTop1 || isAlwaysOnTop2) { throw new RuntimeException("Malicious applet can show always-on-top " + "popup menu which has whole screen size"); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JPopupMenu/6694823/bug6694823.java --- a/jdk/test/javax/swing/JPopupMenu/6694823/bug6694823.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JPopupMenu/6694823/bug6694823.java Mon Dec 01 12:08:17 2014 +0100 @@ -32,25 +32,25 @@ import javax.swing.*; import java.awt.*; -import sun.awt.SunToolkit; import java.security.Permission; -import sun.awt.AWTPermissions; public class bug6694823 { private static JFrame frame; private static JPopupMenu popup; - private static SunToolkit toolkit; + private static Toolkit toolkit; private static Insets screenInsets; + private static Robot robot; public static void main(String[] args) throws Exception { - toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + robot = new Robot(); + toolkit = Toolkit.getDefaultToolkit(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { createGui(); } }); - toolkit.realSync(); + robot.waitForIdle(); // Get screen insets screenInsets = toolkit.getScreenInsets(frame.getGraphicsConfiguration()); @@ -61,12 +61,9 @@ System.setSecurityManager(new SecurityManager(){ - private String allowsAlwaysOnTopPermission = - AWTPermissions.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION.getName(); - @Override public void checkPermission(Permission perm) { - if (allowsAlwaysOnTopPermission.equals(perm.getName())) { + if (perm.getName().equals("setWindowAlwaysOnTop") ) { throw new SecurityException(); } } @@ -107,7 +104,7 @@ }); // Ensure frame is visible - toolkit.realSync(); + robot.waitForIdle(); final Point point = new Point(); SwingUtilities.invokeAndWait(new Runnable() { @@ -120,7 +117,7 @@ }); // Ensure popup is visible - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JScrollBar/4865918/bug4865918.java --- a/jdk/test/javax/swing/JScrollBar/4865918/bug4865918.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JScrollBar/4865918/bug4865918.java Mon Dec 01 12:08:17 2014 +0100 @@ -33,15 +33,14 @@ import java.awt.*; import java.awt.event.*; import java.util.*; -import sun.awt.SunToolkit; public class bug4865918 { private static TestScrollBar sbar; public static void main(String[] argv) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -49,7 +48,7 @@ } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @@ -59,7 +58,7 @@ } }); - toolkit.realSync(); + robot.waitForIdle(); int value = getValue(); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JScrollPane/6274267/bug6274267.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JScrollPane/6274267/bug6274267.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2011, 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 6274267 + @summary Checks that ScrollPaneLayout properly calculates preferred + layout size. + @author Mikhail Lapshin + @run main bug6274267 +*/ + +import javax.swing.*; +import java.awt.*; + +public class bug6274267 { + private JFrame frame; + private Component left; + + public static void main(String[] args) throws Exception { + final bug6274267 test = new bug6274267(); + Robot robot = new Robot(); + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + test.setupUI1(); + } + }); + robot.waitForIdle(); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + test.setupUI2(); + } + }); + test.test(); + } finally { + if (test.frame != null) { + test.frame.dispose(); + } + } + } + + private void setupUI1() { + frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + left = new JPanel(); + left.setPreferredSize(new Dimension(100, 100)); + + JPanel rightPanel = new JPanel(); + rightPanel.setPreferredSize(new Dimension(100, 50)); + Component right = new JScrollPane(rightPanel); + + JSplitPane split = + new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right); + + frame = new JFrame(); + frame.add(split); + frame.pack(); + } + + // It is important to separate frame.pack() from frame.setVisible(true). + // Otherwise the repaint manager will combine validate() calls and + // the bug won't appear. + private void setupUI2() { + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + private void test() throws Exception { + if (left.getSize().width == 100) { + System.out.println("Test passed"); + } else { + throw new RuntimeException("ScrollPaneLayout sometimes improperly " + + "calculates the preferred layout size. "); + } + } +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JSpinner/8008657/bug8008657.java --- a/jdk/test/javax/swing/JSpinner/8008657/bug8008657.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JSpinner/8008657/bug8008657.java Mon Dec 01 12:08:17 2014 +0100 @@ -22,7 +22,7 @@ */ import java.awt.ComponentOrientation; -import java.awt.Toolkit; +import java.awt.Robot; import java.util.Calendar; import java.util.Date; import javax.swing.JFrame; @@ -32,7 +32,6 @@ import javax.swing.SpinnerModel; import javax.swing.SpinnerNumberModel; import javax.swing.SwingUtilities; -import sun.awt.SunToolkit; /** * @test @@ -43,19 +42,19 @@ */ public class bug8008657 { - private static SunToolkit toolkit; + private static Robot robot; private static JSpinner spinner; public static void main(String[] args) throws Exception { - toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + robot = new Robot(); SwingUtilities.invokeAndWait(() -> { createDateSpinner(); createAndShowUI(); }); - toolkit.realSync(); + robot.waitForIdle(); testSpinner(false); SwingUtilities.invokeAndWait(() -> { @@ -63,7 +62,7 @@ createAndShowUI(); }); - toolkit.realSync(); + robot.waitForIdle(); testSpinner(true); } @@ -73,7 +72,7 @@ SwingUtilities.invokeAndWait(() -> { spinner.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(() -> { @@ -91,7 +90,7 @@ spinner.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(() -> { JTextField textField = getTextField(); @@ -152,4 +151,4 @@ frame.getContentPane().add(spinner); frame.setVisible(true); } -} \ No newline at end of file +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JSplitPane/4816114/bug4816114.java --- a/jdk/test/javax/swing/JSplitPane/4816114/bug4816114.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JSplitPane/4816114/bug4816114.java Mon Dec 01 12:08:17 2014 +0100 @@ -30,7 +30,6 @@ import javax.swing.*; import java.awt.*; import java.lang.reflect.*; -import sun.awt.SunToolkit; public class bug4816114 { @@ -46,14 +45,14 @@ static bug4816114 test = new bug4816114(); - public static void main(String[] args) throws InterruptedException, InvocationTargetException { + public static void main(String[] args) throws InterruptedException, InvocationTargetException, AWTException { SwingUtilities.invokeAndWait(new Runnable() { public void run() { test.createAndShowGUI(); } }); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); Thread.sleep(1000); Thread.sleep(2000); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JTabbedPane/7024235/Test7024235.java --- a/jdk/test/javax/swing/JTabbedPane/7024235/Test7024235.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JTabbedPane/7024235/Test7024235.java Mon Dec 01 12:08:17 2014 +0100 @@ -22,7 +22,6 @@ */ import java.awt.BorderLayout; -import sun.awt.SunToolkit; import java.awt.Container; import java.awt.Rectangle; @@ -41,7 +40,10 @@ * @test * @bug 7024235 * @summary Tests JFrame.pack() with the JTabbedPane + * @library ../../../../lib/testlibrary/ + * @build ExtendedRobot * @author Sergey Malenkov + * @run main Test7024235 */ public class Test7024235 implements Runnable { @@ -50,13 +52,17 @@ public static void main(String[] args) throws Exception { Test7024235 test = new Test7024235(); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { UIManager.setLookAndFeel(info.getClassName()); test.test(); - toolkit.realSync(); - Thread.sleep(1000); + try { + ExtendedRobot robot = new ExtendedRobot(); + robot.waitForIdle(1000); + }catch(Exception ex) { + ex.printStackTrace(); + throw new Error("Unexpected Failure"); + } test.test(); } } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JTabbedPane/7170310/bug7170310.java --- a/jdk/test/javax/swing/JTabbedPane/7170310/bug7170310.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JTabbedPane/7170310/bug7170310.java Mon Dec 01 12:08:17 2014 +0100 @@ -34,13 +34,14 @@ import javax.swing.UIManager; import javax.swing.plaf.metal.MetalLookAndFeel; -import sun.awt.SunToolkit; /** * @test * @bug 7170310 * @author Alexey Ivanov * @summary Selected tab should be scrolled into view. + * @library ../../../../lib/testlibrary/ + * @build ExtendedRobot * @run main bug7170310 */ public class bug7170310 { @@ -58,12 +59,11 @@ UIManager.setLookAndFeel(new MetalLookAndFeel()); SwingUtilities.invokeAndWait(bug7170310::createAndShowUI); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.realSync(); + sync(); for (int i = 0; i < TABS_NUMBER; i++) { SwingUtilities.invokeAndWait(bug7170310::addTab); - toolkit.realSync(); + sync(); } SwingUtilities.invokeAndWait(bug7170310::check); @@ -121,4 +121,13 @@ exception = e; } } + private static void sync() { + try { + ExtendedRobot robot = new ExtendedRobot(); + robot.waitForIdle(300); + }catch(Exception ex) { + ex.printStackTrace(); + throw new Error("Unexpected Failure"); + } + } } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JTabbedPane/8017284/bug8017284.java --- a/jdk/test/javax/swing/JTabbedPane/8017284/bug8017284.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JTabbedPane/8017284/bug8017284.java Mon Dec 01 12:08:17 2014 +0100 @@ -22,12 +22,12 @@ */ import java.awt.BorderLayout; import java.awt.Toolkit; +import java.awt.Robot; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTabbedPane; import javax.swing.SwingUtilities; import javax.swing.plaf.metal.MetalLookAndFeel; -import sun.awt.SunToolkit; /** * @test @@ -45,6 +45,7 @@ public static void main(String[] args) throws Exception { + Robot robot = new Robot(); SwingUtilities.invokeAndWait(() -> { frame = new JFrame(); frame.setSize(500, 500); @@ -61,7 +62,7 @@ frame.setVisible(true); }); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(() -> { for (int j = 0; j < ITERATIONS; j++) { @@ -70,7 +71,7 @@ } } }); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(() -> frame.dispose()); } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JTable/8032874/bug8032874.java --- a/jdk/test/javax/swing/JTable/8032874/bug8032874.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JTable/8032874/bug8032874.java Mon Dec 01 12:08:17 2014 +0100 @@ -37,15 +37,13 @@ import javax.swing.table.AbstractTableModel; import javax.swing.table.TableRowSorter; -import sun.awt.SunToolkit; - public class bug8032874 { private static final int ROW_COUNT = 5; private static JTable table; private static TestTableModel tableModel; public static void main(String args[]) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -53,7 +51,7 @@ createAndShowUI(); } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -63,7 +61,7 @@ table.setRowSelectionInterval(1, 2); } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JTextArea/7049024/bug7049024.java --- a/jdk/test/javax/swing/JTextArea/7049024/bug7049024.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JTextArea/7049024/bug7049024.java Mon Dec 01 12:08:17 2014 +0100 @@ -31,8 +31,6 @@ * @author Sean Chou */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.text.DefaultCaret; import java.awt.*; @@ -53,7 +51,7 @@ public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { @@ -70,7 +68,7 @@ frame.setVisible(true); } }); - toolkit.realSync(); + robot.waitForIdle(); clipboard = textField.getToolkit().getSystemSelection(); if (null == clipboard) { @@ -83,7 +81,7 @@ textField.requestFocusInWindow(); } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -93,7 +91,7 @@ caret.moveDot(4); } }); - toolkit.realSync(); + robot.waitForIdle(); String oldSelection = (String) clipboard.getData(DataFlavor.stringFlavor); System.out.println("oldSelection is " + oldSelection); @@ -104,7 +102,7 @@ button.requestFocusInWindow(); } }); - toolkit.realSync(); // So JTextField loses the focus. + robot.waitForIdle(); // So JTextField loses the focus. SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -113,7 +111,7 @@ caret.moveDot(6); } }); - toolkit.realSync(); + robot.waitForIdle(); String newSelection = (String) clipboard.getData(DataFlavor.stringFlavor); System.out.println("newSelection is " + newSelection); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JToolBar/4529206/bug4529206.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JToolBar/4529206/bug4529206.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2004, 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 4529206 + @summary JToolBar - setFloating does not work correctly + @author Konstantin Eremin + @run main bug4529206 +*/ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class bug4529206 extends JFrame { + static JFrame frame; + static JToolBar jToolBar1; + public bug4529206() { + setDefaultCloseOperation(EXIT_ON_CLOSE); + JPanel jPanFrame = (JPanel) this.getContentPane(); + jPanFrame.setLayout(new BorderLayout()); + this.setSize(new Dimension(200, 100)); + this.setLocation(125, 75); + this.setTitle("Test Floating Toolbar"); + jToolBar1 = new JToolBar(); + JButton jButton1 = new JButton("Float"); + jPanFrame.add(jToolBar1, BorderLayout.NORTH); + JTextField tf = new JTextField("click here"); + jPanFrame.add(tf); + jToolBar1.add(jButton1, null); + jButton1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + buttonPressed(e); + } + }); + makeToolbarFloat(); + setVisible(true); + } + + private void makeToolbarFloat() { + javax.swing.plaf.basic.BasicToolBarUI ui = (javax.swing.plaf.basic.BasicToolBarUI) jToolBar1.getUI(); + if (!ui.isFloating()) { + ui.setFloatingLocation(100, 100); + ui.setFloating(true, jToolBar1.getLocation()); + } + } + + private void buttonPressed(ActionEvent e) { + makeToolbarFloat(); + } + + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame = new bug4529206(); + } + }); + Robot robot = new Robot(); + robot.waitForIdle(); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + if (frame.isFocused()) { + throw (new RuntimeException("setFloating does not work correctly")); + } + } + }); + } +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/JViewport/7107099/bug7107099.java --- a/jdk/test/javax/swing/JViewport/7107099/bug7107099.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/JViewport/7107099/bug7107099.java Mon Dec 01 12:08:17 2014 +0100 @@ -27,8 +27,6 @@ @author Pavel Porvatov */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; @@ -43,7 +41,8 @@ private static int extent; public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + + java.awt.Robot robot = new java.awt.Robot(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -61,7 +60,7 @@ } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -81,7 +80,7 @@ } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/Popup/6514582/bug6514582.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/Popup/6514582/bug6514582.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2011, 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 6514582 + @summary SubMenu of a JMenu with no items paints a single pixel tiny menu. + @author Alexander Potochkin + @run main bug6514582 +*/ + +import javax.swing.*; +import java.awt.*; + +public class bug6514582 { + private static JPopupMenu popup; + + public static void main(String ...args) throws Exception { + Robot robot = new Robot(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + popup = new JPopupMenu(); + popup.add(new JMenuItem("item")); + popup.setVisible(true); + + } + }); + + robot.waitForIdle(); + + if (!popup.isShowing()) { + throw new RuntimeException("Where is my popup ?"); + } + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + popup.setVisible(false); + popup.removeAll(); + popup.setVisible(true); + } + }); + + robot.waitForIdle(); + + if (popup.isShowing()) { + throw new RuntimeException("Empty popup is shown"); + } + + popup.setVisible(false); + } +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/RepaintManager/IconifyTest/IconifyTest.java --- a/jdk/test/javax/swing/RepaintManager/IconifyTest/IconifyTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/RepaintManager/IconifyTest/IconifyTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -31,7 +31,6 @@ import java.awt.*; import java.awt.event.*; import javax.swing.*; -import sun.awt.*; public class IconifyTest { private static volatile boolean windowIconifiedIsCalled = false; @@ -40,7 +39,7 @@ static JButton button; public static void main(String[] args) throws Throwable { - SunToolkit toolkit = (SunToolkit) SunToolkit.getDefaultToolkit(); + Robot robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame = new JFrame(); @@ -61,14 +60,14 @@ frame.setVisible(true); } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame.setExtendedState(Frame.ICONIFIED); } }); - toolkit.realSync(); + robot.waitForIdle(); if (!windowIconifiedIsCalled) { throw new Exception("Test failed: window was not iconified."); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/Security/6657138/ComponentTest.java --- a/jdk/test/javax/swing/Security/6657138/ComponentTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/Security/6657138/ComponentTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -28,8 +28,6 @@ * @author Alexander Potochkin */ -import sun.awt.SunToolkit; - import javax.swing.*; import java.awt.*; @@ -50,14 +48,14 @@ public static void main(String[] args) throws Exception { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame = new ComponentTest(); frame.setVisible(true); } }); - toolkit.realSync(); + robot.waitForIdle(); UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels(); for (final UIManager.LookAndFeelInfo laf : lafs) { SwingUtilities.invokeAndWait(new Runnable() { @@ -70,7 +68,7 @@ SwingUtilities.updateComponentTreeUI(frame); } }); - toolkit.realSync(); + robot.waitForIdle(); } } } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/SwingTest.java --- a/jdk/test/javax/swing/SwingTest.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/SwingTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -21,7 +21,6 @@ * questions. */ -import sun.awt.SunToolkit; import java.awt.Toolkit; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -134,11 +133,8 @@ else { SwingUtilities.invokeLater(this); // invoke on the event dispatch thread } - Toolkit tk = Toolkit.getDefaultToolkit(); - if (tk instanceof SunToolkit) { - SunToolkit stk = (SunToolkit) tk; - stk.realSync(); // wait until done - } + java.awt.Robot robot = new java.awt.Robot(); + robot.waitForIdle(); } while (this.frame != null); if (this.error != null) { diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/SwingUtilities/7088744/bug7088744.java --- a/jdk/test/javax/swing/SwingUtilities/7088744/bug7088744.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/SwingUtilities/7088744/bug7088744.java Mon Dec 01 12:08:17 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, 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,18 +27,24 @@ @author Pavel Porvatov */ -import sun.awt.SunToolkit; - -import javax.swing.*; -import java.awt.*; +import java.awt.Component; +import java.awt.Event; +import java.awt.Point; +import java.awt.Robot; import java.awt.event.InputEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.SwingUtilities; + public class bug7088744 { + private static volatile JLabel label; + private static volatile JFrame frame; - private static volatile Point point; + private static volatile Point point = new Point(); private static final int MOUSE_CLICKED = 1; private static final int MOUSE_PRESSED = 2; @@ -117,7 +123,7 @@ SwingUtilities.invokeAndWait(new Runnable() { public void run() { - JFrame frame = new JFrame(); + frame = new JFrame(); label = new JLabel("A label"); @@ -137,26 +143,24 @@ frame.add(label); frame.setSize(200, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLocationRelativeTo(null); frame.setVisible(true); } }); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - - toolkit.realSync(); - - // On Linux platforms realSync doesn't guaranties setSize completion - Thread.sleep(1000); + Robot robot = new Robot(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { - point = label.getLocationOnScreen(); + Point pt = label.getLocationOnScreen(); + point.x = pt.x + label.getWidth() / 2; + point.y = pt.y + label.getHeight() / 2; } }); - Robot robot = new Robot(); - robot.setAutoDelay(100); + robot.setAutoWaitForIdle(true); robot.mouseMove(point.x, point.y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mousePress(InputEvent.BUTTON2_MASK); @@ -165,10 +169,9 @@ robot.mouseRelease(InputEvent.BUTTON2_MASK); robot.mouseRelease(InputEvent.BUTTON3_MASK); - toolkit.realSync(); - SwingUtilities.invokeAndWait(new Runnable() { public void run() { + frame.dispose(); if (eventCount != BUTTON_EVENTS_SEQUENCE.length) { throw new RuntimeException("Not all events received"); } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/text/Utilities/bug7045593.java --- a/jdk/test/javax/swing/text/Utilities/bug7045593.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/text/Utilities/bug7045593.java Mon Dec 01 12:08:17 2014 +0100 @@ -28,8 +28,6 @@ * @author Pavel Porvatov */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.text.BadLocationException; import java.awt.*; @@ -49,7 +47,8 @@ } }); - ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/text/View/8048110/bug8048110.java --- a/jdk/test/javax/swing/text/View/8048110/bug8048110.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/text/View/8048110/bug8048110.java Mon Dec 01 12:08:17 2014 +0100 @@ -28,8 +28,6 @@ * @run main bug8048110 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.text.Element; import javax.swing.text.html.HTMLDocument; @@ -37,7 +35,7 @@ import java.awt.*; public class bug8048110 { - private static SunToolkit toolkit = (SunToolkit)Toolkit.getDefaultToolkit(); + private static Robot robot; private static Object lock = new Object(); private static boolean isRealSyncPerformed = false; private static final String htmlText = "" + @@ -45,6 +43,7 @@ "
    PCOk
    "; public static void main(String[] args) throws Exception { + robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { @@ -55,7 +54,7 @@ Thread thread = new Thread() { @Override public void run() { - toolkit.realSync(); + robot.waitForIdle(); synchronized (lock) { isRealSyncPerformed = true; lock.notifyAll(); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/text/html/7189299/bug7189299.java --- a/jdk/test/javax/swing/text/html/7189299/bug7189299.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/text/html/7189299/bug7189299.java Mon Dec 01 12:08:17 2014 +0100 @@ -25,7 +25,7 @@ * Portions Copyright (c) 2013 IBM Corporation */ import java.awt.BorderLayout; -import java.awt.Toolkit; +import java.awt.Robot; import java.awt.event.ActionListener; import javax.swing.DefaultButtonModel; @@ -35,7 +35,6 @@ import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; import javax.swing.text.html.HTMLEditorKit; -import sun.awt.SunToolkit; /* @@ -111,7 +110,7 @@ } public static void main(String[] args) throws Exception { - final SunToolkit toolkit = ((SunToolkit) Toolkit.getDefaultToolkit()); + final Robot robot = new Robot(); SwingUtilities.invokeAndWait(new Runnable() { @@ -120,7 +119,7 @@ setup(); } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/text/html/HTMLDocument/8058120/bug8058120.java --- a/jdk/test/javax/swing/text/html/HTMLDocument/8058120/bug8058120.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/text/html/HTMLDocument/8058120/bug8058120.java Mon Dec 01 12:08:17 2014 +0100 @@ -28,8 +28,6 @@ * @run main bug8058120 */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.text.Element; import javax.swing.text.html.HTML; @@ -38,12 +36,18 @@ import java.awt.*; public class bug8058120 { - private static SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); private static HTMLDocument document = null; private static final String text = "

    ab

    "; private static final String textToInsert = "c"; public static void main(String[] args) { + Robot robot; + try { + robot = new Robot(); + }catch(Exception ex) { + ex.printStackTrace(); + throw new RuntimeException("Unexpected failure"); + } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -51,7 +55,7 @@ } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeLater(new Runnable() { @Override @@ -64,7 +68,7 @@ } }); - toolkit.realSync(); + robot.waitForIdle(); SwingUtilities.invokeLater(new Runnable() { @Override diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/text/html/HTMLEditorKit/4242228/bug4242228.java --- a/jdk/test/javax/swing/text/html/HTMLEditorKit/4242228/bug4242228.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/text/html/HTMLEditorKit/4242228/bug4242228.java Mon Dec 01 12:08:17 2014 +0100 @@ -27,8 +27,6 @@ @author Peter Zhelezniakov */ -import sun.awt.SunToolkit; - import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -85,7 +83,8 @@ } }); - ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { @Override diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/swing/text/html/parser/Parser/7165725/bug7165725.java --- a/jdk/test/javax/swing/text/html/parser/Parser/7165725/bug7165725.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/swing/text/html/parser/Parser/7165725/bug7165725.java Mon Dec 01 12:08:17 2014 +0100 @@ -28,9 +28,8 @@ @run main bug7165725 */ -import sun.awt.SunToolkit; - import java.awt.BorderLayout; +import java.awt.Robot; import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -127,7 +126,8 @@ } }); - ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync(); + Robot robot = new Robot(); + robot.waitForIdle(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff -r a5647c044923 -r 5bec79a6bbca jdk/test/javax/xml/jaxp/Encodings/CheckEncodingPropertiesFile.java --- a/jdk/test/javax/xml/jaxp/Encodings/CheckEncodingPropertiesFile.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/javax/xml/jaxp/Encodings/CheckEncodingPropertiesFile.java Mon Dec 01 12:08:17 2014 +0100 @@ -23,7 +23,7 @@ /** * @test - * @bug 8008738 + * @bug 8008738 8065138 * @summary checks that the mapping implemented by * com.sun.org.apache.xml.internal.serializer.Encodings * correctly identifies valid Charset names and @@ -64,6 +64,15 @@ props.load(is); } + if (!props.containsKey("UTF8")) { + // If the test fails here - it may indicate that you stumbled on an + // issue similar to that fixed by JDK-8065138. + // Check that the content of the Encodings.properties included in + // the tested build image matches the content of the file in the source + // jaxp tree of the jdk forest. + throw new RuntimeException("UTF8 key missing in " + ClassLoader.getSystemResource(ENCODINGS_FILE)); + } + //printAllCharsets(); test(props); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java --- a/jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java Mon Dec 01 12:08:17 2014 +0100 @@ -38,6 +38,7 @@ import java.util.Collections; import java.util.regex.Pattern; import java.util.regex.Matcher; +import java.util.concurrent.TimeUnit; /** * Common library for various test helper functions. @@ -69,6 +70,12 @@ TIMEOUT_FACTOR = Double.parseDouble(toFactor); } + /** + * Returns the value of JTREG default test timeout in milliseconds + * converted to {@code long}. + */ + public static final long DEFAULT_TEST_TIMEOUT = TimeUnit.SECONDS.toMillis(120); + private Utils() { // Private constructor to prevent class instantiation } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/sun/net/www/http/HttpClient/StreamingRetry.java --- a/jdk/test/sun/net/www/http/HttpClient/StreamingRetry.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/sun/net/www/http/HttpClient/StreamingRetry.java Mon Dec 01 12:08:17 2014 +0100 @@ -37,13 +37,13 @@ public class StreamingRetry implements Runnable { static final int ACCEPT_TIMEOUT = 20 * 1000; // 20 seconds - ServerSocket ss; + volatile ServerSocket ss; - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws Exception { (new StreamingRetry()).instanceMain(); } - void instanceMain() throws IOException { + void instanceMain() throws Exception { out.println("Test with default method"); test(null); out.println("Test with POST method"); @@ -54,12 +54,13 @@ if (failed > 0) throw new RuntimeException("Some tests failed"); } - void test(String method) throws IOException { + void test(String method) throws Exception { ss = new ServerSocket(0); ss.setSoTimeout(ACCEPT_TIMEOUT); int port = ss.getLocalPort(); - (new Thread(this)).start(); + Thread otherThread = new Thread(this); + otherThread.start(); try { URL url = new URL("http://localhost:" + port + "/"); @@ -77,6 +78,7 @@ //expected.printStackTrace(); } finally { ss.close(); + otherThread.join(); } } diff -r a5647c044923 -r 5bec79a6bbca jdk/test/sun/net/www/protocol/http/B6369510.java --- a/jdk/test/sun/net/www/protocol/http/B6369510.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/sun/net/www/protocol/http/B6369510.java Mon Dec 01 12:08:17 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2014, 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 @@ -40,7 +40,7 @@ com.sun.net.httpserver.HttpServer httpServer; ExecutorService executorService; - public static void main(String[] args) + public static void main(String[] args) throws Exception { new B6369510(); } @@ -58,13 +58,15 @@ void doClient() { try { InetSocketAddress address = httpServer.getAddress(); + String urlString = "http://" + InetAddress.getLocalHost().getHostName() + ":" + address.getPort() + "/test/"; + System.out.println("URL == " + urlString); // GET Request - URL url = new URL("http://" + address.getHostName() + ":" + address.getPort() + "/test/"); + URL url = new URL("http://" + InetAddress.getLocalHost().getHostName() + ":" + address.getPort() + "/test/"); HttpURLConnection uc = (HttpURLConnection)url.openConnection(); int resp = uc.getResponseCode(); if (resp != 200) - throw new RuntimeException("Failed: Response code from GET is not 200"); + throw new RuntimeException("Failed: Response code from GET is not 200 RSP == " + resp); System.out.println("Response code from GET = 200 OK"); @@ -75,12 +77,13 @@ OutputStream os = uc.getOutputStream(); resp = uc.getResponseCode(); if (resp != 200) - throw new RuntimeException("Failed: Response code form POST is not 200"); + throw new RuntimeException("Failed: Response code form POST is not 200 RSP == " + resp); System.out.println("Response code from POST = 200 OK"); } catch (IOException e) { e.printStackTrace(); + throw new RuntimeException("Failed with IOException"); } finally { httpServer.stop(1); executorService.shutdown(); diff -r a5647c044923 -r 5bec79a6bbca jdk/test/sun/tools/jinfo/Basic.sh --- a/jdk/test/sun/tools/jinfo/Basic.sh Mon Nov 24 20:00:44 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2006, 2012, 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 6402766 -# @summary Unit test for jinfo utility -# -# @library ../common -# @build SimpleApplication ShutdownSimpleApplication -# @run shell Basic.sh - -. ${TESTSRC}/../common/CommonSetup.sh -. ${TESTSRC}/../common/ApplicationSetup.sh - -# Start application and use PORTFILE for coordination -PORTFILE="${TESTCLASSES}"/shutdown.port -startApplication SimpleApplication "${PORTFILE}" - -# all return statuses are checked in this test -set +e -set -x - -failed=0 - -runSA=true - -if [ $isMacos = true -o $isAIX = true -o `uname -m` = ppc64 ]; then - runSA=false -fi - -if [ $isLinux = true ]; then - # Some Linux systems disable non-child ptrace (see 7050524) - ptrace_scope=`/sbin/sysctl -n kernel.yama.ptrace_scope` - if [ $? = 0 ]; then - if [ $ptrace_scope = 1 ]; then - runSA=false - fi - fi -fi - -if [ $runSA = true ]; then - # -sysprops option - ${JINFO} -J-XX:+UsePerfData -F -sysprops $appJavaPid - if [ $? != 0 ]; then failed=1; fi - - # -flags option - ${JINFO} -J-XX:+UsePerfData -F -flags $appJavaPid - if [ $? != 0 ]; then failed=1; fi - - # no option - ${JINFO} -J-XX:+UsePerfData -F $appJavaPid - if [ $? != 0 ]; then failed=1; fi -fi - -# -sysprops option -${JINFO} -J-XX:+UsePerfData -sysprops $appJavaPid -if [ $? != 0 ]; then failed=1; fi - -# -flags option -${JINFO} -J-XX:+UsePerfData -flags $appJavaPid -if [ $? != 0 ]; then failed=1; fi - -# no option -${JINFO} -J-XX:+UsePerfData $appJavaPid -if [ $? != 0 ]; then failed=1; fi - -# -flag option -${JINFO} -J-XX:+UsePerfData -flag +PrintGC $appJavaPid -if [ $? != 0 ]; then failed=1; fi - -${JINFO} -J-XX:+UsePerfData -flag -PrintGC $appJavaPid -if [ $? != 0 ]; then failed=1; fi - -${JINFO} -J-XX:+UsePerfData -flag PrintGC $appJavaPid -if [ $? != 0 ]; then failed=1; fi - -if $isSolaris; then - - ${JINFO} -J-XX:+UsePerfData -flag +ExtendedDTraceProbes $appJavaPid - if [ $? != 0 ]; then failed=1; fi - - ${JINFO} -J-XX:+UsePerfData -flag -ExtendedDTraceProbes $appJavaPid - if [ $? != 0 ]; then failed=1; fi - - ${JINFO} -J-XX:+UsePerfData -flag ExtendedDTraceProbes $appJavaPid - if [ $? != 0 ]; then failed=1; fi - -fi - -set -e - -stopApplication "${PORTFILE}" -waitForApplication - -exit $failed diff -r a5647c044923 -r 5bec79a6bbca jdk/test/sun/tools/jinfo/JInfoHelper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/tools/jinfo/JInfoHelper.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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.util.Arrays; + +import jdk.testlibrary.JDKToolLauncher; +import jdk.testlibrary.OutputAnalyzer; +import jdk.testlibrary.ProcessTools; + +/** + * The helper class for running jinfo utility. + */ +public final class JInfoHelper { + + /** + * Print configuration information for the current process + * + * @param toolArgs List of jinfo options + */ + public static OutputAnalyzer jinfo(String... toolArgs) throws Exception { + return jinfo(true, toolArgs); + } + + /** + * Print usage information + * + * @param toolArgs List of jinfo options + */ + public static OutputAnalyzer jinfoNoPid(String... toolArgs) throws Exception { + return jinfo(false, toolArgs); + } + + private static OutputAnalyzer jinfo(boolean toPid, String... toolArgs) throws Exception { + JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo"); + if (toolArgs != null) { + for (String toolArg : toolArgs) { + launcher.addToolArg(toolArg); + } + } + if (toPid) { + launcher.addToolArg(Integer.toString(ProcessTools.getProcessId())); + } + + ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand()); + System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", "")); + OutputAnalyzer output = ProcessTools.executeProcess(processBuilder); + System.out.println(output.getOutput()); + + return output; + } + +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/sun/tools/jinfo/JInfoRunningProcessFlagTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/tools/jinfo/JInfoRunningProcessFlagTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 sun.management.ManagementFactoryHelper; + +import com.sun.management.HotSpotDiagnosticMXBean; + +import jdk.testlibrary.OutputAnalyzer; +import static jdk.testlibrary.Platform.isSolaris; +import static jdk.testlibrary.Asserts.assertEquals; +import static jdk.testlibrary.Asserts.assertNotEquals; +import static jdk.testlibrary.Asserts.assertTrue; + +/** + * @test + * @summary The test sanity checks 'jinfo -flag' option. + * @library /lib/testlibrary + * @build jdk.testlibrary.* JInfoHelper + * @run main/othervm -XX:+HeapDumpOnOutOfMemoryError JInfoRunningProcessFlagTest + */ +public class JInfoRunningProcessFlagTest { + + public static void main(String[] args) throws Exception { + testFlag(); + testFlagPlus(); + testFlagMinus(); + testFlagEqual(); + + testInvalidFlag(); + + testSolarisSpecificFlag(); + } + + private static void testFlag() throws Exception { + OutputAnalyzer output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError"); + output.shouldHaveExitValue(0); + assertTrue(output.getStderr().isEmpty(), "'jinfo -flag HeapDumpOnOutOfMemoryError' stderr should be empty"); + output.shouldContain("+HeapDumpOnOutOfMemoryError"); + } + + private static void testFlagPlus() throws Exception { + OutputAnalyzer output = JInfoHelper.jinfo("-flag", "+PrintGC"); + output.shouldHaveExitValue(0); + output = JInfoHelper.jinfo("-flag", "PrintGC"); + output.shouldHaveExitValue(0); + output.shouldContain("+PrintGC"); + verifyIsEnabled("PrintGC"); + } + + private static void testFlagMinus() throws Exception { + OutputAnalyzer output = JInfoHelper.jinfo("-flag", "-PrintGC"); + output.shouldHaveExitValue(0); + output = JInfoHelper.jinfo("-flag", "PrintGC"); + output.shouldHaveExitValue(0); + output.shouldContain("-PrintGC"); + verifyIsDisabled("PrintGC"); + } + + private static void testFlagEqual() throws Exception { + OutputAnalyzer output = JInfoHelper.jinfo("-flag", "PrintGC=1"); + output.shouldHaveExitValue(0); + output = JInfoHelper.jinfo("-flag", "PrintGC"); + output.shouldHaveExitValue(0); + output.shouldContain("+PrintGC"); + verifyIsEnabled("PrintGC"); + } + + private static void testInvalidFlag() throws Exception { + OutputAnalyzer output = JInfoHelper.jinfo("-flag", "monkey"); + assertNotEquals(output.getExitValue(), 0, "A non-zero exit code should be returned for invalid flag"); + } + + private static void testSolarisSpecificFlag() throws Exception { + if (!isSolaris()) + return; + + OutputAnalyzer output = JInfoHelper.jinfo("-flag", "+ExtendedDTraceProbes"); + output.shouldHaveExitValue(0); + output = JInfoHelper.jinfo(); + output.shouldContain("+ExtendedDTraceProbes"); + verifyIsEnabled("ExtendedDTraceProbes"); + + output = JInfoHelper.jinfo("-flag", "-ExtendedDTraceProbes"); + output.shouldHaveExitValue(0); + output = JInfoHelper.jinfo(); + output.shouldContain("-ExtendedDTraceProbes"); + verifyIsDisabled("ExtendedDTraceProbes"); + + output = JInfoHelper.jinfo("-flag", "ExtendedDTraceProbes"); + output.shouldContain("-ExtendedDTraceProbes"); + output.shouldHaveExitValue(0); + } + + private static void verifyIsEnabled(String flag) { + HotSpotDiagnosticMXBean hotspotDiagnostic = ManagementFactoryHelper.getDiagnosticMXBean(); + String flagValue = hotspotDiagnostic.getVMOption(flag).getValue(); + assertEquals(flagValue, "true", "Expected '" + flag + "' flag be enabled"); + } + + private static void verifyIsDisabled(String flag) { + HotSpotDiagnosticMXBean hotspotDiagnostic = ManagementFactoryHelper.getDiagnosticMXBean(); + String flagValue = hotspotDiagnostic.getVMOption(flag).getValue(); + assertEquals(flagValue, "false", "Expected '" + flag + "' flag be disabled"); + } + +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/sun/tools/jinfo/JInfoRunningProcessTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/tools/jinfo/JInfoRunningProcessTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 jdk.testlibrary.OutputAnalyzer; +import static jdk.testlibrary.Asserts.assertTrue; + +/** + * @test + * @summary The test sanity checks functionality of 'jinfo', 'jinfo -sysprops' and 'jinfo -flags' + * @library /lib/testlibrary + * @build jdk.testlibrary.* JInfoHelper + * @run main/othervm -XX:+HeapDumpOnOutOfMemoryError JInfoRunningProcessTest + */ +public class JInfoRunningProcessTest { + + public static void main(String[] args) throws Exception { + testNoOptions(); + testSysprops(); + testFlags(); + } + + private static void testNoOptions() throws Exception { + OutputAnalyzer output = JInfoHelper.jinfo(); + output.shouldHaveExitValue(0); + assertTrue(output.getStderr().isEmpty(), "'jinfo' stderr should be empty"); + output.shouldContain("+HeapDumpOnOutOfMemoryError"); + } + + private static void testSysprops() throws Exception { + OutputAnalyzer output = JInfoHelper.jinfo("-sysprops"); + output.shouldHaveExitValue(0); + assertTrue(output.getStderr().isEmpty(), "'jinfo -sysprops' stderr should be empty"); + } + + private static void testFlags() throws Exception { + OutputAnalyzer output = JInfoHelper.jinfo("-flags"); + output.shouldHaveExitValue(0); + assertTrue(output.getStderr().isEmpty(), "'jinfo -flags' stderr should be empty"); + output.shouldContain("+HeapDumpOnOutOfMemoryError"); + } + +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/sun/tools/jinfo/JInfoSanityTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/tools/jinfo/JInfoSanityTest.java Mon Dec 01 12:08:17 2014 +0100 @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2014, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 static jdk.testlibrary.Asserts.assertNotEquals; +import static jdk.testlibrary.Asserts.assertTrue; +import static jdk.testlibrary.Asserts.assertFalse; +import jdk.testlibrary.OutputAnalyzer; + +/** + * @test + * @summary The test sanity checks functionality of 'jinfo -h', 'jinfo -help', + * and verifies jinfo exits abnormally if started with invalid options. + * @library /lib/testlibrary + * @build jdk.testlibrary.* JInfoHelper + * @run main JInfoSanityTest + */ +public class JInfoSanityTest { + + public static void main(String[] args) throws Exception { + test_h(); + test_help(); + testVersion(); + testUnknownHost(); + } + + private static void test_h() throws Exception { + OutputAnalyzer output = JInfoHelper.jinfoNoPid("-h"); + output.shouldHaveExitValue(0); + assertFalse(output.getStderr().isEmpty(), "'jinfo -h' stderr should not be empty"); + assertTrue(output.getStdout().isEmpty(), "'jinfo -h' stdout should be empty"); + } + + private static void test_help() throws Exception { + OutputAnalyzer output = JInfoHelper.jinfoNoPid("-help"); + output.shouldHaveExitValue(0); + assertFalse(output.getStderr().isEmpty(), "'jinfo -help' stderr should not be empty"); + assertTrue(output.getStdout().isEmpty(), "'jinfo -help' stdout should be empty"); + } + + private static void testVersion() throws Exception { + OutputAnalyzer output = JInfoHelper.jinfoNoPid("-version"); + output.shouldHaveExitValue(1); + assertFalse(output.getStderr().isEmpty(), "'jinfo -version' stderr should not be empty"); + assertTrue(output.getStdout().isEmpty(), "'jinfo -version' stdout should be empty"); + } + + private static void testUnknownHost() throws Exception { + String unknownHost = "Oja781nh2ev7vcvbajdg-Sda1-C"; + OutputAnalyzer output = JInfoHelper.jinfoNoPid("med@" + unknownHost); + assertNotEquals(output.getExitValue(), 0, "A non-zero exit code should be returned for invalid operation"); + output.shouldContain("UnknownHostException: " + unknownHost); + } + +} diff -r a5647c044923 -r 5bec79a6bbca jdk/test/tools/launcher/TestHelper.java --- a/jdk/test/tools/launcher/TestHelper.java Mon Nov 24 20:00:44 2014 +0100 +++ b/jdk/test/tools/launcher/TestHelper.java Mon Dec 01 12:08:17 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2014, 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 @@ -50,6 +50,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Arrays; import javax.tools.JavaCompiler; import javax.tools.ToolProvider; @@ -333,15 +334,10 @@ } static void createJar(String... args) { - sun.tools.jar.Main jarTool = - new sun.tools.jar.Main(System.out, System.err, "JarCreator"); - if (!jarTool.run(args)) { - String message = "jar creation failed with command:"; - for (String x : args) { - message = message.concat(" " + x); - } - throw new RuntimeException(message); - } + List cmdList = new ArrayList<>(); + cmdList.add(jarCmd); + cmdList.addAll(Arrays.asList(args)); + doExec(cmdList.toArray(new String[cmdList.size()])); } static void copyStream(InputStream in, OutputStream out) throws IOException {