diff --git a/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java b/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java index dbc8d73c396d23d7f6cda5802013542cc6869839..29f4639adf1248a8552c86fad49f76158c26196e 100644 --- a/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java +++ b/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java @@ -41,7 +41,7 @@ import javax.print.attribute.standard.PageRanges; import sun.java2d.*; import sun.print.*; -final class CPrinterJob extends RasterPrinterJob { +public final class CPrinterJob extends RasterPrinterJob { // NOTE: This uses RasterPrinterJob as a base, but it doesn't use // all of the RasterPrinterJob functions. RasterPrinterJob will // break down printing to pieces that aren't necessary under MacOSX diff --git a/src/share/classes/java/util/Spliterators.java b/src/share/classes/java/util/Spliterators.java index 3f97a833a68ee3c9c7a285884472efceb06eb405..79c0ef3efde19332fa24591bb4931e5a021222f6 100644 --- a/src/share/classes/java/util/Spliterators.java +++ b/src/share/classes/java/util/Spliterators.java @@ -384,7 +384,7 @@ public final class Spliterators { */ private static void checkFromToBounds(int arrayLength, int origin, int fence) { if (origin > fence) { - throw new IllegalArgumentException( + throw new ArrayIndexOutOfBoundsException( "origin(" + origin + ") > fence(" + fence + ")"); } if (origin < 0) { diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/ByteVector.java b/src/share/classes/jdk/internal/org/objectweb/asm/ByteVector.java index 89eb6d4b64077241b5987ca972bccc7dbaa0f8cf..98de3231a8687ad24a84e89ff8d5e42d9869d413 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/ByteVector.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/ByteVector.java @@ -259,41 +259,68 @@ public class ByteVector { if (c >= '\001' && c <= '\177') { data[len++] = (byte) c; } else { - int byteLength = i; - for (int j = i; j < charLength; ++j) { - c = s.charAt(j); - if (c >= '\001' && c <= '\177') { - byteLength++; - } else if (c > '\u07FF') { - byteLength += 3; - } else { - byteLength += 2; - } - } - if (byteLength > 65535) { - throw new IllegalArgumentException(); - } - data[length] = (byte) (byteLength >>> 8); - data[length + 1] = (byte) byteLength; - if (length + 2 + byteLength > data.length) { - length = len; - enlarge(2 + byteLength); - data = this.data; - } - for (int j = i; j < charLength; ++j) { - c = s.charAt(j); - if (c >= '\001' && c <= '\177') { - data[len++] = (byte) c; - } else if (c > '\u07FF') { - data[len++] = (byte) (0xE0 | c >> 12 & 0xF); - data[len++] = (byte) (0x80 | c >> 6 & 0x3F); - data[len++] = (byte) (0x80 | c & 0x3F); - } else { - data[len++] = (byte) (0xC0 | c >> 6 & 0x1F); - data[len++] = (byte) (0x80 | c & 0x3F); - } - } - break; + length = len; + return encodeUTF8(s, i, 65535); + } + } + length = len; + return this; + } + + /** + * Puts an UTF8 string into this byte vector. The byte vector is + * automatically enlarged if necessary. The string length is encoded in two + * bytes before the encoded characters, if there is space for that (i.e. if + * this.length - i - 2 >= 0). + * + * @param s + * the String to encode. + * @param i + * the index of the first character to encode. The previous + * characters are supposed to have already been encoded, using + * only one byte per character. + * @param maxByteLength + * the maximum byte length of the encoded string, including the + * already encoded characters. + * @return this byte vector. + */ + ByteVector encodeUTF8(final String s, int i, int maxByteLength) { + int charLength = s.length(); + int byteLength = i; + char c; + for (int j = i; j < charLength; ++j) { + c = s.charAt(j); + if (c >= '\001' && c <= '\177') { + byteLength++; + } else if (c > '\u07FF') { + byteLength += 3; + } else { + byteLength += 2; + } + } + if (byteLength > maxByteLength) { + throw new IllegalArgumentException(); + } + int start = length - i - 2; + if (start >= 0) { + data[start] = (byte) (byteLength >>> 8); + data[start + 1] = (byte) byteLength; + } + if (length + byteLength - i > data.length) { + enlarge(byteLength - i); + } + int len = length; + for (int j = i; j < charLength; ++j) { + c = s.charAt(j); + if (c >= '\001' && c <= '\177') { + data[len++] = (byte) c; + } else if (c > '\u07FF') { + data[len++] = (byte) (0xE0 | c >> 12 & 0xF); + data[len++] = (byte) (0x80 | c >> 6 & 0x3F); + data[len++] = (byte) (0x80 | c & 0x3F); + } else { + data[len++] = (byte) (0xC0 | c >> 6 & 0x1F); + data[len++] = (byte) (0x80 | c & 0x3F); } } length = len; diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/ClassWriter.java b/src/share/classes/jdk/internal/org/objectweb/asm/ClassWriter.java index ab9dcd0dce46b7bccfeee6a28906a135bb6f12c1..66e8e7e3f119026be3e2435323d557a928d579d3 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/ClassWriter.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/ClassWriter.java @@ -716,7 +716,8 @@ public class ClassWriter extends ClassVisitor { sourceFile = newUTF8(file); } if (debug != null) { - sourceDebug = new ByteVector().putUTF8(debug); + sourceDebug = new ByteVector().encodeUTF8(debug, 0, + Integer.MAX_VALUE); } } @@ -857,7 +858,7 @@ public class ClassWriter extends ClassVisitor { } if (sourceDebug != null) { ++attributeCount; - size += sourceDebug.length + 4; + size += sourceDebug.length + 6; newUTF8("SourceDebugExtension"); } if (enclosingMethodOwner != 0) { @@ -946,9 +947,9 @@ public class ClassWriter extends ClassVisitor { out.putShort(newUTF8("SourceFile")).putInt(2).putShort(sourceFile); } if (sourceDebug != null) { - int len = sourceDebug.length - 2; + int len = sourceDebug.length; out.putShort(newUTF8("SourceDebugExtension")).putInt(len); - out.putByteArray(sourceDebug.data, 2, len); + out.putByteArray(sourceDebug.data, 0, len); } if (enclosingMethodOwner != 0) { out.putShort(newUTF8("EnclosingMethod")).putInt(4); diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/Frame.java b/src/share/classes/jdk/internal/org/objectweb/asm/Frame.java index 78953ce4f877ea4e3de646956ab923f90a5babd6..e32a13af942f9c5e15087afce03109c12eb95397 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/Frame.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/Frame.java @@ -99,8 +99,8 @@ final class Frame { * stack types. VALUE depends on KIND. For LOCAL types, it is an index in * the input local variable types. For STACK types, it is a position * relatively to the top of input frame stack. For BASE types, it is either - * one of the constants defined in FrameVisitor, or for OBJECT and - * UNINITIALIZED types, a tag and an index in the type table. + * one of the constants defined below, or for OBJECT and UNINITIALIZED + * types, a tag and an index in the type table. * * Output frames can contain types of any kind and with a positive or * negative dimension (and even unassigned types, represented by 0 - which @@ -537,7 +537,7 @@ final class Frame { /** * The types that are initialized in the basic block. A constructor * invocation on an UNINITIALIZED or UNINITIALIZED_THIS type must replace - * every occurrence of this type in the local variables and in the + * every occurence of this type in the local variables and in the * operand stack. This cannot be done during the first phase of the * algorithm since, during this phase, the local variables and the operand * stack are not completely computed. It is therefore necessary to store the @@ -1446,6 +1446,7 @@ final class Frame { // if t is the NULL type, merge(u,t)=u, so there is no change return false; } else if ((t & (DIM | BASE_KIND)) == (u & (DIM | BASE_KIND))) { + // if t and u have the same dimension and same base kind if ((u & BASE_KIND) == OBJECT) { // if t is also a reference type, and if u and t have the // same dimension merge(u,t) = dim(t) | common parent of the @@ -1458,9 +1459,13 @@ final class Frame { v = OBJECT | cw.addType("java/lang/Object"); } } else if ((t & BASE_KIND) == OBJECT || (t & DIM) != 0) { - // if t is any other reference or array type, - // merge(u,t)=java/lang/Object - v = OBJECT | cw.addType("java/lang/Object"); + // if t is any other reference or array type, the merged type + // is Object, or min(dim(u), dim(t)) | java/lang/Object is u + // and t have different array dimensions + int tdim = t & DIM; + int udim = u & DIM; + v = (udim != tdim ? Math.min(tdim, udim) : 0) | OBJECT + | cw.addType("java/lang/Object"); } else { // if t is any other type, merge(u,t)=TOP v = TOP; diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/commons/AnalyzerAdapter.java b/src/share/classes/jdk/internal/org/objectweb/asm/commons/AnalyzerAdapter.java index e914d45134ef86525d7bafd6589abf0583670850..b761babb1386b7e4002ee5e21f8dc6e0bbe09184 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/commons/AnalyzerAdapter.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/commons/AnalyzerAdapter.java @@ -240,6 +240,7 @@ public class AnalyzerAdapter extends MethodVisitor { locals.add(types[i].getInternalName()); } } + maxLocals = locals.size(); } @Override @@ -519,12 +520,12 @@ public class AnalyzerAdapter extends MethodVisitor { // ------------------------------------------------------------------------ private Object get(final int local) { - maxLocals = Math.max(maxLocals, local); + maxLocals = Math.max(maxLocals, local + 1); return local < locals.size() ? locals.get(local) : Opcodes.TOP; } private void set(final int local, final Object type) { - maxLocals = Math.max(maxLocals, local); + maxLocals = Math.max(maxLocals, local + 1); while (local >= locals.size()) { locals.add(Opcodes.TOP); } diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/tree/InsnList.java b/src/share/classes/jdk/internal/org/objectweb/asm/tree/InsnList.java index 2ba917cb6a314ac5fbe7ac92409bfdd0816fb37c..7acfff532f5185523554bc3d3fe6c49a3256d3b4 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/tree/InsnList.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/tree/InsnList.java @@ -556,6 +556,8 @@ public class InsnList { AbstractInsnNode prev; + AbstractInsnNode remove; + InsnListIterator(int index) { if (index == size()) { next = null; @@ -577,12 +579,22 @@ public class InsnList { AbstractInsnNode result = next; prev = result; next = result.next; + remove = result; return result; } public void remove() { - InsnList.this.remove(prev); - prev = prev.prev; + if (remove != null) { + if (remove == next) { + next = next.next; + } else { + prev = prev.prev; + } + InsnList.this.remove(remove); + remove = null; + } else { + throw new IllegalStateException(); + } } public boolean hasPrevious() { @@ -593,6 +605,7 @@ public class InsnList { AbstractInsnNode result = prev; next = result; prev = result.prev; + remove = result; return result; } @@ -619,6 +632,7 @@ public class InsnList { public void add(Object o) { InsnList.this.insertBefore(next, (AbstractInsnNode) o); prev = (AbstractInsnNode) o; + remove = null; } public void set(Object o) { diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Analyzer.java b/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Analyzer.java index cd64b52156d9075b05e6caa1e246365c2b1b6526..8f987532efdfb00d92a2472b458041e82c992473 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Analyzer.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Analyzer.java @@ -404,7 +404,7 @@ public class Analyzer implements Opcodes { * instruction of the method. The size of the returned array is * equal to the number of instructions (and labels) of the method. A * given frame is null if the corresponding instruction - * cannot be reached, or if an error occurred during the analysis of + * cannot be reached, or if an error occured during the analysis of * the method. */ public Frame[] getFrames() { diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Interpreter.java b/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Interpreter.java index 122ee939c59007f4ec54693795919a8dd7aa18d7..649d5a4c5d8a2fdef89c966ecc78d215e1b5038f 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Interpreter.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/tree/analysis/Interpreter.java @@ -111,7 +111,7 @@ public abstract class Interpreter { * the bytecode instruction to be interpreted. * @return the result of the interpretation of the given instruction. * @throws AnalyzerException - * if an error occurred during the interpretation. + * if an error occured during the interpretation. */ public abstract V newOperation(AbstractInsnNode insn) throws AnalyzerException; @@ -130,7 +130,7 @@ public abstract class Interpreter { * @return the result of the interpretation of the given instruction. The * returned value must be equal to the given value. * @throws AnalyzerException - * if an error occurred during the interpretation. + * if an error occured during the interpretation. */ public abstract V copyOperation(AbstractInsnNode insn, V value) throws AnalyzerException; @@ -151,7 +151,7 @@ public abstract class Interpreter { * the argument of the instruction to be interpreted. * @return the result of the interpretation of the given instruction. * @throws AnalyzerException - * if an error occurred during the interpretation. + * if an error occured during the interpretation. */ public abstract V unaryOperation(AbstractInsnNode insn, V value) throws AnalyzerException; @@ -175,7 +175,7 @@ public abstract class Interpreter { * the second argument of the instruction to be interpreted. * @return the result of the interpretation of the given instruction. * @throws AnalyzerException - * if an error occurred during the interpretation. + * if an error occured during the interpretation. */ public abstract V binaryOperation(AbstractInsnNode insn, V value1, V value2) throws AnalyzerException; @@ -196,7 +196,7 @@ public abstract class Interpreter { * the third argument of the instruction to be interpreted. * @return the result of the interpretation of the given instruction. * @throws AnalyzerException - * if an error occurred during the interpretation. + * if an error occured during the interpretation. */ public abstract V ternaryOperation(AbstractInsnNode insn, V value1, V value2, V value3) throws AnalyzerException; @@ -214,7 +214,7 @@ public abstract class Interpreter { * the arguments of the instruction to be interpreted. * @return the result of the interpretation of the given instruction. * @throws AnalyzerException - * if an error occurred during the interpretation. + * if an error occured during the interpretation. */ public abstract V naryOperation(AbstractInsnNode insn, List values) throws AnalyzerException; @@ -232,7 +232,7 @@ public abstract class Interpreter { * @param expected * the expected return type of the analyzed method. * @throws AnalyzerException - * if an error occurred during the interpretation. + * if an error occured during the interpretation. */ public abstract void returnOperation(AbstractInsnNode insn, V value, V expected) throws AnalyzerException; diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/util/CheckAnnotationAdapter.java b/src/share/classes/jdk/internal/org/objectweb/asm/util/CheckAnnotationAdapter.java index 3650e37db39513bc4cfbae265c3ac2ebe8c7f12e..4b68882676448a6e36dc31aff515eca5fab0bb0f 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/util/CheckAnnotationAdapter.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/util/CheckAnnotationAdapter.java @@ -99,7 +99,7 @@ public class CheckAnnotationAdapter extends AnnotationVisitor { } if (value instanceof Type) { int sort = ((Type) value).getSort(); - if (sort != Type.OBJECT && sort != Type.ARRAY) { + if (sort == Type.METHOD) { throw new IllegalArgumentException("Invalid annotation value"); } } diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/util/Textifier.java b/src/share/classes/jdk/internal/org/objectweb/asm/util/Textifier.java index 5e20f52c553dfad0aea09789fe3eda88fd0e17fa..5c2c8bf4776a8f7db1598498ecda0b1d736ecbb0 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/util/Textifier.java +++ b/src/share/classes/jdk/internal/org/objectweb/asm/util/Textifier.java @@ -166,6 +166,11 @@ public class Textifier extends Printer { */ protected Map labelNames; + /** + * Class access flags + */ + private int access; + private int valueNumber = 0; /** @@ -245,6 +250,7 @@ public class Textifier extends Printer { public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) { + this.access = access; int major = version & 0xFFFF; int minor = version >>> 16; buf.setLength(0); @@ -447,6 +453,11 @@ public class Textifier extends Printer { if ((access & Opcodes.ACC_BRIDGE) != 0) { buf.append("bridge "); } + if ((this.access & Opcodes.ACC_INTERFACE) != 0 + && (access & Opcodes.ACC_ABSTRACT) == 0 + && (access & Opcodes.ACC_STATIC) == 0) { + buf.append("default "); + } buf.append(name); appendDescriptor(METHOD_DESCRIPTOR, desc); @@ -856,7 +867,6 @@ public class Textifier extends Printer { appendDescriptor(INTERNAL_NAME, owner); buf.append('.').append(name).append(' '); appendDescriptor(METHOD_DESCRIPTOR, desc); - buf.append(' ').append(itf ? "itf" : ""); buf.append('\n'); text.add(buf.toString()); } @@ -869,26 +879,35 @@ public class Textifier extends Printer { buf.append(name); appendDescriptor(METHOD_DESCRIPTOR, desc); buf.append(" ["); + buf.append('\n'); + buf.append(tab3); appendHandle(bsm); + buf.append('\n'); buf.append(tab3).append("// arguments:"); if (bsmArgs.length == 0) { buf.append(" none"); } else { - buf.append('\n').append(tab3); + buf.append('\n'); for (int i = 0; i < bsmArgs.length; i++) { + buf.append(tab3); Object cst = bsmArgs[i]; if (cst instanceof String) { Printer.appendString(buf, (String) cst); } else if (cst instanceof Type) { - buf.append(((Type) cst).getDescriptor()).append(".class"); + Type type = (Type) cst; + if(type.getSort() == Type.METHOD){ + appendDescriptor(METHOD_DESCRIPTOR, type.getDescriptor()); + } else { + buf.append(type.getDescriptor()).append(".class"); + } } else if (cst instanceof Handle) { appendHandle((Handle) cst); } else { buf.append(cst); } - buf.append(", "); + buf.append(", \n"); } - buf.setLength(buf.length() - 2); + buf.setLength(buf.length() - 3); } buf.append('\n'); buf.append(tab2).append("]\n"); @@ -1234,10 +1253,10 @@ public class Textifier extends Printer { * a handle, non null. */ protected void appendHandle(final Handle h) { - buf.append('\n').append(tab3); int tag = h.getTag(); buf.append("// handle kind 0x").append(Integer.toHexString(tag)) .append(" : "); + boolean isMethodHandle = false; switch (tag) { case Opcodes.H_GETFIELD: buf.append("GETFIELD"); @@ -1253,18 +1272,23 @@ public class Textifier extends Printer { break; case Opcodes.H_INVOKEINTERFACE: buf.append("INVOKEINTERFACE"); + isMethodHandle = true; break; case Opcodes.H_INVOKESPECIAL: buf.append("INVOKESPECIAL"); + isMethodHandle = true; break; case Opcodes.H_INVOKESTATIC: buf.append("INVOKESTATIC"); + isMethodHandle = true; break; case Opcodes.H_INVOKEVIRTUAL: buf.append("INVOKEVIRTUAL"); + isMethodHandle = true; break; case Opcodes.H_NEWINVOKESPECIAL: buf.append("NEWINVOKESPECIAL"); + isMethodHandle = true; break; } buf.append('\n'); @@ -1272,9 +1296,13 @@ public class Textifier extends Printer { appendDescriptor(INTERNAL_NAME, h.getOwner()); buf.append('.'); buf.append(h.getName()); - buf.append('('); + if(!isMethodHandle){ + buf.append('('); + } appendDescriptor(HANDLE_DESCRIPTOR, h.getDesc()); - buf.append(')').append('\n'); + if(!isMethodHandle){ + buf.append(')'); + } } /** diff --git a/src/share/classes/jdk/internal/org/objectweb/asm/version.txt b/src/share/classes/jdk/internal/org/objectweb/asm/version.txt index efe71fa4d26b457fce7150e41a9a0c35f13513d6..c6f8ad648afb243b9900d47699741a5704676886 100644 --- a/src/share/classes/jdk/internal/org/objectweb/asm/version.txt +++ b/src/share/classes/jdk/internal/org/objectweb/asm/version.txt @@ -1,12 +1,12 @@ Path: . -Working Copy Root Path: /hudson/jobs/objectweb-pull/workspace/ASM_5_0_BETA -URL: svn://svn.forge.objectweb.org/svnroot/asm/trunk/asm -Repository Root: svn://svn.forge.objectweb.org/svnroot/asm +Working Copy Root Path: /hudson/jobs/objectweb-pull/workspace/asm-svn-2014-03-12 +URL: file:///svnroot/asm/trunk/asm +Repository Root: file:///svnroot/asm Repository UUID: 271bd773-ee82-43a6-9b2b-1890ed8ce7f9 -Revision: 1700 +Revision: 1721 Node Kind: directory Schedule: normal Last Changed Author: ebruneton -Last Changed Rev: 1700 -Last Changed Date: 2013-10-29 20:22:52 +0100 (Tue, 29 Oct 2013) +Last Changed Rev: 1721 +Last Changed Date: 2014-03-02 17:25:35 +0100 (Sun, 02 Mar 2014) diff --git a/src/share/classes/sun/java2d/SunGraphics2D.java b/src/share/classes/sun/java2d/SunGraphics2D.java index f66eee685b076679cd87037b713bba2de3a974de..287549c20627871ce5a1e16210bd5fb09af9f236 100644 --- a/src/share/classes/sun/java2d/SunGraphics2D.java +++ b/src/share/classes/sun/java2d/SunGraphics2D.java @@ -2430,6 +2430,8 @@ public final class SunGraphics2D surfaceData = NullSurfaceData.theInstance; } + invalidatePipe(); + // this will recalculate the composite clip setDevClip(surfaceData.getBounds()); diff --git a/src/share/classes/sun/security/krb5/Config.java b/src/share/classes/sun/security/krb5/Config.java index a86cdfd15e406c0d9d87b78c722bd03ca615a848..3b108622b0736fb4a0658f43a5d788d9887811f1 100644 --- a/src/share/classes/sun/security/krb5/Config.java +++ b/src/share/classes/sun/security/krb5/Config.java @@ -549,12 +549,11 @@ public class Config { previous = line.substring(1).trim(); } } else { - if (previous == null) { - throw new KrbException( - "Config file must starts with a section"); + // Lines before the first section are ignored + if (previous != null) { + v.add(previous); + previous = line; } - v.add(previous); - previous = line; } } if (previous != null) { diff --git a/src/share/classes/sun/security/provider/certpath/PKIXCertPathValidator.java b/src/share/classes/sun/security/provider/certpath/PKIXCertPathValidator.java index c4eaff3fe36a1e0f59ef43ec523838e6fe27ea53..571801fc8d177b2d594543e39d456ae378b22eab 100644 --- a/src/share/classes/sun/security/provider/certpath/PKIXCertPathValidator.java +++ b/src/share/classes/sun/security/provider/certpath/PKIXCertPathValidator.java @@ -94,9 +94,6 @@ public final class PKIXCertPathValidator extends CertPathValidatorSpi { X509Certificate firstCert = certList.get(0); // check trusted certificate's subject selector.setSubject(firstCert.getIssuerX500Principal()); - // check the validity period - selector.setValidityPeriod(firstCert.getNotBefore(), - firstCert.getNotAfter()); /* * Facilitate certification path construction with authority * key identifier and subject key identifier. diff --git a/src/windows/native/sun/windows/awt_DesktopProperties.cpp b/src/windows/native/sun/windows/awt_DesktopProperties.cpp index 7d68f25983e508a02037ba49e1a793e612cbff8d..21a4b0074ce2c41c1a55b97327f5ec10d9ef8d7b 100644 --- a/src/windows/native/sun/windows/awt_DesktopProperties.cpp +++ b/src/windows/native/sun/windows/awt_DesktopProperties.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -83,13 +83,19 @@ void AwtDesktopProperties::GetSystemProperties() { HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); if (dc != NULL) { - SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font")); - SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font")); - SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font")); - SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font")); - SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font")); - SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font")); - SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font")); + try { + SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font")); + SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font")); + SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font")); + SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font")); + SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font")); + SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font")); + SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font")); + } + catch (std::bad_alloc&) { + DeleteDC(dc); + throw; + } DeleteDC(dc); } } @@ -206,24 +212,35 @@ void AwtDesktopProperties::GetXPStyleProperties() { LPTSTR value; value = getXPStylePropFromReg(TEXT("ThemeActive")); - SetBooleanProperty(TEXT("win.xpstyle.themeActive"), (value != NULL && *value == _T('1'))); - if (value != NULL) { - free(value); - } - value = getXPStylePropFromReg(TEXT("DllName")); - if (value != NULL) { - SetStringProperty(TEXT("win.xpstyle.dllName"), value); - free(value); - } - value = getXPStylePropFromReg(TEXT("SizeName")); - if (value != NULL) { - SetStringProperty(TEXT("win.xpstyle.sizeName"), value); - free(value); + try { + SetBooleanProperty(TEXT("win.xpstyle.themeActive"), (value != NULL && *value == _T('1'))); + if (value != NULL) { + free(value); + value = NULL; + } + value = getXPStylePropFromReg(TEXT("DllName")); + if (value != NULL) { + SetStringProperty(TEXT("win.xpstyle.dllName"), value); + free(value); + value = NULL; + } + value = getXPStylePropFromReg(TEXT("SizeName")); + if (value != NULL) { + SetStringProperty(TEXT("win.xpstyle.sizeName"), value); + free(value); + value = NULL; + } + value = getXPStylePropFromReg(TEXT("ColorName")); + if (value != NULL) { + SetStringProperty(TEXT("win.xpstyle.colorName"), value); + free(value); + } } - value = getXPStylePropFromReg(TEXT("ColorName")); - if (value != NULL) { - SetStringProperty(TEXT("win.xpstyle.colorName"), value); - free(value); + catch (std::bad_alloc&) { + if (value != NULL) { + free(value); + } + throw; } } @@ -564,27 +581,37 @@ void AwtDesktopProperties::GetOtherParameters() { // Shell Icon BPP - only honored on platforms before XP value = getWindowsPropFromReg(TEXT("Control Panel\\Desktop\\WindowMetrics"), TEXT("Shell Icon BPP"), &valueType); - if (value != NULL) { - if (valueType == REG_SZ) { - SetStringProperty(TEXT("win.icon.shellIconBPP"), value); + + try { + if (value != NULL) { + if (valueType == REG_SZ) { + SetStringProperty(TEXT("win.icon.shellIconBPP"), value); + } + free(value); + value = NULL; } - free(value); - } - // The following registry settings control the file chooser places bar - // under the Windows L&F. These settings are not present by default, but - // can be enabled using the TweakUI tool from Microsoft. For more info, - // see http://msdn.microsoft.com/msdnmag/issues/1100/Registry/ + // The following registry settings control the file chooser places bar + // under the Windows L&F. These settings are not present by default, but + // can be enabled using the TweakUI tool from Microsoft. For more info, + // see http://msdn.microsoft.com/msdnmag/issues/1100/Registry/ - // NoPlacesBar is a REG_DWORD, with values 0 or 1 - value = getWindowsPropFromReg(TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32"), - TEXT("NoPlacesBar"), &valueType); - if (value != NULL) { - if (valueType == REG_DWORD) { - SetBooleanProperty(TEXT("win.comdlg.noPlacesBar"), (BOOL)((int)*value != 0)); + // NoPlacesBar is a REG_DWORD, with values 0 or 1 + value = getWindowsPropFromReg(TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32"), + TEXT("NoPlacesBar"), &valueType); + if (value != NULL) { + if (valueType == REG_DWORD) { + SetBooleanProperty(TEXT("win.comdlg.noPlacesBar"), (BOOL)((int)*value != 0)); + } + free(value); } - free(value); + } + catch (std::bad_alloc&) { + if (value != NULL) { + free(value); + } + throw; } LPTSTR valueName = TEXT("PlaceN"); @@ -592,7 +619,15 @@ void AwtDesktopProperties::GetOtherParameters() { lstrcpy(valueNameBuf, valueName); LPTSTR propKey = TEXT("win.comdlg.placesBarPlaceN"); - LPTSTR propKeyBuf = (LPTSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (lstrlen(propKey) + 1), sizeof(TCHAR)); + + LPTSTR propKeyBuf; + try { + propKeyBuf = (LPTSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (lstrlen(propKey) + 1), sizeof(TCHAR)); + } + catch (std::bad_alloc&) { + free(valueNameBuf); + throw; + } lstrcpy(propKeyBuf, propKey); int i = 0; @@ -601,20 +636,31 @@ void AwtDesktopProperties::GetOtherParameters() { propKeyBuf[25] = valueNameBuf[5]; LPTSTR key = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32\\PlacesBar"); - if ((value = getWindowsPropFromReg(key, valueNameBuf, &valueType)) != NULL) { - if (valueType == REG_DWORD) { - // Value is a CSIDL - SetIntegerProperty(propKeyBuf, (int)*value); - } else { - // Value is a path - SetStringProperty(propKeyBuf, value); + try { + value = NULL; + if ((value = getWindowsPropFromReg(key, valueNameBuf, &valueType)) != NULL) { + if (valueType == REG_DWORD) { + // Value is a CSIDL + SetIntegerProperty(propKeyBuf, (int)*value); + } else { + // Value is a path + SetStringProperty(propKeyBuf, value); + } + free(value); } - free(value); + } + catch (std::bad_alloc&) { + if (value != NULL) { + free(value); + } + free(propKeyBuf); + free(valueNameBuf); + throw; } } while (value != NULL); - free(valueNameBuf); free(propKeyBuf); + free(valueNameBuf); } void AwtDesktopProperties::GetSoundEvents() { @@ -656,14 +702,26 @@ UINT AwtDesktopProperties::GetIntegerParameter(UINT spi) { void AwtDesktopProperties::SetStringProperty(LPCTSTR propName, LPTSTR value) { jstring key = JNU_NewStringPlatform(GetEnv(), propName); + if (key == NULL) { + throw std::bad_alloc(); + } + jstring jValue = JNU_NewStringPlatform(GetEnv(), value); + if (jValue == NULL) { + GetEnv()->DeleteLocalRef(key); + throw std::bad_alloc(); + } GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setStringPropertyID, - key, JNU_NewStringPlatform(GetEnv(), value)); + key, jValue); + GetEnv()->DeleteLocalRef(jValue); GetEnv()->DeleteLocalRef(key); } void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) { jstring key = JNU_NewStringPlatform(GetEnv(), propName); + if (key == NULL) { + throw std::bad_alloc(); + } GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setIntegerPropertyID, key, (jint)value); @@ -672,6 +730,9 @@ void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) { void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) { jstring key = JNU_NewStringPlatform(GetEnv(), propName); + if (key == NULL) { + throw std::bad_alloc(); + } GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setBooleanPropertyID, key, value ? JNI_TRUE : JNI_FALSE); @@ -680,6 +741,9 @@ void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) { void AwtDesktopProperties::SetColorProperty(LPCTSTR propName, DWORD value) { jstring key = JNU_NewStringPlatform(GetEnv(), propName); + if (key == NULL) { + throw std::bad_alloc(); + } GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setColorPropertyID, key, GetRValue(value), GetGValue(value), @@ -720,6 +784,11 @@ void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID, else { fontName = JNU_NewStringPlatform(GetEnv(), face); } + if (fontName == NULL) { + delete[] face; + throw std::bad_alloc(); + } + jint pointSize = metrics.tmHeight - metrics.tmInternalLeading; jint style = java_awt_Font_PLAIN; @@ -732,11 +801,16 @@ void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID, } jstring key = JNU_NewStringPlatform(GetEnv(), propName); + if (key == NULL) { + GetEnv()->DeleteLocalRef(fontName); + delete[] face; + throw std::bad_alloc(); + } GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setFontPropertyID, key, fontName, style, pointSize); - GetEnv()->DeleteLocalRef(fontName); GetEnv()->DeleteLocalRef(key); + GetEnv()->DeleteLocalRef(fontName); } } delete[] face; @@ -750,7 +824,9 @@ void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & fon jint style; fontName = JNU_NewStringPlatform(GetEnv(), font.lfFaceName); - + if (fontName == NULL) { + throw std::bad_alloc(); + } #if 0 HDC hdc; int pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY); @@ -773,22 +849,31 @@ void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & fon } jstring key = JNU_NewStringPlatform(GetEnv(), propName); + if (key == NULL) { + GetEnv()->DeleteLocalRef(fontName); + throw std::bad_alloc(); + } GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setFontPropertyID, key, fontName, style, pointSize); - - GetEnv()->DeleteLocalRef(fontName); GetEnv()->DeleteLocalRef(key); + GetEnv()->DeleteLocalRef(fontName); } void AwtDesktopProperties::SetSoundProperty(LPCTSTR propName, LPCTSTR winEventName) { jstring key = JNU_NewStringPlatform(GetEnv(), propName); + if (key == NULL) { + throw std::bad_alloc(); + } jstring event = JNU_NewStringPlatform(GetEnv(), winEventName); + if (event == NULL) { + GetEnv()->DeleteLocalRef(key); + throw std::bad_alloc(); + } GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setSoundPropertyID, key, event); - - GetEnv()->DeleteLocalRef(key); GetEnv()->DeleteLocalRef(event); + GetEnv()->DeleteLocalRef(key); } void AwtDesktopProperties::PlayWindowsSound(LPCTSTR event) { @@ -814,24 +899,37 @@ Java_sun_awt_windows_WDesktopProperties_initIDs(JNIEnv *env, jclass cls) { AwtDesktopProperties::pDataID = env->GetFieldID(cls, "pData", "J"); DASSERT(AwtDesktopProperties::pDataID != 0); + CHECK_NULL(AwtDesktopProperties::pDataID); - AwtDesktopProperties::setBooleanPropertyID = env->GetMethodID(cls, "setBooleanProperty", "(Ljava/lang/String;Z)V"); + AwtDesktopProperties::setBooleanPropertyID = + env->GetMethodID(cls, "setBooleanProperty", "(Ljava/lang/String;Z)V"); DASSERT(AwtDesktopProperties::setBooleanPropertyID != 0); + CHECK_NULL(AwtDesktopProperties::setBooleanPropertyID); - AwtDesktopProperties::setIntegerPropertyID = env->GetMethodID(cls, "setIntegerProperty", "(Ljava/lang/String;I)V"); + AwtDesktopProperties::setIntegerPropertyID = + env->GetMethodID(cls, "setIntegerProperty", "(Ljava/lang/String;I)V"); DASSERT(AwtDesktopProperties::setIntegerPropertyID != 0); + CHECK_NULL(AwtDesktopProperties::setIntegerPropertyID); - AwtDesktopProperties::setStringPropertyID = env->GetMethodID(cls, "setStringProperty", "(Ljava/lang/String;Ljava/lang/String;)V"); + AwtDesktopProperties::setStringPropertyID = + env->GetMethodID(cls, "setStringProperty", "(Ljava/lang/String;Ljava/lang/String;)V"); DASSERT(AwtDesktopProperties::setStringPropertyID != 0); + CHECK_NULL(AwtDesktopProperties::setStringPropertyID); - AwtDesktopProperties::setColorPropertyID = env->GetMethodID(cls, "setColorProperty", "(Ljava/lang/String;III)V"); + AwtDesktopProperties::setColorPropertyID = + env->GetMethodID(cls, "setColorProperty", "(Ljava/lang/String;III)V"); DASSERT(AwtDesktopProperties::setColorPropertyID != 0); + CHECK_NULL(AwtDesktopProperties::setColorPropertyID); - AwtDesktopProperties::setFontPropertyID = env->GetMethodID(cls, "setFontProperty", "(Ljava/lang/String;Ljava/lang/String;II)V"); + AwtDesktopProperties::setFontPropertyID = + env->GetMethodID(cls, "setFontProperty", "(Ljava/lang/String;Ljava/lang/String;II)V"); DASSERT(AwtDesktopProperties::setFontPropertyID != 0); + CHECK_NULL(AwtDesktopProperties::setFontPropertyID); - AwtDesktopProperties::setSoundPropertyID = env->GetMethodID(cls, "setSoundProperty", "(Ljava/lang/String;Ljava/lang/String;)V"); + AwtDesktopProperties::setSoundPropertyID = + env->GetMethodID(cls, "setSoundProperty", "(Ljava/lang/String;Ljava/lang/String;)V"); DASSERT(AwtDesktopProperties::setSoundPropertyID != 0); + CHECK_NULL(AwtDesktopProperties::setSoundPropertyID); CATCH_BAD_ALLOC; } diff --git a/src/windows/native/sun/windows/awt_Event.cpp b/src/windows/native/sun/windows/awt_Event.cpp index 445ae8762f4cd75eea68880edb118210ada61a1e..e267285f09270fafda86611b957467ee48c6fe50 100644 --- a/src/windows/native/sun/windows/awt_Event.cpp +++ b/src/windows/native/sun/windows/awt_Event.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -45,12 +45,16 @@ Java_java_awt_Event_initIDs(JNIEnv *env, jclass cls) { TRY; AwtEvent::targetID = env->GetFieldID(cls, "target", "Ljava/lang/Object;"); - AwtEvent::xID = env->GetFieldID(cls, "x", "I"); - AwtEvent::yID = env->GetFieldID(cls, "y", "I"); - DASSERT(AwtEvent::targetID != NULL); + CHECK_NULL(AwtEvent::targetID); + + AwtEvent::xID = env->GetFieldID(cls, "x", "I"); DASSERT(AwtEvent::xID != NULL); + CHECK_NULL(AwtEvent::xID); + + AwtEvent::yID = env->GetFieldID(cls, "y", "I"); DASSERT(AwtEvent::yID != NULL); + CHECK_NULL(AwtEvent::yID); CATCH_BAD_ALLOC; } diff --git a/src/windows/native/sun/windows/awt_MouseEvent.cpp b/src/windows/native/sun/windows/awt_MouseEvent.cpp index d373b523e880928d8ff3b0959241baacbd9e805e..682c6e2fa6f37f5896219604f17a2793b8fba115 100644 --- a/src/windows/native/sun/windows/awt_MouseEvent.cpp +++ b/src/windows/native/sun/windows/awt_MouseEvent.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -45,12 +45,16 @@ Java_java_awt_event_MouseEvent_initIDs(JNIEnv *env, jclass cls) { TRY; AwtMouseEvent::xID = env->GetFieldID(cls, "x", "I"); - AwtMouseEvent::yID = env->GetFieldID(cls, "y", "I"); - AwtMouseEvent::buttonID = env->GetFieldID(cls, "button", "I"); - DASSERT(AwtMouseEvent::xID != NULL); + CHECK_NULL(AwtMouseEvent::xID); + + AwtMouseEvent::yID = env->GetFieldID(cls, "y", "I"); DASSERT(AwtMouseEvent::yID != NULL); + CHECK_NULL(AwtMouseEvent::yID); + + AwtMouseEvent::buttonID = env->GetFieldID(cls, "button", "I"); DASSERT(AwtMouseEvent::buttonID != NULL); + CHECK_NULL(AwtMouseEvent::buttonID); CATCH_BAD_ALLOC; } diff --git a/test/ProblemList.txt b/test/ProblemList.txt index 1d9efbc98432f06958d5d814adc5baa286fa126c..af94e076941e35f0dc3b2b933eb0d0ef44f36499 100644 --- a/test/ProblemList.txt +++ b/test/ProblemList.txt @@ -229,15 +229,6 @@ sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java solaris-all java/security/KeyPairGenerator/SolarisShortDSA.java solaris-all sun/security/tools/keytool/standard.sh solaris-all -# 8000439: NPG: REGRESSION : sun/security/krb5/auto/MaxRetries.java fails with timeout -sun/security/krb5/auto/MaxRetries.java solaris-sparcv9 - -# 8006690: sun/security/krb5/auto/BadKdc1.java fails intermittently -sun/security/krb5/auto/BadKdc1.java solaris-sparcv9 -sun/security/krb5/auto/BadKdc2.java solaris-sparcv9 -sun/security/krb5/auto/BadKdc3.java solaris-sparcv9 -sun/security/krb5/auto/BadKdc4.java solaris-sparcv9 - ############################################################################ # jdk_sound diff --git a/test/java/awt/FileDialog/SaveFileNameOverrideTest/SaveFileNameOverrideTest.java b/test/java/awt/FileDialog/SaveFileNameOverrideTest/SaveFileNameOverrideTest.java index 7348f663a8f89262f57d6701fedbb554d1f25382..79b5a3a6de0d1366a2b0aab433fce93db52fee40 100644 --- a/test/java/awt/FileDialog/SaveFileNameOverrideTest/SaveFileNameOverrideTest.java +++ b/test/java/awt/FileDialog/SaveFileNameOverrideTest/SaveFileNameOverrideTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, 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 @@ -23,7 +23,7 @@ /* test - @bug 6998877 + @bug 6998877 8022531 @summary After double-click on the folder names, FileNameOverrideTest FAILED @author Sergey.Bylokhov@oracle.com area=awt.filedialog @library ../../regtesthelpers @@ -59,7 +59,8 @@ public class SaveFileNameOverrideTest extends Applet implements ActionListener { String[] instructions = { "1) Click on 'Show File Dialog' button. A file dialog will come up.", - "2) Double-click on '" + clickDirName + "' and click OK.", + "2) Double-click on '" + clickDirName + "' and click a confirmation", + " button, it can be 'OK', 'Save' or any other platform-dependent name.", "3) See result of the test below" }; diff --git a/test/java/awt/Toolkit/Headless/WrappedToolkitTest/WrappedToolkitTest.sh b/test/java/awt/Toolkit/Headless/WrappedToolkitTest/WrappedToolkitTest.sh index 977f1b473618eeae199895db661be1d25980b164..8b404602ec57b352e114a7744b0908e29a619faa 100644 --- a/test/java/awt/Toolkit/Headless/WrappedToolkitTest/WrappedToolkitTest.sh +++ b/test/java/awt/Toolkit/Headless/WrappedToolkitTest/WrappedToolkitTest.sh @@ -1,7 +1,7 @@ #!/bin/ksh -p # -# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2012, 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 @@ -25,7 +25,7 @@ # # @test -# @bug 6282388 +# @bug 6282388 8030640 # @summary Tests that AWT use correct toolkit to be wrapped into HeadlessToolkit # @author artem.ananiev@sun.com: area=awt.headless # @compile TestWrapped.java @@ -59,30 +59,14 @@ pass() # Checking for proper OS OS=`uname -s` case "$OS" in - SunOS ) - VAR="One value for Sun" - DEFAULT_JDK=/usr/local/java/jdk1.2/solaris + SunOS | Linux | Darwin | CYGWIN* ) FILESEP="/" ;; - - Linux ) - VAR="A different value for Linux" - DEFAULT_JDK=/usr/local/java/jdk1.4/linux-i386 - FILESEP="/" - ;; - - Windows* | CYGWIN* ) - VAR="A different value for Win32" - DEFAULT_JDK=/usr/local/java/jdk1.2/win32 + + Windows* ) FILESEP="\\" ;; - Darwin) - VAR="Lets not forget about Mac" - DEFAULT_JDK=$(/usr/libexec/java_home) - FILESEP="/" - ;; - # catch all other OSs * ) echo "Unrecognized system! $OS" @@ -113,8 +97,7 @@ if [ -z "${TESTJAVA}" ] ; then # THIS IS THE JDK BEING TESTED. if [ -n "$1" ] ; then TESTJAVA=$1 - else echo "no JDK specified on command line so using default!" - TESTJAVA=$DEFAULT_JDK + else fail "no JDK specified on command line!" fi TESTSRC=. TESTCLASSES=. diff --git a/test/java/awt/event/KeyEvent/SwallowKeyEvents/SwallowKeyEvents.java b/test/java/awt/event/KeyEvent/SwallowKeyEvents/SwallowKeyEvents.java index c10094eed67d3d21b1947144da9164a4c4d82e26..310e78f9ff87eeeb219a0f319be1cfe6f8ea0241 100644 --- a/test/java/awt/event/KeyEvent/SwallowKeyEvents/SwallowKeyEvents.java +++ b/test/java/awt/event/KeyEvent/SwallowKeyEvents/SwallowKeyEvents.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 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 7154072 + @bug 7154072 7161320 @summary Tests that key events with modifiers are not swallowed. @author anton.tarasov: area=awt.focus @library ../../../regtesthelpers @@ -49,6 +49,11 @@ public class SwallowKeyEvents { static Robot r; public static void main(String[] args) { + if (sun.awt.OSInfo.getOSType() == sun.awt.OSInfo.OSType.WINDOWS) { + System.out.println("Skipped. Test not for MS Windows."); + return; + } + f.add(t); f.pack(); f.setVisible(true); diff --git a/test/java/util/Arrays/StreamAndSpliterator.java b/test/java/util/Arrays/StreamAndSpliterator.java new file mode 100644 index 0000000000000000000000000000000000000000..b475e7e6f3909c9e8c773b32de655c643dd1528f --- /dev/null +++ b/test/java/util/Arrays/StreamAndSpliterator.java @@ -0,0 +1,148 @@ +/* + * 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 8037857 + * @summary tests for stream and spliterator factory methods + * @run testng StreamAndSpliterator + */ + +import org.testng.annotations.Test; + +import java.util.Arrays; +import java.util.Spliterators; + +import static org.testng.Assert.assertNotNull; + +public class StreamAndSpliterator { + @Test + public void testStreamNPEs() { + assertThrowsNPE(() -> Arrays.stream((int[]) null, 0, 0)); + assertThrowsNPE(() -> Arrays.stream((long[]) null, 0, 0)); + assertThrowsNPE(() -> Arrays.stream((double[]) null, 0, 0)); + assertThrowsNPE(() -> Arrays.stream((String[]) null, 0, 0)); + } + + @Test + public void testStreamAIOBEs() { + // origin > fence + assertThrowsAIOOB(() -> Arrays.stream(new int[]{}, 1, 0)); + assertThrowsAIOOB(() -> Arrays.stream(new long[]{}, 1, 0)); + assertThrowsAIOOB(() -> Arrays.stream(new double[]{}, 1, 0)); + assertThrowsAIOOB(() -> Arrays.stream(new String[]{}, 1, 0)); + + // bad origin + assertThrowsAIOOB(() -> Arrays.stream(new int[]{}, -1, 0)); + assertThrowsAIOOB(() -> Arrays.stream(new long[]{}, -1, 0)); + assertThrowsAIOOB(() -> Arrays.stream(new double[]{}, -1, 0)); + assertThrowsAIOOB(() -> Arrays.stream(new String[]{}, -1, 0)); + + // bad fence + assertThrowsAIOOB(() -> Arrays.stream(new int[]{}, 0, 1)); + assertThrowsAIOOB(() -> Arrays.stream(new long[]{}, 0, 1)); + assertThrowsAIOOB(() -> Arrays.stream(new double[]{}, 0, 1)); + assertThrowsAIOOB(() -> Arrays.stream(new String[]{}, 0, 1)); + } + + + @Test + public void testSpliteratorNPEs() { + assertThrowsNPE(() -> Arrays.spliterator((int[]) null, 0, 0)); + assertThrowsNPE(() -> Arrays.spliterator((long[]) null, 0, 0)); + assertThrowsNPE(() -> Arrays.spliterator((double[]) null, 0, 0)); + assertThrowsNPE(() -> Arrays.spliterator((String[]) null, 0, 0)); + } + + @Test + public void testSpliteratorAIOBEs() { + // origin > fence + assertThrowsAIOOB(() -> Arrays.spliterator(new int[]{}, 1, 0)); + assertThrowsAIOOB(() -> Arrays.spliterator(new long[]{}, 1, 0)); + assertThrowsAIOOB(() -> Arrays.spliterator(new double[]{}, 1, 0)); + assertThrowsAIOOB(() -> Arrays.spliterator(new String[]{}, 1, 0)); + + // bad origin + assertThrowsAIOOB(() -> Arrays.spliterator(new int[]{}, -1, 0)); + assertThrowsAIOOB(() -> Arrays.spliterator(new long[]{}, -1, 0)); + assertThrowsAIOOB(() -> Arrays.spliterator(new double[]{}, -1, 0)); + assertThrowsAIOOB(() -> Arrays.spliterator(new String[]{}, -1, 0)); + + // bad fence + assertThrowsAIOOB(() -> Arrays.spliterator(new int[]{}, 0, 1)); + assertThrowsAIOOB(() -> Arrays.spliterator(new long[]{}, 0, 1)); + assertThrowsAIOOB(() -> Arrays.spliterator(new double[]{}, 0, 1)); + assertThrowsAIOOB(() -> Arrays.spliterator(new String[]{}, 0, 1)); + } + + + @Test + public void testSpliteratorNPEsFromSpliterators() { + assertThrowsNPE(() -> Spliterators.spliterator((int[]) null, 0, 0, 0)); + assertThrowsNPE(() -> Spliterators.spliterator((long[]) null, 0, 0, 0)); + assertThrowsNPE(() -> Spliterators.spliterator((double[]) null, 0, 0, 0)); + assertThrowsNPE(() -> Spliterators.spliterator((String[]) null, 0, 0, 0)); + } + + @Test + public void testSpliteratorAIOBEsFromSpliterators() { + // origin > fence + assertThrowsAIOOB(() -> Spliterators.spliterator(new int[]{}, 1, 0, 0)); + assertThrowsAIOOB(() -> Spliterators.spliterator(new long[]{}, 1, 0, 0)); + assertThrowsAIOOB(() -> Spliterators.spliterator(new double[]{}, 1, 0, 0)); + assertThrowsAIOOB(() -> Spliterators.spliterator(new String[]{}, 1, 0, 0)); + + // bad origin + assertThrowsAIOOB(() -> Spliterators.spliterator(new int[]{}, -1, 0, 0)); + assertThrowsAIOOB(() -> Spliterators.spliterator(new long[]{}, -1, 0, 0)); + assertThrowsAIOOB(() -> Spliterators.spliterator(new double[]{}, -1, 0, 0)); + assertThrowsAIOOB(() -> Spliterators.spliterator(new String[]{}, -1, 0, 0)); + + // bad fence + assertThrowsAIOOB(() -> Spliterators.spliterator(new int[]{}, 0, 1, 0)); + assertThrowsAIOOB(() -> Spliterators.spliterator(new long[]{}, 0, 1, 0)); + assertThrowsAIOOB(() -> Spliterators.spliterator(new double[]{}, 0, 1, 0)); + assertThrowsAIOOB(() -> Spliterators.spliterator(new String[]{}, 0, 1, 0)); + } + + void assertThrowsNPE(Runnable r) { + NullPointerException caught = null; + try { + r.run(); + } + catch (NullPointerException e) { + caught = e; + } + assertNotNull(caught, "NullPointerException not thrown"); + } + + void assertThrowsAIOOB(Runnable r) { + ArrayIndexOutOfBoundsException caught = null; + try { + r.run(); + } + catch (ArrayIndexOutOfBoundsException e) { + caught = e; + } + assertNotNull(caught, "ArrayIndexOutOfBoundsException not thrown"); + } +} diff --git a/test/sun/java2d/DrawXORModeTest.java b/test/sun/java2d/DrawXORModeTest.java new file mode 100644 index 0000000000000000000000000000000000000000..973c9a4a55b2253c805ad5f0bbff4995b28578db --- /dev/null +++ b/test/sun/java2d/DrawXORModeTest.java @@ -0,0 +1,110 @@ +/* + * 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 8036022 + * @summary Test verifies that drawing shapes with XOR composite + * does not trigger an InternalError in GDI surface data. + * @run main/othervm -Dsun.java2d.d3d=True DrawXORModeTest + */ +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.geom.Line2D; +import java.util.concurrent.CountDownLatch; + +public class DrawXORModeTest extends Component { + + public static void main(String[] args) { + final DrawXORModeTest c = new DrawXORModeTest(); + + final Frame f = new Frame("XOR mode test"); + f.add(c); + f.pack(); + + f.setVisible(true); + + try { + c.checkResult(); + } finally { + f.dispose(); + } + } + + @Override + public void paint(Graphics g) { + if (g == null || !(g instanceof Graphics2D)) { + return; + } + g.setColor(Color.white); + g.setXORMode(Color.black); + Graphics2D dg = (Graphics2D) g; + Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_MITER, + 10.0f, + new float[]{1.0f, 1.0f}, + 0.0f); + dg.setStroke(stroke); + try { + dg.draw(new Line2D.Float(10, 10, 20, 20)); + } catch (Throwable e) { + synchronized (this) { + theError = e; + } + } finally { + didDraw.countDown(); + } + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(400, 100); + } + + public void checkResult() { + try { + didDraw.await(); + } catch (InterruptedException e) { + } + + synchronized (this) { + if (theError != null) { + System.out.println("Error: " + theError); + + throw new RuntimeException("Test FAILED."); + } + } + System.out.println("Test PASSED."); + + } + + private Throwable theError = null; + + private final CountDownLatch didDraw = new CountDownLatch(1); +} diff --git a/test/sun/security/krb5/auto/BadKdc.java b/test/sun/security/krb5/auto/BadKdc.java index 1c10ccd69aa521f6ea3cba3218750004ffddbeab..d1ace1a4157a15095385d1a1c015eed9477ad51b 100644 --- a/test/sun/security/krb5/auto/BadKdc.java +++ b/test/sun/security/krb5/auto/BadKdc.java @@ -39,7 +39,29 @@ public class BadKdc { // ^ kdc# ^ timeout static final Pattern re = Pattern.compile( ">>> KDCCommunication: kdc=kdc.rabbit.hole UDP:(\\d)...., " + - "timeout=(\\d)000,"); + "timeout=(\\d+),"); + + // Ratio for timeout values of all timeout tests. Not final so that + // each test can choose their own. + static float ratio = 2f; + + static void setRatio(float ratio) { + BadKdc.ratio = ratio; + } + + static float getRatio() { + return ratio; + } + + // Gets real timeout value. This method is called when writing krb5.conf + static int toReal(int from) { + return (int)(from * ratio + .5); + } + + // De-ratio a millisecond value to second + static int toSymbolicSec(int from) { + return (int)(from / ratio / 1000f + 0.5); + } /* * There are several cases this test fails: @@ -101,7 +123,7 @@ public class BadKdc { fw.write("[libdefaults]\n" + "default_realm = " + OneKDC.REALM + "\n" + - "kdc_timeout = 2000\n"); + "kdc_timeout = " + toReal(2000) + "\n"); fw.write("[realms]\n" + OneKDC.REALM + " = {\n" + "kdc = " + OneKDC.KDCHOST + ":" + p1 + "\n" + "kdc = " + OneKDC.KDCHOST + ":" + p2 + "\n" + @@ -184,7 +206,8 @@ public class BadKdc { Matcher m = re.matcher(line); if (m.find()) { System.out.println(line); - sb.append(m.group(1)).append(m.group(2)); + sb.append(m.group(1)) + .append(toSymbolicSec(Integer.parseInt(m.group(2)))); } } if (failed) sb.append('-'); diff --git a/test/sun/security/krb5/auto/BadKdc1.java b/test/sun/security/krb5/auto/BadKdc1.java index 7db7b8ad7a89eb85864a7bf56845813668849391..dd608939a92a3f78aa58805fa0b1de0d525e2354 100644 --- a/test/sun/security/krb5/auto/BadKdc1.java +++ b/test/sun/security/krb5/auto/BadKdc1.java @@ -28,14 +28,21 @@ * @summary krb5 should not try to access unavailable kdc too often */ -import java.io.*; import java.security.Security; public class BadKdc1 { public static void main(String[] args) throws Exception { - Security.setProperty("krb5.kdc.bad.policy", "tryLess"); + + // 5 sec is default timeout for tryLess + if (BadKdc.getRatio() > 2.5) { + Security.setProperty("krb5.kdc.bad.policy", + "tryLess:1," + BadKdc.toReal(2000)); + } else { + Security.setProperty("krb5.kdc.bad.policy", "tryLess"); + } + BadKdc.go( "121212222222(32){1,2}1222(32){1,2}", // 1 2 // The above line means try kdc1 for 2 seconds then kdc1 diff --git a/test/sun/security/krb5/auto/BadKdc2.java b/test/sun/security/krb5/auto/BadKdc2.java index 7568784521dca4096824775ccb3338eeb0aa5de3..4291d5c14c0947c0c2a0eb73bc300d5bd3b39cfe 100644 --- a/test/sun/security/krb5/auto/BadKdc2.java +++ b/test/sun/security/krb5/auto/BadKdc2.java @@ -35,7 +35,12 @@ public class BadKdc2 { public static void main(String[] args) throws Exception { - Security.setProperty("krb5.kdc.bad.policy", "tryLess:2,1000"); + + // 1 sec is too short. + BadKdc.setRatio(3.0f); + + Security.setProperty( + "krb5.kdc.bad.policy", "tryLess:2," + BadKdc.toReal(1000)); BadKdc.go( "121212222222(32){1,2}11112121(32){1,2}", // 1 2 "11112121(32){1,2}11112121(32){1,2}", // 1 2 diff --git a/test/sun/security/krb5/auto/MaxRetries.java b/test/sun/security/krb5/auto/MaxRetries.java index 2e896bc5a563a10c70a7a1109fae028279212764..880c023338123763aa88d6091109a2b200910067 100644 --- a/test/sun/security/krb5/auto/MaxRetries.java +++ b/test/sun/security/krb5/auto/MaxRetries.java @@ -60,7 +60,7 @@ public class MaxRetries { test1(5000, 2); // 2 2 // For tryLess - Security.setProperty("krb5.kdc.bad.policy", "tryless"); + Security.setProperty("krb5.kdc.bad.policy", "tryless:1," + BadKdc.toReal(5000)); rewriteMaxRetries(4); test1(4000, 7); // 1 1 1 1 2 1 2 test1(4000, 4); // 1 2 1 2 @@ -94,7 +94,7 @@ public class MaxRetries { * @param count the expected total try */ private static void test1(int timeout, int count) throws Exception { - String timeoutTag = "timeout=" + timeout; + String timeoutTag = "timeout=" + BadKdc.toReal(timeout); ByteArrayOutputStream bo = new ByteArrayOutputStream(); PrintStream oldout = System.out; System.setOut(new PrintStream(bo)); @@ -192,12 +192,12 @@ public class MaxRetries { if (s.startsWith("[realms]")) { // Reconfig global setting fw.write("max_retries = 2\n"); - fw.write("kdc_timeout = 5000\n"); + fw.write("kdc_timeout = " + BadKdc.toReal(5000) + "\n"); } else if (s.trim().startsWith("kdc = ")) { if (value != -1) { // Reconfig for realm fw.write(" max_retries = " + value + "\n"); - fw.write(" kdc_timeout = " + (value*1000) + "\n"); + fw.write(" kdc_timeout = " + BadKdc.toReal(value*1000) + "\n"); } // Add a bad KDC as the first candidate fw.write(" kdc = localhost:33333\n"); diff --git a/test/sun/security/krb5/auto/TcpTimeout.java b/test/sun/security/krb5/auto/TcpTimeout.java index 325d5bb3591d25d7b8080155d7cdbb91b958b09d..45699fbe5addfd8ee2b50c571a1ee4641db4eb48 100644 --- a/test/sun/security/krb5/auto/TcpTimeout.java +++ b/test/sun/security/krb5/auto/TcpTimeout.java @@ -63,7 +63,7 @@ public class TcpTimeout { "udp_preference_limit = 1\n" + "max_retries = 2\n" + "default_realm = " + OneKDC.REALM + "\n" + - "kdc_timeout = 5000\n"); + "kdc_timeout = " + BadKdc.toReal(5000) + "\n"); fw.write("[realms]\n" + OneKDC.REALM + " = {\n" + "kdc = " + OneKDC.KDCHOST + ":" + p1 + "\n" + "kdc = " + OneKDC.KDCHOST + ":" + p2 + "\n" + diff --git a/test/sun/security/krb5/config/ExtraLines.java b/test/sun/security/krb5/config/ExtraLines.java new file mode 100644 index 0000000000000000000000000000000000000000..babb0c0749d1c2253cd38d6e5c1783bc3d4b0f7a --- /dev/null +++ b/test/sun/security/krb5/config/ExtraLines.java @@ -0,0 +1,52 @@ +/* + * 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 8036971 + * @compile -XDignore.symbol.file ExtraLines.java + * @run main/othervm ExtraLines + * @summary krb5.conf does not accept directive lines before the first section + */ + +import sun.security.krb5.Config; +import java.nio.file.*; +import java.util.Objects; + +public class ExtraLines { + public static void main(String[] args) throws Exception { + Path base = Paths.get("krb5.conf"); + Path include = Paths.get("included.conf"); + String baseConf = "include " + include.toAbsolutePath().toString() + + "\n[x]\na = b\n"; + String includeConf = "[y]\nc = d\n"; + Files.write(include, includeConf.getBytes()); + Files.write(base, baseConf.getBytes()); + + System.setProperty("java.security.krb5.conf", base.toString()); + Config.refresh(); + + if (!Objects.equals(Config.getInstance().get("x", "a"), "b")) { + throw new Exception("Failed"); + } + } +} diff --git a/test/sun/security/provider/certpath/PKIXCertPathValidator/Validity.java b/test/sun/security/provider/certpath/PKIXCertPathValidator/Validity.java new file mode 100644 index 0000000000000000000000000000000000000000..056a369e81a18a002403e5924af562604fd85434 --- /dev/null +++ b/test/sun/security/provider/certpath/PKIXCertPathValidator/Validity.java @@ -0,0 +1,134 @@ +/* + * 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 8021804 + * @summary CertPath should validate even if the validity period of the + * root cert does not include the validity period of a subordinate + * cert. + */ + +import java.io.ByteArrayInputStream; +import java.security.cert.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +public class Validity { + + /* + * Subject: OU=TestOrg, CN=TestCA + * Issuer: OU=TestOrg, CN=TestCA + * Validity + * Not Before: Feb 26 21:33:55 2014 GMT + Not After : Feb 26 21:33:55 2024 GMT + * Version 1 + */ + static String CACertStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIIBvTCCASYCCQCQRiTo4lBCFjANBgkqhkiG9w0BAQUFADAjMRAwDgYDVQQLDAdU\n" + + "ZXN0T3JnMQ8wDQYDVQQDDAZUZXN0Q0EwHhcNMTQwMjI2MjEzMzU1WhcNMjQwMjI2\n" + + "MjEzMzU1WjAjMRAwDgYDVQQLDAdUZXN0T3JnMQ8wDQYDVQQDDAZUZXN0Q0EwgZ8w\n" + + "DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOtKS4ZrsM3ansd61ZxitcrN0w184I+A\n" + + "z0kyrSP1eMtlam+cC2U91NpTz11FYV4XUfBhqqxaXW043AWTUer8pS90Pt4sCrUX\n" + + "COx1+QA1M3ZhbZ4sTM7XQ90JbGaBJ/sEza9mlQP7hQ2yQO/hATKbP6J5qvgG2sT2\n" + + "S2WYjEgwNwmFAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAQ/CXEpnx2WY4LJtv4jwE\n" + + "4jIVirur3pdzV5oBhPyqqHMsyhQBkukCfX7uD7L5wN1+xuM81DfANpIxlnUfybp5\n" + + "CpjcmktLpmyK4kJ6XnSd2blbLOIpsr9x6FqxPxpVDlyw/ySHYrIG/GZdsLHgmzGn\n" + + "B06jeYzH8OLf879VxAxSsPc=\n" + + "-----END CERTIFICATE-----"; + + /* + * Subject: OU=TestOrg, CN=TestEE0 + * Issuer: OU=TestOrg, CN=TestCA + * Validity + * Not Before: Feb 26 22:55:12 2014 GMT + * Not After : Feb 25 22:55:12 2025 GMT + * Version 1 + */ + static String EECertStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIIBtjCCAR8CAQQwDQYJKoZIhvcNAQEFBQAwIzEQMA4GA1UECwwHVGVzdE9yZzEP\n" + + "MA0GA1UEAwwGVGVzdENBMB4XDTE0MDIyNjIyNTUxMloXDTI1MDIyNTIyNTUxMlow\n" + + "JDEQMA4GA1UECwwHVGVzdE9yZzEQMA4GA1UEAwwHVGVzdEVFMDCBnzANBgkqhkiG\n" + + "9w0BAQEFAAOBjQAwgYkCgYEAt8xz9W3ruCTHjSOtTX6cxsUZ0nRP6EavEfzgcOYh\n" + + "CXGA0gr+viSHq3c2vQBxiRny2hm5rLcqpPo+2OxZtw/ajxfyrV6d/r8YyQLBvyl3\n" + + "xdCZdOkG1DCM1oFAQDaSRt9wN5Zm5kyg7uMig5Y4L45fP9Yee4x6Xyh36qYbsR89\n" + + "rFMCAwEAATANBgkqhkiG9w0BAQUFAAOBgQDZrPqSo08va1m9TOWOztTuWilGdjK/\n" + + "2Ed2WXg8utIpy6uAV+NaOYtHQ7ULQBVRNmwg9nKghbVbh+E/xpoihjl1x7OXass4\n" + + "TbwXA5GKFIFpNtDvATQ/QQZoCuCzw1FW/mH0Q7UEQ/9/iJdDad6ebkapeMwtj/8B\n" + + "s2IZV7s85CEOXw==\n" + + "-----END CERTIFICATE-----"; + + public static void main(String[] args) throws Exception { + + String[] certStrs = {EECertStr}; + String[] trustedCertStrs = {CACertStr}; + runTest(certStrs, trustedCertStrs); + + System.out.println("Test passed."); + } + + private static void runTest(String[] certStrs, + String[] trustedCertStrs) + throws Exception { + + CertificateFactory cf = CertificateFactory.getInstance("X509"); + + // Generate the CertPath from the certs named in certStrs + ArrayList certs = new ArrayList<>(); + for (String certStr : certStrs) { + certs.add(generateCert(certStr, cf)); + } + CertPath cp = cf.generateCertPath(certs); + + // Generate the set of Trust Anchors from the certs named in + // trustedCertStrs + Set trustAnchors = new HashSet<>(); + for (String trustedCertStr : trustedCertStrs) { + TrustAnchor ta = new TrustAnchor(generateCert(trustedCertStr, cf), + null); + trustAnchors.add(ta); + } + PKIXParameters params = new PKIXParameters(trustAnchors); + params.setDate(new Date(114, 3, 1)); // 2014-03-01 + params.setRevocationEnabled(false); + + // Attempt to validate the CertPath. If no exception thrown, successful. + CertPathValidator cpv = CertPathValidator.getInstance("PKIX"); + cpv.validate(cp, params); + System.out.println("CertPath validation successful."); + } + + private static X509Certificate generateCert(String certStr, + CertificateFactory cf) + throws Exception { + ByteArrayInputStream stream + = new ByteArrayInputStream(certStr.getBytes()); + return (X509Certificate) cf.generateCertificate(stream); + + } +}