# HG changeset patch # User lana # Date 1340776043 25200 # Node ID a2cf86579ad424b04a29f5eb2624f88794e1b3b2 # Parent 2c1fa96ba3d7037fb76f8dcc60b9d6fbe70a5654# Parent 9b19b2302c28f4da6d4078f66234abecfed5688a Merge diff -r 2c1fa96ba3d7 -r a2cf86579ad4 .hgtags --- a/.hgtags Tue Jun 26 15:28:21 2012 -0700 +++ b/.hgtags Tue Jun 26 22:47:23 2012 -0700 @@ -165,3 +165,4 @@ c029c972396cea042a0dc67c0f7ccf2fe68007d4 jdk8-b41 5c5a64ec0839df5affe9394b99ff338c363acbca jdk8-b42 69d8a827cdf9236be9694a46d75c710d71dac7d7 jdk8-b43 +7e981cb0ad6a194f1fa859f9ad47586db461f269 jdk8-b44 diff -r 2c1fa96ba3d7 -r a2cf86579ad4 .hgtags-top-repo --- a/.hgtags-top-repo Tue Jun 26 15:28:21 2012 -0700 +++ b/.hgtags-top-repo Tue Jun 26 22:47:23 2012 -0700 @@ -165,3 +165,4 @@ 1a8c7c530f8a9b7f5bdb9b0693b2f5435ca5205e jdk8-b41 1ce5dc16416611c58b7480ca67a2eee5153498a6 jdk8-b42 661c9aae602bbd9766d12590800c90f1edd1d8dd jdk8-b43 +e4f81a817447c3a4f6868f083c81c2fb1b15d44c jdk8-b44 diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/.hgtags --- a/corba/.hgtags Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/.hgtags Tue Jun 26 22:47:23 2012 -0700 @@ -165,3 +165,4 @@ 113f0d5f0a08aa0947b3edf783b603e7f042748a jdk8-b41 79cc42c9c71bbd6630ede681642e98f5e4a841fa jdk8-b42 cd879aff5d3cc1f58829aab3116880aa19525b78 jdk8-b43 +439d9bf8e4ff204cc89c9974c1515a508b2cc6ff jdk8-b44 diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/com/sun/corba/se/impl/interceptors/ClientRequestInfoImpl.java --- a/corba/src/share/classes/com/sun/corba/se/impl/interceptors/ClientRequestInfoImpl.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/com/sun/corba/se/impl/interceptors/ClientRequestInfoImpl.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -217,7 +217,7 @@ // ClientRequestInfo validity table (see ptc/00-08-06 table 21-1). // Note: These must be in the same order as specified in contants. - protected static final boolean validCall[][] = { + private static final boolean validCall[][] = { // LEGEND: // s_req = send_request r_rep = receive_reply // s_pol = send_poll r_exc = receive_exception diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/com/sun/corba/se/impl/interceptors/ServerRequestInfoImpl.java --- a/corba/src/share/classes/com/sun/corba/se/impl/interceptors/ServerRequestInfoImpl.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/com/sun/corba/se/impl/interceptors/ServerRequestInfoImpl.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -195,7 +195,7 @@ // ServerRequestInfo validity table (see ptc/00-08-06 table 21-2). // Note: These must be in the same order as specified in contants. - protected static final boolean validCall[][] = { + private static final boolean validCall[][] = { // LEGEND: // r_rsc = receive_request_service_contexts // r_req = receive_request diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/com/sun/corba/se/impl/javax/rmi/CORBA/Util.java --- a/corba/src/share/classes/com/sun/corba/se/impl/javax/rmi/CORBA/Util.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/com/sun/corba/se/impl/javax/rmi/CORBA/Util.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -130,10 +130,23 @@ private UtilSystemException utilWrapper = UtilSystemException.get( CORBALogDomains.RPC_ENCODING); - public static Util instance = null; + private static Util instance = null; public Util() { - instance = this; + setInstance(this); + } + + private static void setInstance( Util util ) { + assert instance == null : "Instance already defined"; + instance = util; + } + + public static Util getInstance() { + return instance; + } + + public static boolean isInstanceDefined() { + return instance != null; } // Used by TOAFactory.shutdown to unexport all targets for this diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/com/sun/corba/se/impl/oa/poa/POAPolicyMediatorBase_R.java --- a/corba/src/share/classes/com/sun/corba/se/impl/oa/poa/POAPolicyMediatorBase_R.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/com/sun/corba/se/impl/oa/poa/POAPolicyMediatorBase_R.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -93,7 +93,7 @@ activeObjectMap.putServant( servant, entry ) ; - if (Util.instance != null) { + if (Util.isInstanceDefined()) { POAManagerImpl pm = (POAManagerImpl)poa.the_POAManager() ; POAFactory factory = pm.getFactory() ; factory.registerPOAForServant(poa, servant); @@ -129,7 +129,7 @@ activeObjectMap.remove(key); - if (Util.instance != null) { + if (Util.isInstanceDefined()) { POAManagerImpl pm = (POAManagerImpl)poa.the_POAManager() ; POAFactory factory = pm.getFactory() ; factory.unregisterPOAForServant(poa, s); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/com/sun/corba/se/impl/oa/toa/TOAFactory.java --- a/corba/src/share/classes/com/sun/corba/se/impl/oa/toa/TOAFactory.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/com/sun/corba/se/impl/oa/toa/TOAFactory.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -78,8 +78,8 @@ public void shutdown( boolean waitForCompletion ) { - if (Util.instance != null) { - Util.instance.unregisterTargetsForORB(orb); + if (Util.isInstanceDefined()) { + Util.getInstance().unregisterTargetsForORB(orb); } } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/com/sun/corba/se/impl/orb/ParserTable.java --- a/corba/src/share/classes/com/sun/corba/se/impl/orb/ParserTable.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/com/sun/corba/se/impl/orb/ParserTable.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -106,7 +106,9 @@ public ParserData[] getParserData() { - return parserData ; + ParserData[] parserArray = new ParserData[parserData.length]; + System.arraycopy(parserData, 0, parserArray, 0, parserData.length); + return parserArray; } private ParserTable() { diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3.java --- a/corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -62,7 +62,7 @@ // legal use of '.' in a Java name. public static final RepositoryIdCache_1_3 cache = new RepositoryIdCache_1_3(); - public static final byte[] IDL_IDENTIFIER_CHARS = { + private static final byte[] IDL_IDENTIFIER_CHARS = { // 0 1 2 3 4 5 6 7 8 9 a b c d e f 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 00-0f @@ -180,7 +180,7 @@ public static final String kRemoteTypeStr = ""; public static final String kRemoteValueRepID = ""; - public static final Hashtable kSpecialArrayTypeStrings = new Hashtable(); + private static final Hashtable kSpecialArrayTypeStrings = new Hashtable(); static { kSpecialArrayTypeStrings.put("CORBA.WStringValue", new StringBuffer(java.lang.String.class.getName())); @@ -189,7 +189,7 @@ } - public static final Hashtable kSpecialCasesRepIDs = new Hashtable(); + private static final Hashtable kSpecialCasesRepIDs = new Hashtable(); static { kSpecialCasesRepIDs.put(java.lang.String.class, kWStringValueRepID); @@ -197,7 +197,7 @@ kSpecialCasesRepIDs.put(java.rmi.Remote.class, kRemoteValueRepID); } - public static final Hashtable kSpecialCasesStubValues = new Hashtable(); + private static final Hashtable kSpecialCasesStubValues = new Hashtable(); static { kSpecialCasesStubValues.put(java.lang.String.class, kWStringStubValue); @@ -209,7 +209,7 @@ } - public static final Hashtable kSpecialCasesVersions = new Hashtable(); + private static final Hashtable kSpecialCasesVersions = new Hashtable(); static { kSpecialCasesVersions.put(java.lang.String.class, kWStringValueHash); @@ -220,7 +220,7 @@ kSpecialCasesVersions.put(java.rmi.Remote.class, kRemoteValueHash); } - public static final Hashtable kSpecialCasesClasses = new Hashtable(); + private static final Hashtable kSpecialCasesClasses = new Hashtable(); static { kSpecialCasesClasses.put(kWStringTypeStr, java.lang.String.class); @@ -232,7 +232,7 @@ //kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote.class); } - public static final Hashtable kSpecialCasesArrayPrefix = new Hashtable(); + private static final Hashtable kSpecialCasesArrayPrefix = new Hashtable(); static { kSpecialCasesArrayPrefix.put(java.lang.String.class, kValuePrefix + kSequencePrefix + kCORBAPrefix); @@ -243,7 +243,7 @@ kSpecialCasesArrayPrefix.put(java.rmi.Remote.class, kValuePrefix + kSequencePrefix + kCORBAPrefix); } - public static final Hashtable kSpecialPrimitives = new Hashtable(); + private static final Hashtable kSpecialPrimitives = new Hashtable(); static { kSpecialPrimitives.put("int","long"); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3_1.java --- a/corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3_1.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3_1.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -63,7 +63,7 @@ // uniformly, and is safe because that is the only // legal use of '.' in a Java name. - public static final byte[] IDL_IDENTIFIER_CHARS = { + private static final byte[] IDL_IDENTIFIER_CHARS = { // 0 1 2 3 4 5 6 7 8 9 a b c d e f 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 00-0f @@ -198,7 +198,7 @@ public static final String kRemoteTypeStr = ""; public static final String kRemoteValueRepID = ""; - public static final Hashtable kSpecialArrayTypeStrings = new Hashtable(); + private static final Hashtable kSpecialArrayTypeStrings = new Hashtable(); static { kSpecialArrayTypeStrings.put("CORBA.WStringValue", new StringBuffer(java.lang.String.class.getName())); @@ -207,7 +207,7 @@ } - public static final Hashtable kSpecialCasesRepIDs = new Hashtable(); + private static final Hashtable kSpecialCasesRepIDs = new Hashtable(); static { kSpecialCasesRepIDs.put(java.lang.String.class, kWStringValueRepID); @@ -215,7 +215,7 @@ kSpecialCasesRepIDs.put(java.rmi.Remote.class, kRemoteValueRepID); } - public static final Hashtable kSpecialCasesStubValues = new Hashtable(); + private static final Hashtable kSpecialCasesStubValues = new Hashtable(); static { kSpecialCasesStubValues.put(java.lang.String.class, kWStringStubValue); @@ -227,7 +227,7 @@ } - public static final Hashtable kSpecialCasesVersions = new Hashtable(); + private static final Hashtable kSpecialCasesVersions = new Hashtable(); static { kSpecialCasesVersions.put(java.lang.String.class, kWStringValueHash); @@ -238,7 +238,7 @@ kSpecialCasesVersions.put(java.rmi.Remote.class, kRemoteValueHash); } - public static final Hashtable kSpecialCasesClasses = new Hashtable(); + private static final Hashtable kSpecialCasesClasses = new Hashtable(); static { kSpecialCasesClasses.put(kWStringTypeStr, java.lang.String.class); @@ -250,7 +250,7 @@ //kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote.class); } - public static final Hashtable kSpecialCasesArrayPrefix = new Hashtable(); + private static final Hashtable kSpecialCasesArrayPrefix = new Hashtable(); static { kSpecialCasesArrayPrefix.put(java.lang.String.class, kValuePrefix + kSequencePrefix + kCORBAPrefix); @@ -261,7 +261,7 @@ kSpecialCasesArrayPrefix.put(java.rmi.Remote.class, kValuePrefix + kSequencePrefix + kCORBAPrefix); } - public static final Hashtable kSpecialPrimitives = new Hashtable(); + private static final Hashtable kSpecialPrimitives = new Hashtable(); static { kSpecialPrimitives.put("int","long"); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/com/sun/corba/se/impl/protocol/LocalClientRequestDispatcherBase.java --- a/corba/src/share/classes/com/sun/corba/se/impl/protocol/LocalClientRequestDispatcherBase.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/com/sun/corba/se/impl/protocol/LocalClientRequestDispatcherBase.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -52,7 +52,7 @@ // If isNextIsLocalValid.get() == Boolean.TRUE, // the next call to isLocal should be valid - protected static ThreadLocal isNextCallValid = new ThreadLocal() { + private static final ThreadLocal isNextCallValid = new ThreadLocal() { protected synchronized Object initialValue() { return Boolean.TRUE; } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/com/sun/corba/se/impl/util/RepositoryId.java --- a/corba/src/share/classes/com/sun/corba/se/impl/util/RepositoryId.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/com/sun/corba/se/impl/util/RepositoryId.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -57,7 +57,7 @@ // uniformly, and is safe because that is the only // legal use of '.' in a Java name. - public static final byte[] IDL_IDENTIFIER_CHARS = { + private static final byte[] IDL_IDENTIFIER_CHARS = { // 0 1 2 3 4 5 6 7 8 9 a b c d e f 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 00-0f @@ -95,7 +95,7 @@ private static IdentityHashtable classIDLToRepStr = new IdentityHashtable(); private static IdentityHashtable classSeqToRepStr = new IdentityHashtable(); - private static IdentityHashtable repStrToByteArray = new IdentityHashtable(); + private static final IdentityHashtable repStrToByteArray = new IdentityHashtable(); private static Hashtable repStrToClass = new Hashtable(); private String repId = null; @@ -192,7 +192,7 @@ public static final String kRemoteTypeStr = ""; public static final String kRemoteValueRepID = ""; - public static final Hashtable kSpecialArrayTypeStrings = new Hashtable(); + private static final Hashtable kSpecialArrayTypeStrings = new Hashtable(); static { kSpecialArrayTypeStrings.put("CORBA.WStringValue", new StringBuffer(java.lang.String.class.getName())); @@ -201,7 +201,7 @@ } - public static final Hashtable kSpecialCasesRepIDs = new Hashtable(); + private static final Hashtable kSpecialCasesRepIDs = new Hashtable(); static { kSpecialCasesRepIDs.put(java.lang.String.class, kWStringValueRepID); @@ -209,7 +209,7 @@ kSpecialCasesRepIDs.put(java.rmi.Remote.class, kRemoteValueRepID); } - public static final Hashtable kSpecialCasesStubValues = new Hashtable(); + private static final Hashtable kSpecialCasesStubValues = new Hashtable(); static { kSpecialCasesStubValues.put(java.lang.String.class, kWStringStubValue); @@ -221,7 +221,7 @@ } - public static final Hashtable kSpecialCasesVersions = new Hashtable(); + private static final Hashtable kSpecialCasesVersions = new Hashtable(); static { kSpecialCasesVersions.put(java.lang.String.class, kWStringValueHash); @@ -232,7 +232,7 @@ kSpecialCasesVersions.put(java.rmi.Remote.class, kRemoteValueHash); } - public static final Hashtable kSpecialCasesClasses = new Hashtable(); + private static final Hashtable kSpecialCasesClasses = new Hashtable(); static { kSpecialCasesClasses.put(kWStringTypeStr, java.lang.String.class); @@ -244,7 +244,7 @@ //kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote.class); } - public static final Hashtable kSpecialCasesArrayPrefix = new Hashtable(); + private static final Hashtable kSpecialCasesArrayPrefix = new Hashtable(); static { kSpecialCasesArrayPrefix.put(java.lang.String.class, kValuePrefix + kSequencePrefix + kCORBAPrefix); @@ -255,7 +255,7 @@ kSpecialCasesArrayPrefix.put(java.rmi.Remote.class, kValuePrefix + kSequencePrefix + kCORBAPrefix); } - public static final Hashtable kSpecialPrimitives = new Hashtable(); + private static final Hashtable kSpecialPrimitives = new Hashtable(); static { kSpecialPrimitives.put("int","long"); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/com/sun/corba/se/spi/logging/CORBALogDomains.java --- a/corba/src/share/classes/com/sun/corba/se/spi/logging/CORBALogDomains.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/com/sun/corba/se/spi/logging/CORBALogDomains.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -58,7 +58,7 @@ private CORBALogDomains() {} // Top level log domain for CORBA - public static String TOP_LEVEL_DOMAIN = "javax.enterprise.resource.corba"; + public static final String TOP_LEVEL_DOMAIN = "javax.enterprise.resource.corba"; public static final String RPC = "rpc" ; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/sun/rmi/rmic/iiop/IDLNames.java --- a/corba/src/share/classes/sun/rmi/rmic/iiop/IDLNames.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/sun/rmi/rmic/iiop/IDLNames.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -71,6 +71,34 @@ (byte)'F', }; + // Legal IDL Identifier characters (1 = legal). Note + // that '.' (2E) is marked as legal even though it is + // not legal in IDL. This allows us to treat a fully + // qualified Java name with '.' package separators + // uniformly, and is safe because that is the only + // legal use of '.' in a Java name. + + private static final byte[] IDL_IDENTIFIER_CHARS = { + + // 0 1 2 3 4 5 6 7 8 9 a b c d e f + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 00-0f + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 10-1f + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,1,0, // 20-2f + 1,1,1,1, 1,1,1,1, 1,1,0,0, 0,0,0,0, // 30-3f + 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // 40-4f + 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,1, // 50-5f + 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // 60-6f + 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0, // 70-7f + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 80-8f + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 90-9f + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // a0-af + 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // b0-bf + 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // c0-cf + 0,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,0,1, // d0-df + 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // e0-ef + 0,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,0,1, // f0-ff + }; + //_____________________________________________________________________ // Public Interfaces //_____________________________________________________________________ @@ -139,7 +167,7 @@ result = replace(result,"x\\U","U"); // Now see if we have any remaining illegal characters (see - // RepositoryId.IDL_IDENTIFIER_CHARS array)... + // IDL_IDENTIFIER_CHARS array)... int length = result.length(); StringBuffer buffer = null; @@ -148,7 +176,7 @@ char c = result.charAt(i); - if (c > 255 || RepositoryId.IDL_IDENTIFIER_CHARS[c] == 0) { + if (c > 255 || IDL_IDENTIFIER_CHARS[c] == 0) { // We gotta convert. Have we already started? diff -r 2c1fa96ba3d7 -r a2cf86579ad4 corba/src/share/classes/sun/rmi/rmic/iiop/StubGenerator.java --- a/corba/src/share/classes/sun/rmi/rmic/iiop/StubGenerator.java Tue Jun 26 15:28:21 2012 -0700 +++ b/corba/src/share/classes/sun/rmi/rmic/iiop/StubGenerator.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -425,7 +425,7 @@ // Write the _ids() method... p.plnI("public String[] _ids() { "); - p.pln("return _type_ids;"); + p.pln("return (String[]) _type_ids.clone();"); p.pOln("}"); // Get all the methods and write each stub method... @@ -1860,11 +1860,11 @@ { if(POATie){ p.plnI("public String[] _all_interfaces(org.omg.PortableServer.POA poa, byte[] objectId){"); - p.pln("return _type_ids;"); + p.pln("return (String[]) _type_ids.clone();"); p.pOln("}"); } else { p.plnI("public String[] _ids() { "); - p.pln("return _type_ids;"); + p.pln("return (String[]) _type_ids.clone();"); p.pOln("}"); } } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 hotspot/.hgtags --- a/hotspot/.hgtags Tue Jun 26 15:28:21 2012 -0700 +++ b/hotspot/.hgtags Tue Jun 26 22:47:23 2012 -0700 @@ -255,3 +255,4 @@ 55954061c6e8750ea39a63523fd65d580db6eeb1 jdk8-b42 e77b8e0ed1f84e3e268239e276c7ab64fa573baa jdk8-b43 5ba29a1db46ecb80a321ca873adb56a3fe6ad320 hs24-b14 +831e5c76a20af18f3c08c5a95ed31be0e128a010 jdk8-b44 diff -r 2c1fa96ba3d7 -r a2cf86579ad4 hotspot/src/share/vm/ci/ciField.cpp --- a/hotspot/src/share/vm/ci/ciField.cpp Tue Jun 26 15:28:21 2012 -0700 +++ b/hotspot/src/share/vm/ci/ciField.cpp Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -67,7 +67,7 @@ // ------------------------------------------------------------------ // ciField::ciField -ciField::ciField(ciInstanceKlass* klass, int index): _known_to_link_with(NULL) { +ciField::ciField(ciInstanceKlass* klass, int index): _known_to_link_with_put(NULL), _known_to_link_with_get(NULL) { ASSERT_IN_VM; CompilerThread *thread = CompilerThread::current(); @@ -143,7 +143,7 @@ initialize_from(&field_desc); } -ciField::ciField(fieldDescriptor *fd): _known_to_link_with(NULL) { +ciField::ciField(fieldDescriptor *fd): _known_to_link_with_put(NULL), _known_to_link_with_get(NULL) { ASSERT_IN_VM; _cp_index = -1; @@ -315,6 +315,10 @@ bool ciField::will_link(ciInstanceKlass* accessing_klass, Bytecodes::Code bc) { VM_ENTRY_MARK; + assert(bc == Bytecodes::_getstatic || bc == Bytecodes::_putstatic || + bc == Bytecodes::_getfield || bc == Bytecodes::_putfield, + "unexpected bytecode"); + if (_offset == -1) { // at creation we couldn't link to our holder so we need to // maintain that stance, otherwise there's no safe way to use this @@ -322,8 +326,22 @@ return false; } - if (_known_to_link_with == accessing_klass) { - return true; + // Check for static/nonstatic mismatch + bool is_static = (bc == Bytecodes::_getstatic || bc == Bytecodes::_putstatic); + if (is_static != this->is_static()) { + return false; + } + + // Get and put can have different accessibility rules + bool is_put = (bc == Bytecodes::_putfield || bc == Bytecodes::_putstatic); + if (is_put) { + if (_known_to_link_with_put == accessing_klass) { + return true; + } + } else { + if (_known_to_link_with_get == accessing_klass) { + return true; + } } FieldAccessInfo result; @@ -334,8 +352,13 @@ true, false, KILL_COMPILE_ON_FATAL_(false)); // update the hit-cache, unless there is a problem with memory scoping: - if (accessing_klass->is_shared() || !is_shared()) - _known_to_link_with = accessing_klass; + if (accessing_klass->is_shared() || !is_shared()) { + if (is_put) { + _known_to_link_with_put = accessing_klass; + } else { + _known_to_link_with_get = accessing_klass; + } + } return true; } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 hotspot/src/share/vm/ci/ciField.hpp --- a/hotspot/src/share/vm/ci/ciField.hpp Tue Jun 26 15:28:21 2012 -0700 +++ b/hotspot/src/share/vm/ci/ciField.hpp Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -49,7 +49,8 @@ ciType* _type; int _offset; bool _is_constant; - ciInstanceKlass* _known_to_link_with; + ciInstanceKlass* _known_to_link_with_put; + ciInstanceKlass* _known_to_link_with_get; ciConstant _constant_value; // Used for will_link diff -r 2c1fa96ba3d7 -r a2cf86579ad4 hotspot/src/share/vm/classfile/verifier.cpp --- a/hotspot/src/share/vm/classfile/verifier.cpp Tue Jun 26 15:28:21 2012 -0700 +++ b/hotspot/src/share/vm/classfile/verifier.cpp Tue Jun 26 22:47:23 2012 -0700 @@ -1884,10 +1884,10 @@ VerificationType type = current_frame->pop_stack( VerificationType::reference_check(), CHECK_VERIFY(this)); if (type == VerificationType::uninitialized_this_type()) { - // The method must be an method of either this class, or one of its - // superclasses + // The method must be an method of this class or its superclass + klassOop superk = current_class()->super(); if (ref_class_type.name() != current_class()->name() && - !name_in_supers(ref_class_type.name(), current_class())) { + ref_class_type.name() != superk->klass_part()->name()) { verify_error(bci, "Bad method call"); return; } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 hotspot/src/share/vm/compiler/compilerOracle.cpp --- a/hotspot/src/share/vm/compiler/compilerOracle.cpp Tue Jun 26 15:28:21 2012 -0700 +++ b/hotspot/src/share/vm/compiler/compilerOracle.cpp Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -551,13 +551,21 @@ } static const char* cc_file() { +#ifdef ASSERT if (CompileCommandFile == NULL) return ".hotspot_compiler"; +#endif return CompileCommandFile; } + +bool CompilerOracle::has_command_file() { + return cc_file() != NULL; +} + bool CompilerOracle::_quiet = false; void CompilerOracle::parse_from_file() { + assert(has_command_file(), "command file must be specified"); FILE* stream = fopen(cc_file(), "rt"); if (stream == NULL) return; @@ -600,6 +608,7 @@ } void CompilerOracle::append_comment_to_file(const char* message) { + assert(has_command_file(), "command file must be specified"); fileStream stream(fopen(cc_file(), "at")); stream.print("# "); for (int index = 0; message[index] != '\0'; index++) { @@ -610,6 +619,7 @@ } void CompilerOracle::append_exclude_to_file(methodHandle method) { + assert(has_command_file(), "command file must be specified"); fileStream stream(fopen(cc_file(), "at")); stream.print("exclude "); Klass::cast(method->method_holder())->name()->print_symbol_on(&stream); @@ -624,7 +634,9 @@ void compilerOracle_init() { CompilerOracle::parse_from_string(CompileCommand, CompilerOracle::parse_from_line); CompilerOracle::parse_from_string(CompileOnly, CompilerOracle::parse_compile_only); - CompilerOracle::parse_from_file(); + if (CompilerOracle::has_command_file()) { + CompilerOracle::parse_from_file(); + } if (lists[PrintCommand] != NULL) { if (PrintAssembly) { warning("CompileCommand and/or .hotspot_compiler file contains 'print' commands, but PrintAssembly is also enabled"); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 hotspot/src/share/vm/compiler/compilerOracle.hpp --- a/hotspot/src/share/vm/compiler/compilerOracle.hpp Tue Jun 26 15:28:21 2012 -0700 +++ b/hotspot/src/share/vm/compiler/compilerOracle.hpp Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -36,6 +36,10 @@ static bool _quiet; public: + + // True if the command file has been specified or is implicit + static bool has_command_file(); + // Reads from file and adds to lists static void parse_from_file(); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 hotspot/src/share/vm/opto/runtime.cpp --- a/hotspot/src/share/vm/opto/runtime.cpp Tue Jun 26 15:28:21 2012 -0700 +++ b/hotspot/src/share/vm/opto/runtime.cpp Tue Jun 26 22:47:23 2012 -0700 @@ -896,7 +896,8 @@ methodOop method = ((nmethod*)n)->method(); tty->print_cr("# Method where it happened %s.%s ", Klass::cast(method->method_holder())->name()->as_C_string(), method->name()->as_C_string()); tty->print_cr("#"); - if (ShowMessageBoxOnError && UpdateHotSpotCompilerFileOnError) { + if (ShowMessageBoxOnError && UpdateHotSpotCompilerFileOnError && + CompilerOracle::has_command_file()) { const char* title = "HotSpot Runtime Error"; const char* question = "Do you want to exclude compilation of this method in future runs?"; if (os::message_box(title, question)) { diff -r 2c1fa96ba3d7 -r a2cf86579ad4 hotspot/src/share/vm/runtime/arguments.cpp --- a/hotspot/src/share/vm/runtime/arguments.cpp Tue Jun 26 15:28:21 2012 -0700 +++ b/hotspot/src/share/vm/runtime/arguments.cpp Tue Jun 26 22:47:23 2012 -0700 @@ -3017,12 +3017,14 @@ } } +#ifdef ASSERT // Parse default .hotspotrc settings file if (!settings_file_specified) { if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) { return JNI_EINVAL; } } +#endif if (PrintVMOptions) { for (index = 0; index < args->nOptions; index++) { diff -r 2c1fa96ba3d7 -r a2cf86579ad4 hotspot/test/runtime/7110720/Test7110720.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/test/runtime/7110720/Test7110720.sh Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,122 @@ +# +# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# + + +# +# @test Test7110720.sh +# @bug 7110720 +# @summary improve VM configuration file loading +# @run shell Test7110720.sh +# + +if [ "${TESTSRC}" = "" ] + then TESTSRC=. +fi + +if [ "${TESTJAVA}" = "" ] +then + PARENT=`dirname \`which java\`` + TESTJAVA=`dirname ${PARENT}` + echo "TESTJAVA not set, selecting " ${TESTJAVA} + echo "If this is incorrect, try setting the variable manually." +fi + +if [ "${TESTCLASSES}" = "" ] +then + echo "TESTCLASSES not set. Test cannot execute. Failed." + exit 1 +fi + +# Jtreg sets TESTVMOPTS which may include -d64 which is +# required to test a 64-bit JVM on some platforms. +# If another test harness still creates HOME/JDK64BIT, +# we can recognise that. + +# set platform-dependent variables +OS=`uname -s` +case "$OS" in + SunOS | Linux ) + FS="/" + RM=/bin/rm + CP=/bin/cp + MV=/bin/mv + ## for solaris, linux it's HOME + FILE_LOCATION=$HOME + if [ -f ${FILE_LOCATION}${FS}JDK64BIT -a ${OS} = "SunOS" ] + then + TESTVMOPTS=`cat ${FILE_LOCATION}${FS}JDK64BIT` + fi + ;; + Windows_* ) + FS="\\" + RM=rm + CP=cp + MV=mv + ;; + * ) + echo "Unrecognized system!" + exit 1; + ;; +esac + + +JAVA=${TESTJAVA}${FS}bin${FS}java + +# Don't test debug builds, they do read the config files: +${JAVA} ${TESTVMOPTS} -version 2>&1 | grep "debug" >/dev/null +if [ "$?" = "0" ]; then + echo Skipping test for debug build. + exit 0 +fi + +ok=yes + +$RM -f .hotspot_compiler .hotspotrc + +${JAVA} ${TESTVMOPTS} -version 2>&1 | grep "garbage in" >/dev/null +if [ "$?" = "0" ]; then + echo "FAILED: base case failure" + exit 1 +fi + + +echo "garbage in, garbage out" > .hotspot_compiler +${JAVA} ${TESTVMOPTS} -version 2>&1 | grep "garbage in" >/dev/null +if [ "$?" = "0" ]; then + echo "FAILED: .hotspot_compiler was read" + ok=no +fi + +$MV .hotspot_compiler hs_comp.txt +${JAVA} ${TESTVMOPTS} -XX:CompileCommandFile=hs_comp.txt -version 2>&1 | grep "garbage in" >/dev/null +if [ "$?" = "1" ]; then + echo "FAILED: explicit compiler command file not read" + ok=no +fi + +$RM -f .hotspot_compiler hs_comp.txt + +echo "garbage" > .hotspotrc +${JAVA} ${TESTVMOPTS} -version 2>&1 | grep "garbage" >/dev/null +if [ "$?" = "0" ]; then + echo "FAILED: .hotspotrc was read" + ok=no +fi + +$MV .hotspotrc hs_flags.txt +${JAVA} ${TESTVMOPTS} -XX:Flags=hs_flags.txt -version 2>&1 | grep "garbage" >/dev/null +if [ "$?" = "1" ]; then + echo "FAILED: explicit flags file not read" + ok=no +fi + +if [ "${ok}" = "no" ]; then + echo "Some tests failed." + exit 1 +else + echo "Passed" + exit 0 +fi + diff -r 2c1fa96ba3d7 -r a2cf86579ad4 hotspot/test/runtime/7160757/Test7160757.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/test/runtime/7160757/Test7160757.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 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 Test7160757.java + * @bug 7160757 + * @summary Tests that superclass initialization is not skipped + */ + +public class Test7160757 { + + public static void main(String args[]) throws Exception { + + ClassLoader loader = new SLoader(); + try { + Class.forName("S", true, loader); + System.out.println("FAILED"); + throw new Exception("Should have thrown a VerifyError."); + } catch (VerifyError e) { + System.out.println(e); + System.out.println("PASSED"); + } + } + + static class SLoader extends ClassLoader { + + /** + * public class S extends Throwable { + * public S() { + * aload_0 + * invokespecial Object.() + * return + * } + * } + */ + static byte b(int i) { return (byte)i; } + static byte S_class[] = { + b(0xca), b(0xfe), b(0xba), b(0xbe), 0x00, 0x00, 0x00, 0x32, + 0x00, 0x0c, 0x0a, 0x00, 0x0b, 0x00, 0x07, 0x07, + 0x00, 0x08, 0x07, 0x00, 0x09, 0x01, 0x00, 0x06, + 0x3c, 0x69, 0x6e, 0x69, 0x74, 0x3e, 0x01, 0x00, + 0x03, 0x28, 0x29, 0x56, 0x01, 0x00, 0x04, 0x43, + 0x6f, 0x64, 0x65, 0x0c, 0x00, 0x04, 0x00, 0x05, + 0x01, 0x00, 0x01, 0x53, 0x01, 0x00, 0x13, 0x6a, + 0x61, 0x76, 0x61, 0x2f, 0x6c, 0x61, 0x6e, 0x67, + 0x2f, 0x54, 0x68, 0x72, 0x6f, 0x77, 0x61, 0x62, + 0x6c, 0x65, 0x01, 0x00, 0x10, 0x6a, 0x61, 0x76, + 0x61, 0x2f, 0x6c, 0x61, 0x6e, 0x67, 0x2f, 0x4f, + 0x62, 0x6a, 0x65, 0x63, 0x74, 0x07, 0x00, 0x0a, + 0x00, 0x21, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x04, + 0x00, 0x05, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00, + 0x00, 0x11, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x05, 0x2a, b(0xb7), 0x00, 0x01, b(0xb1), 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + public Class findClass(String name) throws ClassNotFoundException { + return defineClass(name, S_class, 0, S_class.length); + } + } +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jaxp/.hgtags --- a/jaxp/.hgtags Tue Jun 26 15:28:21 2012 -0700 +++ b/jaxp/.hgtags Tue Jun 26 22:47:23 2012 -0700 @@ -165,3 +165,4 @@ 6f5c0e17415de7a9c74900ef4ba12f47accdf88b jdk8-b41 39ee03c1602155ff02e5feb6cd44869452f24cf7 jdk8-b42 eff4ece9c8bc43b3ce2b3758574c4c20147f0689 jdk8-b43 +0b3f3a4ce13930430b32b616a717dfc7fe385b28 jdk8-b44 diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLScanner.java --- a/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLScanner.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLScanner.java Tue Jun 26 22:47:23 2012 -0700 @@ -402,6 +402,16 @@ boolean dataFoundForTarget = false; boolean sawSpace = fEntityScanner.skipSpaces(); + // since pseudoattributes are *not* attributes, + // their quotes don't need to be preserved in external parameter entities. + // the XMLEntityScanner#scanLiteral method will continue to + // emit -1 in such cases when it finds a quote; this is + // fine for other methods that parse scanned entities, + // but not for the scanning of pseudoattributes. So, + // temporarily, we must mark the current entity as not being "literal" + Entity.ScannedEntity currEnt = fEntityManager.getCurrentEntity(); + boolean currLiteral = currEnt.literal; + currEnt.literal = false; while (fEntityScanner.peekChar() != '?') { dataFoundForTarget = true; String name = scanPseudoAttribute(scanningTextDecl, fString); @@ -499,6 +509,9 @@ } sawSpace = fEntityScanner.skipSpaces(); } + // restore original literal value + if(currLiteral) + currEnt.literal = true; // REVISIT: should we remove this error reporting? if (scanningTextDecl && state != STATE_DONE) { reportFatalError("MorePseudoAttributes", null); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jaxws/.hgtags --- a/jaxws/.hgtags Tue Jun 26 15:28:21 2012 -0700 +++ b/jaxws/.hgtags Tue Jun 26 22:47:23 2012 -0700 @@ -165,3 +165,4 @@ f2072b164b0519227833a2994f78e3988ee67827 jdk8-b41 1f20f37818a91b66eaeba268d0b785718598ee0e jdk8-b42 f00c12994562c2f68d348a7c3e829374a89294e2 jdk8-b43 +f6a417540ef124c9b4123d07da5e26f2ab909949 jdk8-b44 diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/.hgtags --- a/jdk/.hgtags Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/.hgtags Tue Jun 26 22:47:23 2012 -0700 @@ -165,3 +165,4 @@ 4eac56f073ea8179b1a35fcd2af9b48b0088be9f jdk8-b41 cf5c1f6fbc5ba14163fe0ef8eb8601b33f951372 jdk8-b42 b3246687c3695dff6f461bb407f9db88f7d072e7 jdk8-b43 +db471a7af03168e4441c245b1d9976f720a7cb77 jdk8-b44 diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/make/com/oracle/net/Makefile diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/make/com/sun/jmx/Makefile --- a/jdk/make/com/sun/jmx/Makefile Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/make/com/sun/jmx/Makefile Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ # -# Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2003, 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 @@ -100,6 +100,23 @@ # so that *_tie classes are generated in package without the prefix # org.omg.stub (6375696) # +# To ensure the latest stub generator files are picked up from corba repo +# when available, we need to run with latest rmic version available. rmic +# launch tool not built at this stage but we can invoke via rmi class. + +RMIC_JAVA = $(OUTPUTDIR)/bin/java +# need to treat 64bit solaris differently +ifeq ($(PLATFORM)-$(LIBARCH), solaris-amd64) +RMIC_JAVA = $(OUTPUTDIR)/bin/amd64/java +endif +ifeq ($(PLATFORM)-$(LIBARCH), solaris-sparcv9) +RMIC_JAVA = $(OUTPUTDIR)/bin/sparcv9/java +endif + +ifeq ($(CROSS_COMPILE_ARCH),) +RMIC = $(RMIC_JAVA) $(JAVA_TOOLS_FLAGS) -cp $(OUTPUTDIR)/classes sun.rmi.rmic.Main +endif + $(CLASSDESTDIR)/%_Stub.class: $(CLASSDESTDIR)/%.class $(prep-target) $(RMIC) -classpath "$(CLASSDESTDIR)" \ diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/make/common/Defs-embedded.gmk --- a/jdk/make/common/Defs-embedded.gmk Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/make/common/Defs-embedded.gmk Tue Jun 26 22:47:23 2012 -0700 @@ -42,7 +42,7 @@ OTHER_CPPFLAGS += -DJAVASE_EMBEDDED # Product naming -PRODUCT_SUFFIX = SE Runtime Environment for Embedded +PRODUCT_SUFFIX = SE Embedded Runtime Environment RUNTIME_NAME = $(PRODUCT_NAME) $(PRODUCT_SUFFIX) # Reduced JRE locations diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/make/java/java/FILES_java.gmk --- a/jdk/make/java/java/FILES_java.gmk Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/make/java/java/FILES_java.gmk Tue Jun 26 22:47:23 2012 -0700 @@ -372,6 +372,7 @@ java/util/spi/CurrencyNameProvider.java \ java/util/spi/LocaleNameProvider.java \ java/util/spi/LocaleServiceProvider.java \ + java/util/spi/ResourceBundleControlProvider.java \ java/util/spi/TimeZoneNameProvider.java \ java/io/Closeable.java \ java/io/Flushable.java \ diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/make/java/nio/mapfile-linux --- a/jdk/make/java/nio/mapfile-linux Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/make/java/nio/mapfile-linux Tue Jun 26 22:47:23 2012 -0700 @@ -88,6 +88,7 @@ Java_sun_nio_ch_IOUtil_fdVal; Java_sun_nio_ch_IOUtil_fdLimit; Java_sun_nio_ch_IOUtil_initIDs; + Java_sun_nio_ch_IOUtil_iovMax; Java_sun_nio_ch_IOUtil_makePipe; Java_sun_nio_ch_IOUtil_randomBytes; Java_sun_nio_ch_IOUtil_setfdVal; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/make/java/nio/mapfile-solaris --- a/jdk/make/java/nio/mapfile-solaris Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/make/java/nio/mapfile-solaris Tue Jun 26 22:47:23 2012 -0700 @@ -76,6 +76,7 @@ Java_sun_nio_ch_IOUtil_fdLimit; Java_sun_nio_ch_IOUtil_fdVal; Java_sun_nio_ch_IOUtil_initIDs; + Java_sun_nio_ch_IOUtil_iovMax; Java_sun_nio_ch_IOUtil_makePipe; Java_sun_nio_ch_IOUtil_randomBytes; Java_sun_nio_ch_IOUtil_setfdVal; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/make/sun/rmi/rmi/mapfile-vers diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/macosx/classes/apple/applescript/AppleScriptEngine.java --- a/jdk/src/macosx/classes/apple/applescript/AppleScriptEngine.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/macosx/classes/apple/applescript/AppleScriptEngine.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -26,6 +26,7 @@ package apple.applescript; import java.io.*; +import java.nio.file.Files; import java.util.*; import java.util.Map.Entry; @@ -297,7 +298,7 @@ File tmpfile; FileWriter tmpwrite; try { - tmpfile = File.createTempFile("AppleScriptEngine.", ".scpt"); + tmpfile = Files.createTempFile("AppleScriptEngine.", ".scpt").toFile(); tmpwrite = new FileWriter(tmpfile); // read in our input and write directly to tmpfile diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Tue Jun 26 22:47:23 2012 -0700 @@ -63,6 +63,7 @@ private static native void nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY); private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled); private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr); + private static native void nativeDispose(long nsWindowPtr); private static native int nativeGetNSWindowDisplayID_AppKitThread(long nsWindowPtr); @@ -423,6 +424,7 @@ EventQueue.invokeLater(new Runnable() { public void run() { contentView.dispose(); + nativeDispose(getNSWindowPtr()); CPlatformWindow.super.dispose(); } }); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java Tue Jun 26 22:47:23 2012 -0700 @@ -41,10 +41,11 @@ } public void enter() { - toolkit.startNativeNestedEventLoop(); + // Execute the next AppKit event while we are waiting for system to + // finish our request - this will save us from biting our own tail + toolkit.executeNextAppKitEvent(); } public void exit() { - toolkit.stopNativeNestedEventLoop(); } } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Tue Jun 26 22:47:23 2012 -0700 @@ -63,9 +63,7 @@ private static native void initIDs(); - static native void startNativeNestedEventLoop(); - - static native void stopNativeNestedEventLoop(); + static native void executeNextAppKitEvent(); private static CInputMethodDescriptor sInputMethodDescriptor; @@ -361,9 +359,11 @@ CWrapper.NSObject.release(screen); } // Convert between Cocoa's coordinate system and Java. - return new Insets(fullScreen.height - workArea.height - workArea.y, - workArea.x, workArea.y, - fullScreen.width - workArea.width - workArea.x); + int bottom = workArea.y - fullScreen.y; + int top = fullScreen.height - workArea.height - bottom; + int left = workArea.x - fullScreen.x; + int right = fullScreen.width - workArea.width - left; + return new Insets(top, left, bottom, right); } @Override diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/macosx/native/sun/awt/AWTView.m --- a/jdk/src/macosx/native/sun/awt/AWTView.m Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/macosx/native/sun/awt/AWTView.m Tue Jun 26 22:47:23 2012 -0700 @@ -188,7 +188,9 @@ #endif } } else { +#if IM_DEBUG NSLog(@"-> IM does not want to handle event"); +#endif [self deliverJavaMouseEvent: event]; } } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/macosx/native/sun/awt/AWTWindow.m --- a/jdk/src/macosx/native/sun/awt/AWTWindow.m Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/macosx/native/sun/awt/AWTWindow.m Tue Jun 26 22:47:23 2012 -0700 @@ -228,6 +228,7 @@ } if (self.nsWindow == nil) return nil; // no hope either + [self.nsWindow release]; // the property retains the object already self.isEnabled = YES; self.javaPlatformWindow = platformWindow; @@ -677,9 +678,9 @@ styleBits:styleBits frameRect:frameRect contentView:contentView]; + // the window is released is CPlatformWindow.nativeDispose() - if (window) CFRetain(window); - [window release]; // GC + if (window) CFRetain(window.nsWindow); }]; JNF_COCOA_EXIT(env); @@ -1160,3 +1161,24 @@ JNF_COCOA_EXIT(env); } +JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeDispose +(JNIEnv *env, jclass clazz, jlong windowPtr) +{ +JNF_COCOA_ENTER(env); + + NSWindow *nsWindow = OBJC(windowPtr); + [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ + AWTWindow *window = (AWTWindow*)[nsWindow delegate]; + + // AWTWindow holds a reference to the NSWindow in its nsWindow + // property. Unsetting the delegate allows it to be deallocated + // which releases the reference. This, in turn, allows the window + // itself be deallocated. + [nsWindow setDelegate: nil]; + + [window release]; + }]; + +JNF_COCOA_EXIT(env); +} + diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/macosx/native/sun/awt/LWCToolkit.m --- a/jdk/src/macosx/native/sun/awt/LWCToolkit.m Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.m Tue Jun 26 22:47:23 2012 -0700 @@ -42,7 +42,6 @@ @implementation AWTToolkit static long eventCount; -static bool shouldKeepRunningNestedLoop = NO; + (long) getEventCount{ return eventCount; @@ -460,33 +459,18 @@ /* * Class: sun_lwawt_macosx_LWCToolkit - * Method: startNativeNestedEventLoop + * Method: executeNextAppKitEvent * Signature: ()V */ -JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_startNativeNestedEventLoop +JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_executeNextAppKitEvent (JNIEnv *env, jclass cls) { - if(!shouldKeepRunningNestedLoop) { - NSRunLoop *theRL = [NSRunLoop currentRunLoop]; - NSApplication * app = [NSApplication sharedApplication]; - shouldKeepRunningNestedLoop = YES; - while (shouldKeepRunningNestedLoop && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) - { - NSEvent * event = [app nextEventMatchingMask: 0xFFFFFFFF untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES]; - if (event != nil) { - [app sendEvent: event]; - } - } + // Simply get the next event in native loop and pass it to execution + // We'll be called repeatedly so there's no need to block here + NSRunLoop *theRL = [NSRunLoop currentRunLoop]; + NSApplication * app = [NSApplication sharedApplication]; + NSEvent * event = [app nextEventMatchingMask: 0xFFFFFFFF untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES]; + if (event != nil) { + [app sendEvent: event]; } } - -/* - * Class: sun_lwawt_macosx_LWCToolkit - * Method: stopNativeNestedEventLoop - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopNativeNestedEventLoop -(JNIEnv *env, jclass cls) -{ - shouldKeepRunningNestedLoop = NO; -} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m --- a/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m Tue Jun 26 22:47:23 2012 -0700 @@ -63,12 +63,14 @@ CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo; if (ctxinfo != NULL) { + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; [NSOpenGLContext clearCurrentContext]; [ctxinfo->context clearDrawable]; [ctxinfo->context release]; if (ctxinfo->scratchSurface != 0) { [ctxinfo->scratchSurface release]; } + [pool drain]; free(ctxinfo); } } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.h --- a/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.h Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.h Tue Jun 26 22:47:23 2012 -0700 @@ -30,6 +30,8 @@ BOOL fHandlesDocumentTypes; BOOL fHandlesURLTypes; + id realDelegate; + NSMutableArray* queue; } @@ -40,5 +42,9 @@ - (void)processQueuedEventsWithTargetDelegate:(id )delegate; +@property(retain) id realDelegate; + +@property(retain) NSMutableArray* queue; + @end diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.m --- a/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.m Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.m Tue Jun 26 22:47:23 2012 -0700 @@ -27,8 +27,6 @@ #import "QueuingApplicationDelegate.h" -static id realDelegate = nil; - @interface NSBundle (EAWTOverrides) - (BOOL)_hasEAWTOverride:(NSString *)key; @end @@ -44,6 +42,9 @@ @implementation QueuingApplicationDelegate +@synthesize realDelegate; +@synthesize queue; + + (QueuingApplicationDelegate*) sharedDelegate { static QueuingApplicationDelegate * qad = nil; @@ -62,7 +63,7 @@ return self; } - self->queue = [[NSMutableArray arrayWithCapacity: 0] retain]; + self.queue = [NSMutableArray arrayWithCapacity: 0]; // If the java application has a bundle with an Info.plist file with // a CFBundleDocumentTypes entry, then it is set up to handle Open Doc @@ -100,8 +101,8 @@ Class clz = [QueuingApplicationDelegate class]; [ctr removeObserver:clz]; - [self->queue release]; - self->queue = nil; + self.queue = nil; + self.realDelegate = nil; [super dealloc]; } @@ -109,16 +110,16 @@ - (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEvent:(NSAppleEventDescriptor *)replyEvent { - [self->queue addObject:^(){ - [realDelegate _handleOpenURLEvent:openURLEvent withReplyEvent:replyEvent]; - }]; + [self.queue addObject:[^(){ + [self.realDelegate _handleOpenURLEvent:openURLEvent withReplyEvent:replyEvent]; + } copy]]; } - (void)application:(NSApplication *)theApplication openFiles:(NSArray *)fileNames { - [self->queue addObject:^(){ - [realDelegate application:theApplication openFiles:fileNames]; - }]; + [self.queue addObject:[^(){ + [self.realDelegate application:theApplication openFiles:fileNames]; + } copy]]; } - (NSApplicationPrintReply)application:(NSApplication *)application printFiles:(NSArray *)fileNames withSettings:(NSDictionary *)printSettings showPrintPanels:(BOOL)showPrintPanels @@ -127,9 +128,9 @@ return NSPrintingCancelled; } - [self->queue addObject:^(){ - [realDelegate application:application printFiles:fileNames withSettings:printSettings showPrintPanels:showPrintPanels]; - }]; + [self.queue addObject:[^(){ + [self.realDelegate application:application printFiles:fileNames withSettings:printSettings showPrintPanels:showPrintPanels]; + } copy]]; // well, a bit premature, but what else can we do?.. return NSPrintingSuccess; @@ -137,76 +138,76 @@ - (void)_willFinishLaunching { - QueuingApplicationDelegate * q = self; - [self->queue addObject:^(){ - [[realDelegate class] _willFinishLaunching]; - }]; + [self.queue addObject:[^(){ + [[self.realDelegate class] _willFinishLaunching]; + } copy]]; } - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag { - [self->queue addObject:^(){ - [realDelegate applicationShouldHandleReopen:theApplication hasVisibleWindows:flag]; - }]; + [self.queue addObject:[^(){ + [self.realDelegate applicationShouldHandleReopen:theApplication hasVisibleWindows:flag]; + } copy]]; return YES; } - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app { - [self->queue addObject:^(){ - [realDelegate applicationShouldTerminate:app]; - }]; + [self.queue addObject:[^(){ + [self.realDelegate applicationShouldTerminate:app]; + } copy]]; return NSTerminateLater; } - (void)_systemWillPowerOff { - [self->queue addObject:^(){ - [[realDelegate class] _systemWillPowerOff]; - }]; + [self.queue addObject:[^(){ + [[self.realDelegate class] _systemWillPowerOff]; + } copy]]; } - (void)_appDidActivate { - [self->queue addObject:^(){ - [[realDelegate class] _appDidActivate]; - }]; + [self.queue addObject:[^(){ + [[self.realDelegate class] _appDidActivate]; + } copy]]; } - (void)_appDidDeactivate { - [self->queue addObject:^(){ - [[realDelegate class] _appDidDeactivate]; - }]; + [self.queue addObject:[^(){ + [[self.realDelegate class] _appDidDeactivate]; + } copy]]; } - (void)_appDidHide { - [self->queue addObject:^(){ - [[realDelegate class] _appDidHide]; - }]; + [self.queue addObject:[^(){ + [[self.realDelegate class] _appDidHide]; + } copy]]; } - (void)_appDidUnhide { - [self->queue addObject:^(){ - [[realDelegate class] _appDidUnhide]; - }]; + [self.queue addObject:[^(){ + [[self.realDelegate class] _appDidUnhide]; + } copy]]; } - (void)processQueuedEventsWithTargetDelegate:(id )delegate { + self.realDelegate = delegate; + NSUInteger i; - NSUInteger count = [self->queue count]; - - realDelegate = delegate; + NSUInteger count = [self.queue count]; for (i = 0; i < count; i++) { - void (^event)() = (void (^)())[self->queue objectAtIndex: i]; + void (^event)() = (void (^)())[self.queue objectAtIndex: i]; event(); + [event release]; } - [self->queue removeAllObjects]; + [self.queue removeAllObjects]; } @end diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java --- a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java Tue Jun 26 22:47:23 2012 -0700 @@ -926,9 +926,20 @@ int x, int y, int w, int h) { // Text is odd in that it uses the TEXT_BACKGROUND vs BACKGROUND. JComponent c = context.getComponent(); + Container container = c.getParent(); + Container containerParent = null; GTKStyle style = (GTKStyle)context.getStyle(); Region id = context.getRegion(); int state = context.getComponentState(); + + if (c instanceof ListCellRenderer && container != null) { + containerParent = container.getParent(); + if (containerParent instanceof JComboBox + && containerParent.hasFocus()) { + state |= SynthConstants.FOCUSED; + } + } + synchronized (UNIXToolkit.GTK_LOCK) { if (ENGINE.paintCachedImage(g, x, y, w, h, id, state)) { return; @@ -938,9 +949,10 @@ int focusSize = 0; boolean interiorFocus = style.getClassSpecificBoolValue( context, "interior-focus", true); + + focusSize = style.getClassSpecificIntValue(context, + "focus-line-width",1); if (!interiorFocus && (state & SynthConstants.FOCUSED) != 0) { - focusSize = style.getClassSpecificIntValue(context, - "focus-line-width",1); x += focusSize; y += focusSize; w -= 2 * focusSize; @@ -961,11 +973,25 @@ h - (2 * yThickness), ColorType.TEXT_BACKGROUND); - if (focusSize > 0) { - x -= focusSize; - y -= focusSize; - w += 2 * focusSize; - h += 2 * focusSize; + if (focusSize > 0 && (state & SynthConstants.FOCUSED) != 0) { + if (!interiorFocus) { + x -= focusSize; + y -= focusSize; + w += 2 * focusSize; + h += 2 * focusSize; + } else { + if (containerParent instanceof JComboBox) { + x += (focusSize + 2); + y += (focusSize + 1); + w -= (2 * focusSize + 1); + h -= (2 * focusSize + 2); + } else { + x += focusSize; + y += focusSize; + w -= 2 * focusSize; + h -= 2 * focusSize; + } + } ENGINE.paintFocus(g, context, id, gtkState, "entry", x, y, w, h); } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java --- a/jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -35,6 +35,7 @@ import java.io.OutputStream; import java.io.PrintStream; import java.text.MessageFormat; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -385,9 +386,7 @@ if ( base.getParentFile() == null && suffix.equals(".bak")) where = new File(".").getAbsoluteFile(); - - File f = File.createTempFile(prefix, suffix, where); - return f; + return Files.createTempFile(where.toPath(), prefix, suffix).toFile(); } static private diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/com/sun/rowset/CachedRowSetImpl.java --- a/jdk/src/share/classes/com/sun/rowset/CachedRowSetImpl.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/com/sun/rowset/CachedRowSetImpl.java Tue Jun 26 22:47:23 2012 -0700 @@ -659,7 +659,7 @@ * us work with drivers that do not support * getObject with a map in fairly sensible way */ - if (map == null) { + if (map == null || map.isEmpty()) { obj = data.getObject(i); } else { obj = data.getObject(i, map); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java --- a/jdk/src/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -812,101 +812,119 @@ } } - /** - * Inserts a row that has been inserted into the given - * CachedRowSet object into the data source from which - * the rowset is derived, returning false if the insertion - * was successful. - * - * @param crs the CachedRowSet object that has had a row inserted - * and to whose underlying data source the row will be inserted - * @param pstmt the PreparedStatement object that will be used - * to execute the insertion - * @return false to indicate that the insertion was successful; - * true otherwise - * @throws SQLException if a database access error occurs - */ - private boolean insertNewRow(CachedRowSet crs, - PreparedStatement pstmt, CachedRowSetImpl crsRes) throws SQLException { - int i = 0; - int icolCount = crs.getMetaData().getColumnCount(); + /** + * Inserts a row that has been inserted into the given + * CachedRowSet object into the data source from which + * the rowset is derived, returning false if the insertion + * was successful. + * + * @param crs the CachedRowSet object that has had a row inserted + * and to whose underlying data source the row will be inserted + * @param pstmt the PreparedStatement object that will be used + * to execute the insertion + * @return false to indicate that the insertion was successful; + * true otherwise + * @throws SQLException if a database access error occurs + */ + private boolean insertNewRow(CachedRowSet crs, + PreparedStatement pstmt, CachedRowSetImpl crsRes) throws SQLException { + + boolean returnVal = false; - boolean returnVal = false; - PreparedStatement pstmtSel = con.prepareStatement(selectCmd, - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); - ResultSet rs, rs2 = null; - DatabaseMetaData dbmd = con.getMetaData(); - rs = pstmtSel.executeQuery(); - String table = crs.getTableName(); - rs2 = dbmd.getPrimaryKeys(null, null, table); - String [] primaryKeys = new String[icolCount]; - int k = 0; - while(rs2.next()) { - String pkcolname = rs2.getString("COLUMN_NAME"); - primaryKeys[k] = pkcolname; - k++; - } + try (PreparedStatement pstmtSel = con.prepareStatement(selectCmd, + ResultSet.TYPE_SCROLL_SENSITIVE, + ResultSet.CONCUR_READ_ONLY); + ResultSet rs = pstmtSel.executeQuery(); + ResultSet rs2 = con.getMetaData().getPrimaryKeys(null, null, + crs.getTableName()) + ) { + + ResultSetMetaData rsmd = crs.getMetaData(); + int icolCount = rsmd.getColumnCount(); + String[] primaryKeys = new String[icolCount]; + int k = 0; + while (rs2.next()) { + primaryKeys[k] = rs2.getString("COLUMN_NAME"); + k++; + } + + if (rs.next()) { + for (String pkName : primaryKeys) { + if (!isPKNameValid(pkName, rsmd)) { + + /* We came here as one of the the primary keys + * of the table is not present in the cached + * rowset object, it should be an autoincrement column + * and not included while creating CachedRowSet + * Object, proceed to check for other primary keys + */ + continue; + } - if(rs.next()) { - for(int j=0;j() { public File run() throws IOException { - return File.createTempFile("+~JF", ".tmp", null); + return Files.createTempFile("+~JF", ".tmp").toFile(); } } ); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/java/io/SerialCallbackContext.java --- a/jdk/src/share/classes/java/io/SerialCallbackContext.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/java/io/SerialCallbackContext.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,54 +1,74 @@ - /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. - * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. - */ - - package java.io; +/* + * 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. 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. + */ - /** - * Context during upcalls from object stream to class-defined - * readObject/writeObject methods. - * Holds object currently being deserialized and descriptor for current class. - * - * This context keeps track of the thread it was constructed on, and allows - * only a single call of defaultReadObject, readFields, defaultWriteObject - * or writeFields which must be invoked on the same thread before the class's - * readObject/writeObject method has returned. - * If not set to the current thread, the getObj method throws NotActiveException. - */ - final class SerialCallbackContext { - private final Object obj; - private final ObjectStreamClass desc; - /** - * Thread this context is in use by. - * As this only works in one thread, we do not need to worry about thread-safety. - */ - private Thread thread; +package java.io; - public SerialCallbackContext(Object obj, ObjectStreamClass desc) { - this.obj = obj; - this.desc = desc; - this.thread = Thread.currentThread(); - } - - public Object getObj() throws NotActiveException { - checkAndSetUsed(); - return obj; - } +/** + * Context during upcalls from object stream to class-defined + * readObject/writeObject methods. + * Holds object currently being deserialized and descriptor for current class. + * + * This context keeps track of the thread it was constructed on, and allows + * only a single call of defaultReadObject, readFields, defaultWriteObject + * or writeFields which must be invoked on the same thread before the class's + * readObject/writeObject method has returned. + * If not set to the current thread, the getObj method throws NotActiveException. + */ +final class SerialCallbackContext { + private final Object obj; + private final ObjectStreamClass desc; + /** + * Thread this context is in use by. + * As this only works in one thread, we do not need to worry about thread-safety. + */ + private Thread thread; - public ObjectStreamClass getDesc() { - return desc; - } + public SerialCallbackContext(Object obj, ObjectStreamClass desc) { + this.obj = obj; + this.desc = desc; + this.thread = Thread.currentThread(); + } + + public Object getObj() throws NotActiveException { + checkAndSetUsed(); + return obj; + } - private void checkAndSetUsed() throws NotActiveException { - if (thread != Thread.currentThread()) { - throw new NotActiveException( - "not in readObject invocation or fields already read"); - } - thread = null; - } + public ObjectStreamClass getDesc() { + return desc; + } - public void setUsed() { - thread = null; - } - } + private void checkAndSetUsed() throws NotActiveException { + if (thread != Thread.currentThread()) { + throw new NotActiveException( + "not in readObject invocation or fields already read"); + } + thread = null; + } + + public void setUsed() { + thread = null; + } +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/java/lang/invoke/MethodHandles.java --- a/jdk/src/share/classes/java/lang/invoke/MethodHandles.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/java/lang/invoke/MethodHandles.java Tue Jun 26 22:47:23 2012 -0700 @@ -407,7 +407,7 @@ * an access$N method. */ Lookup() { - this(getCallerClassAtEntryPoint(), ALL_MODES); + this(getCallerClassAtEntryPoint(false), ALL_MODES); // make sure we haven't accidentally picked up a privileged class: checkUnprivilegedlookupClass(lookupClass); } @@ -461,8 +461,8 @@ && !VerifyAccess.isSamePackageMember(this.lookupClass, requestedLookupClass)) { newModes &= ~PRIVATE; } - if (newModes == PUBLIC - && !VerifyAccess.isClassAccessible(requestedLookupClass, this.lookupClass)) { + if ((newModes & PUBLIC) != 0 + && !VerifyAccess.isClassAccessible(requestedLookupClass, this.lookupClass, allowedModes)) { // The requested class it not accessible from the lookup class. // No permissions. newModes = 0; @@ -540,13 +540,17 @@ } } - // call this from an entry point method in Lookup with extraFrames=0. - private static Class getCallerClassAtEntryPoint() { + /* Obtain the external caller class, when called from Lookup. or a first-level subroutine. */ + private static Class getCallerClassAtEntryPoint(boolean inSubroutine) { final int CALLER_DEPTH = 4; + // Stack for the constructor entry point (inSubroutine=false): // 0: Reflection.getCC, 1: getCallerClassAtEntryPoint, // 2: Lookup., 3: MethodHandles.*, 4: caller + // The stack is slightly different for a subroutine of a Lookup.find* method: + // 2: Lookup.*, 3: Lookup.find*.*, 4: caller // Note: This should be the only use of getCallerClass in this file. - assert(Reflection.getCallerClass(CALLER_DEPTH-1) == MethodHandles.class); + assert(Reflection.getCallerClass(CALLER_DEPTH-2) == Lookup.class); + assert(Reflection.getCallerClass(CALLER_DEPTH-1) == (inSubroutine ? Lookup.class : MethodHandles.class)); return Reflection.getCallerClass(CALLER_DEPTH); } @@ -1087,7 +1091,7 @@ void checkSymbolicClass(Class refc) throws IllegalAccessException { Class caller = lookupClassOrNull(); - if (caller != null && !VerifyAccess.isClassAccessible(refc, caller)) + if (caller != null && !VerifyAccess.isClassAccessible(refc, caller, allowedModes)) throw new MemberName(refc).makeAccessException("symbolic reference class is not public", this); } @@ -1102,7 +1106,13 @@ // Step 1: smgr.checkMemberAccess(refc, Member.PUBLIC); // Step 2: - if (!VerifyAccess.classLoaderIsAncestor(lookupClass, refc)) + Class callerClass = ((allowedModes & PRIVATE) != 0 + ? lookupClass // for strong access modes, no extra check + // next line does stack walk magic; do not refactor: + : getCallerClassAtEntryPoint(true)); + if (!VerifyAccess.classLoaderIsAncestor(lookupClass, refc) || + (callerClass != lookupClass && + !VerifyAccess.classLoaderIsAncestor(callerClass, refc))) smgr.checkPackageAccess(VerifyAccess.getPackageName(refc)); // Step 3: if (m.isPublic()) return; @@ -1153,9 +1163,10 @@ int requestedModes = fixmods(mods); // adjust 0 => PACKAGE if ((requestedModes & allowedModes) != 0 && VerifyAccess.isMemberAccessible(refc, m.getDeclaringClass(), - mods, lookupClass())) + mods, lookupClass(), allowedModes)) return; if (((requestedModes & ~allowedModes) & PROTECTED) != 0 + && (allowedModes & PACKAGE) != 0 && VerifyAccess.isSamePackage(m.getDeclaringClass(), lookupClass())) // Protected members can also be checked as if they were package-private. return; @@ -1170,9 +1181,9 @@ (defc == refc || Modifier.isPublic(refc.getModifiers()))); if (!classOK && (allowedModes & PACKAGE) != 0) { - classOK = (VerifyAccess.isClassAccessible(defc, lookupClass()) && + classOK = (VerifyAccess.isClassAccessible(defc, lookupClass(), ALL_MODES) && (defc == refc || - VerifyAccess.isClassAccessible(refc, lookupClass()))); + VerifyAccess.isClassAccessible(refc, lookupClass(), ALL_MODES))); } if (!classOK) return "class is not public"; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/java/util/HashMap.java --- a/jdk/src/share/classes/java/util/HashMap.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/java/util/HashMap.java Tue Jun 26 22:47:23 2012 -0700 @@ -288,12 +288,11 @@ * in lower bits. */ final int hash(Object k) { - int h = hashSeed; if (k instanceof String) { - return ((String)k).hash32(); + return ((String) k).hash32(); } - h ^= k.hashCode(); + int h = hashSeed ^ k.hashCode(); // This function ensures that hashCodes that differ only by // constant multiples at each bit position have a bounded diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/java/util/Hashtable.java --- a/jdk/src/share/classes/java/util/Hashtable.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/java/util/Hashtable.java Tue Jun 26 22:47:23 2012 -0700 @@ -194,19 +194,17 @@ transient final int hashSeed = sun.misc.Hashing.randomHashSeed(this); private int hash(Object k) { - int h = hashSeed; - if (k instanceof String) { return ((String)k).hash32(); - } else { - h ^= k.hashCode(); + } + + int h = hashSeed ^ k.hashCode(); - // This function ensures that hashCodes that differ only by - // constant multiples at each bit position have a bounded - // number of collisions (approximately 8 at default load factor). - h ^= (h >>> 20) ^ (h >>> 12); - return h ^ (h >>> 7) ^ (h >>> 4); - } + // This function ensures that hashCodes that differ only by + // constant multiples at each bit position have a bounded + // number of collisions (approximately 8 at default load factor). + h ^= (h >>> 20) ^ (h >>> 12); + return h ^ (h >>> 7) ^ (h >>> 4); } /** @@ -1015,7 +1013,7 @@ */ private static class Entry implements Map.Entry { final int hash; - K key; + final K key; V value; Entry next; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/java/util/ResourceBundle.java --- a/jdk/src/share/classes/java/util/ResourceBundle.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/java/util/ResourceBundle.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -55,6 +55,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.jar.JarEntry; +import java.util.spi.ResourceBundleControlProvider; import sun.util.locale.BaseLocale; import sun.util.locale.LocaleObjectCache; @@ -192,6 +193,17 @@ * {@link #getBundle(String, Locale, ClassLoader, Control) getBundle} * factory method for details. * + *

For the {@code getBundle} factory + * methods that take no {@link Control} instance, their default behavior of resource bundle loading + * can be modified with installed {@link + * ResourceBundleControlProvider} implementations. Any installed providers are + * detected at the {@code ResourceBundle} class loading time. If any of the + * providers provides a {@link Control} for the given base name, that {@link + * Control} will be used instead of the default {@link Control}. If there is + * more than one service provider installed for supporting the same base name, + * the first one returned from {@link ServiceLoader} will be used. + * *

Cache Management

* * Resource bundle instances created by the getBundle factory @@ -294,8 +306,7 @@ /** * Queue for reference objects referring to class loaders or bundles. */ - private static final ReferenceQueue referenceQueue = - new ReferenceQueue<>(); + private static final ReferenceQueue referenceQueue = new ReferenceQueue<>(); /** * The parent bundle of this bundle. @@ -330,6 +341,21 @@ */ private volatile Set keySet; + private static final List providers; + + static { + List list = null; + ServiceLoader serviceLoaders + = ServiceLoader.loadInstalled(ResourceBundleControlProvider.class); + for (ResourceBundleControlProvider provider : serviceLoaders) { + if (list == null) { + list = new ArrayList<>(); + } + list.add(provider); + } + providers = list; + } + /** * Sole constructor. (For invocation by subclass constructors, typically * implicit.) @@ -725,7 +751,7 @@ return getBundleImpl(baseName, Locale.getDefault(), /* must determine loader here, else we break stack invariant */ getLoader(), - Control.INSTANCE); + getDefaultControl(baseName)); } /** @@ -797,7 +823,7 @@ return getBundleImpl(baseName, locale, /* must determine loader here, else we break stack invariant */ getLoader(), - Control.INSTANCE); + getDefaultControl(baseName)); } /** @@ -849,9 +875,15 @@ * Gets a resource bundle using the specified base name, locale, and class * loader. * - *

This method behaves the same as calling + *

This method behaves the same as calling * {@link #getBundle(String, Locale, ClassLoader, Control)} passing a - * default instance of {@link Control}. The following describes this behavior. + * default instance of {@link Control} unless another {@link Control} is + * provided with the {@link ResourceBundleControlProvider} SPI. Refer to the + * description of modifying the default + * behavior. + * + *

The following describes the default + * behavior. * *

getBundle uses the base name, the specified locale, and * the default locale (obtained from {@link java.util.Locale#getDefault() @@ -1026,7 +1058,7 @@ if (loader == null) { throw new NullPointerException(); } - return getBundleImpl(baseName, locale, loader, Control.INSTANCE); + return getBundleImpl(baseName, locale, loader, getDefaultControl(baseName)); } /** @@ -1247,6 +1279,18 @@ return getBundleImpl(baseName, targetLocale, loader, control); } + private static Control getDefaultControl(String baseName) { + if (providers != null) { + for (ResourceBundleControlProvider provider : providers) { + Control control = provider.getControl(baseName); + if (control != null) { + return control; + } + } + } + return Control.INSTANCE; + } + private static ResourceBundle getBundleImpl(String baseName, Locale locale, ClassLoader loader, Control control) { if (locale == null || control == null) { diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/java/util/WeakHashMap.java --- a/jdk/src/share/classes/java/util/WeakHashMap.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/java/util/WeakHashMap.java Tue Jun 26 22:47:23 2012 -0700 @@ -295,13 +295,11 @@ * otherwise encounter collisions for hashCodes that do not differ * in lower bits. */ - int hash(Object k) { - int h = hashSeed; + final int hash(Object k) { if (k instanceof String) { return ((String) k).hash32(); - } else { - h ^= k.hashCode(); } + int h = hashSeed ^ k.hashCode(); // This function ensures that hashCodes that differ only by // constant multiples at each bit position have a bounded diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java --- a/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java Tue Jun 26 22:47:23 2012 -0700 @@ -269,13 +269,11 @@ * differ in lower or upper bits. */ private int hash(Object k) { - int h = hashSeed; - if (k instanceof String) { return ((String) k).hash32(); } - h ^= k.hashCode(); + int h = hashSeed ^ k.hashCode(); // Spread bits to regularize both segment and index locations, // using variant of single-word Wang/Jenkins hash. diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/java/util/spi/ResourceBundleControlProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/src/share/classes/java/util/spi/ResourceBundleControlProvider.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 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. 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. + */ + +package java.util.spi; + +import java.util.ResourceBundle; + +/** + * An interface for service providers that provide implementations of {@link + * java.util.ResourceBundle.Control}. The default resource bundle loading + * behavior of the {@code ResourceBundle.getBundle} factory methods that take + * no {@link java.util.ResourceBundle.Control} instance can be modified with {@code + * ResourceBundleControlProvider} implementations. + * + *

Provider implementations must be packaged using the Java Extension + * Mechanism as installed extensions. Refer to {@link java.util.ServiceLoader} + * for the extension packaging. Any installed {@code + * ResourceBundleControlProvider} implementations are loaded using {@link + * java.util.ServiceLoader} at the {@code ResourceBundle} class loading time. + * + * @author Masayoshi Okutsu + * @since 1.8 + * @see ResourceBundle#getBundle(String, java.util.Locale, ClassLoader, ResourceBundle.Control) + * ResourceBundle.getBundle + * @see java.util.ServiceLoader#loadInstalled(Class) + */ +public interface ResourceBundleControlProvider { + /** + * Returns a {@code ResourceBundle.Control} instance that is used + * to handle resource bundle loading for the given {@code + * baseName}. This method must return {@code null} if the given + * {@code baseName} isn't handled by this provider. + * + * @param baseName the base name of the resource bundle + * @return a {@code ResourceBundle.Control} instance, + * or {@code null} if the given {@code baseName} is not + * applicable to this provider. + * @throws NullPointerException if {@code baseName} is {@code null} + */ + public ResourceBundle.Control getControl(String baseName); +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/javax/imageio/stream/FileCacheImageInputStream.java --- a/jdk/src/share/classes/javax/imageio/stream/FileCacheImageInputStream.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/javax/imageio/stream/FileCacheImageInputStream.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -29,6 +29,7 @@ import java.io.InputStream; import java.io.IOException; import java.io.RandomAccessFile; +import java.nio.file.Files; import com.sun.imageio.stream.StreamCloser; import com.sun.imageio.stream.StreamFinalizer; import sun.java2d.Disposer; @@ -97,8 +98,11 @@ throw new IllegalArgumentException("Not a directory!"); } this.stream = stream; - this.cacheFile = - File.createTempFile("imageio", ".tmp", cacheDir); + if (cacheDir == null) + this.cacheFile = Files.createTempFile("imageio", ".tmp").toFile(); + else + this.cacheFile = Files.createTempFile(cacheDir.toPath(), "imageio", ".tmp") + .toFile(); this.cache = new RandomAccessFile(cacheFile, "rw"); this.closeAction = StreamCloser.createCloseAction(this); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java --- a/jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -29,6 +29,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.RandomAccessFile; +import java.nio.file.Files; import com.sun.imageio.stream.StreamCloser; /** @@ -83,8 +84,11 @@ throw new IllegalArgumentException("Not a directory!"); } this.stream = stream; - this.cacheFile = - File.createTempFile("imageio", ".tmp", cacheDir); + if (cacheDir == null) + this.cacheFile = Files.createTempFile("imageio", ".tmp").toFile(); + else + this.cacheFile = Files.createTempFile(cacheDir.toPath(), "imageio", ".tmp") + .toFile(); this.cache = new RandomAccessFile(cacheFile, "rw"); this.closeAction = StreamCloser.createCloseAction(this); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/javax/management/loading/MLet.java --- a/jdk/src/share/classes/javax/management/loading/MLet.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/javax/management/loading/MLet.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -44,6 +44,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLStreamHandlerFactory; +import java.nio.file.Files; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; @@ -1160,8 +1161,9 @@ try { File directory = new File(libraryDirectory); directory.mkdirs(); - File file = File.createTempFile(libname + ".", null, - directory); + File file = Files.createTempFile(directory.toPath(), + libname + ".", null) + .toFile(); file.deleteOnExit(); FileOutputStream fileOutput = new FileOutputStream(file); try { diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java --- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java Tue Jun 26 22:47:23 2012 -0700 @@ -152,8 +152,8 @@ if (!c.isEnabled()) { state = DISABLED; } - if (SynthLookAndFeel.selectedUI == this) { - return SynthLookAndFeel.selectedUIState | SynthConstants.ENABLED; + if (SynthLookAndFeel.getSelectedUI() == this) { + return SynthLookAndFeel.getSelectedUIState() | SynthConstants.ENABLED; } AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/javax/swing/plaf/synth/SynthLabelUI.java --- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthLabelUI.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthLabelUI.java Tue Jun 26 22:47:23 2012 -0700 @@ -97,9 +97,9 @@ private int getComponentState(JComponent c) { int state = SynthLookAndFeel.getComponentState(c); - if (SynthLookAndFeel.selectedUI == this && + if (SynthLookAndFeel.getSelectedUI() == this && state == SynthConstants.ENABLED) { - state = SynthLookAndFeel.selectedUIState | SynthConstants.ENABLED; + state = SynthLookAndFeel.getSelectedUIState() | SynthConstants.ENABLED; } return state; } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java --- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java Tue Jun 26 22:47:23 2012 -0700 @@ -77,27 +77,25 @@ new StringBuffer("com.sun.java.swing.plaf.gtk.StyleCache"); /** + * AppContext key to get selectedUI. + */ + private static final Object SELECTED_UI_KEY = new StringBuilder("selectedUI"); + + /** + * AppContext key to get selectedUIState. + */ + private static final Object SELECTED_UI_STATE_KEY = new StringBuilder("selectedUIState"); + + /** * The last SynthStyleFactory that was asked for from AppContext * lastContext. */ private static SynthStyleFactory lastFactory; /** - * If this is true it indicates there is more than one AppContext active - * and that we need to make sure in getStyleCache the requesting - * AppContext matches that of lastContext before returning - * it. - */ - private static boolean multipleApps; - /** * AppContext lastLAF came from. */ private static AppContext lastContext; - // Refer to setSelectedUI - static ComponentUI selectedUI; - // Refer to setSelectedUI - static int selectedUIState; - /** * SynthStyleFactory for the this SynthLookAndFeel. */ @@ -111,6 +109,10 @@ private Handler _handler; + static ComponentUI getSelectedUI() { + return (ComponentUI) AppContext.getAppContext().get(SELECTED_UI_KEY); + } + /** * Used by the renderers. For the most part the renderers are implemented * as Labels, which is problematic in so far as they are never selected. @@ -122,8 +124,8 @@ static void setSelectedUI(ComponentUI uix, boolean selected, boolean focused, boolean enabled, boolean rollover) { - selectedUI = uix; - selectedUIState = 0; + int selectedUIState = 0; + if (selected) { selectedUIState = SynthConstants.SELECTED; if (focused) { @@ -140,19 +142,32 @@ else { if (enabled) { selectedUIState |= SynthConstants.ENABLED; - selectedUIState = SynthConstants.FOCUSED; + if (focused) { + selectedUIState |= SynthConstants.FOCUSED; + } } else { selectedUIState |= SynthConstants.DISABLED; } } + + AppContext context = AppContext.getAppContext(); + + context.put(SELECTED_UI_KEY, uix); + context.put(SELECTED_UI_STATE_KEY, Integer.valueOf(selectedUIState)); + } + + static int getSelectedUIState() { + Integer result = (Integer) AppContext.getAppContext().get(SELECTED_UI_STATE_KEY); + + return result == null ? 0 : result.intValue(); } /** * Clears out the selected UI that was last set in setSelectedUI. */ static void resetSelectedUI() { - selectedUI = null; + AppContext.getAppContext().remove(SELECTED_UI_KEY); } @@ -167,10 +182,6 @@ // for a particular AppContext. synchronized(SynthLookAndFeel.class) { AppContext context = AppContext.getAppContext(); - if (!multipleApps && context != lastContext && - lastContext != null) { - multipleApps = true; - } lastFactory = cache; lastContext = context; context.put(STYLE_FACTORY_KEY, cache); @@ -184,17 +195,13 @@ */ public static SynthStyleFactory getStyleFactory() { synchronized(SynthLookAndFeel.class) { - if (!multipleApps) { - return lastFactory; - } AppContext context = AppContext.getAppContext(); if (lastContext == context) { return lastFactory; } lastContext = context; - lastFactory = (SynthStyleFactory)AppContext.getAppContext().get - (STYLE_FACTORY_KEY); + lastFactory = (SynthStyleFactory) context.get(STYLE_FACTORY_KEY); return lastFactory; } } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/javax/swing/text/html/parser/Parser.java --- a/jdk/src/share/classes/javax/swing/text/html/parser/Parser.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/javax/swing/text/html/parser/Parser.java Tue Jun 26 22:47:23 2012 -0700 @@ -1986,8 +1986,6 @@ if (i == SCRIPT_END_TAG.length) { /* '' tag detected */ - /* Here, ch == '>' */ - ch = readCh(); /* Here, ch == the first character after */ return; } else { @@ -2060,6 +2058,8 @@ handleComment(str.toCharArray()); endTag(false); lastBlockStartPos = currentPosition; + + continue; } else { switch (c) { case '<': diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java --- a/jdk/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/awt/dnd/SunDropTargetContextPeer.java Tue Jun 26 22:47:23 2012 -0700 @@ -498,7 +498,7 @@ postDropTargetEvent(component, x, y, dropAction, actions, formats, nativeCtxt, SunDropTargetEvent.MOUSE_DROPPED, - !SunDropTargetContextPeer.DISPATCH_SYNC); + SunDropTargetContextPeer.DISPATCH_SYNC); } /** diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/font/SunLayoutEngine.java --- a/jdk/src/share/classes/sun/font/SunLayoutEngine.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/font/SunLayoutEngine.java Tue Jun 26 22:47:23 2012 -0700 @@ -33,7 +33,7 @@ import sun.font.GlyphLayout.*; import java.awt.geom.Point2D; import java.lang.ref.SoftReference; -import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; import java.util.Locale; /* @@ -129,9 +129,9 @@ // !!! don't need this unless we have more than one sun layout engine... public LayoutEngine getEngine(LayoutEngineKey key) { - HashMap cache = (HashMap)cacheref.get(); + ConcurrentHashMap cache = (ConcurrentHashMap)cacheref.get(); if (cache == null) { - cache = new HashMap(); + cache = new ConcurrentHashMap(); cacheref = new SoftReference(cache); } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/invoke/util/VerifyAccess.java --- a/jdk/src/share/classes/sun/invoke/util/VerifyAccess.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/invoke/util/VerifyAccess.java Tue Jun 26 22:47:23 2012 -0700 @@ -37,6 +37,8 @@ private VerifyAccess() { } // cannot instantiate private static final int PACKAGE_ONLY = 0; + private static final int PACKAGE_ALLOWED = java.lang.invoke.MethodHandles.Lookup.PACKAGE; + private static final int PROTECTED_OR_PACKAGE_ALLOWED = (PACKAGE_ALLOWED|PROTECTED); private static final int ALL_ACCESS_MODES = (PUBLIC|PRIVATE|PROTECTED|PACKAGE_ONLY); private static final boolean ALLOW_NESTMATE_ACCESS = false; @@ -82,14 +84,19 @@ public static boolean isMemberAccessible(Class refc, // symbolic ref class Class defc, // actual def class int mods, // actual member mods - Class lookupClass) { + Class lookupClass, + int allowedModes) { + if (allowedModes == 0) return false; + assert((allowedModes & PUBLIC) != 0 && + (allowedModes & ~(ALL_ACCESS_MODES|PACKAGE_ALLOWED)) == 0); // Usually refc and defc are the same, but if they differ, verify them both. if (refc != defc) { - if (!isClassAccessible(refc, lookupClass)) { + if (!isClassAccessible(refc, lookupClass, allowedModes)) { // Note that defc is verified in the switch below. return false; } - if ((mods & (ALL_ACCESS_MODES|STATIC)) == (PROTECTED|STATIC)) { + if ((mods & (ALL_ACCESS_MODES|STATIC)) == (PROTECTED|STATIC) && + (allowedModes & PROTECTED_OR_PACKAGE_ALLOWED) != 0) { // Apply the special rules for refc here. if (!isRelatedClass(refc, lookupClass)) return isSamePackage(defc, lookupClass); @@ -98,19 +105,28 @@ // a superclass of the lookup class. } } - if (defc == lookupClass) + if (defc == lookupClass && + (allowedModes & PRIVATE) != 0) return true; // easy check; all self-access is OK switch (mods & ALL_ACCESS_MODES) { case PUBLIC: if (refc != defc) return true; // already checked above - return isClassAccessible(refc, lookupClass); + return isClassAccessible(refc, lookupClass, allowedModes); case PROTECTED: - return isSamePackage(defc, lookupClass) || isPublicSuperClass(defc, lookupClass); - case PACKAGE_ONLY: - return isSamePackage(defc, lookupClass); + if ((allowedModes & PROTECTED_OR_PACKAGE_ALLOWED) != 0 && + isSamePackage(defc, lookupClass)) + return true; + if ((allowedModes & PROTECTED) != 0 && + isPublicSuperClass(defc, lookupClass)) + return true; + return false; + case PACKAGE_ONLY: // That is, zero. Unmarked member is package-only access. + return ((allowedModes & PACKAGE_ALLOWED) != 0 && + isSamePackage(defc, lookupClass)); case PRIVATE: // Loosened rules for privates follows access rules for inner classes. return (ALLOW_NESTMATE_ACCESS && + (allowedModes & PRIVATE) != 0 && isSamePackageMember(defc, lookupClass)); default: throw new IllegalArgumentException("bad modifiers: "+Modifier.toString(mods)); @@ -138,11 +154,16 @@ * @param refc the symbolic reference class to which access is being checked (C) * @param lookupClass the class performing the lookup (D) */ - public static boolean isClassAccessible(Class refc, Class lookupClass) { + public static boolean isClassAccessible(Class refc, Class lookupClass, + int allowedModes) { + if (allowedModes == 0) return false; + assert((allowedModes & PUBLIC) != 0 && + (allowedModes & ~(ALL_ACCESS_MODES|PACKAGE_ALLOWED)) == 0); int mods = refc.getModifiers(); if (isPublic(mods)) return true; - if (isSamePackage(lookupClass, refc)) + if ((allowedModes & PACKAGE_ALLOWED) != 0 && + isSamePackage(lookupClass, refc)) return true; return false; } @@ -157,7 +178,7 @@ assert(!class1.isArray() && !class2.isArray()); if (class1 == class2) return true; - if (!loadersAreRelated(class1.getClassLoader(), class2.getClassLoader(), false)) + if (class1.getClassLoader() != class2.getClassLoader()) return false; String name1 = class1.getName(), name2 = class2.getName(); int dot = name1.lastIndexOf('.'); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/misc/JarIndex.java --- a/jdk/src/share/classes/sun/misc/JarIndex.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/misc/JarIndex.java Tue Jun 26 22:47:23 2012 -0700 @@ -201,23 +201,20 @@ packageName = fileName; } - // add the mapping to indexMap - addToList(packageName, jarName, indexMap); - - // add the mapping to jarMap - addToList(jarName, packageName, jarMap); + addMapping(packageName, jarName); } /** * Same as add(String,String) except that it doesn't strip off from the - * last index of '/'. It just adds the filename. + * last index of '/'. It just adds the jarItem (filename or package) + * as it is received. */ - private void addExplicit(String fileName, String jarName) { + private void addMapping(String jarItem, String jarName) { // add the mapping to indexMap - addToList(fileName, jarName, indexMap); + addToList(jarItem, jarName, indexMap); // add the mapping to jarMap - addToList(jarName, fileName, jarMap); + addToList(jarName, jarItem, jarMap); } /** @@ -248,18 +245,14 @@ fileName.equals(JarFile.MANIFEST_NAME)) continue; - if (!metaInfFilenames) { + if (!metaInfFilenames || !fileName.startsWith("META-INF/")) { add(fileName, currentJar); - } else { - if (!fileName.startsWith("META-INF/")) { - add(fileName, currentJar); - } else if (!entry.isDirectory()) { + } else if (!entry.isDirectory()) { // Add files under META-INF explicitly so that certain // services, like ServiceLoader, etc, can be located // with greater accuracy. Directories can be skipped // since each file will be added explicitly. - addExplicit(fileName, currentJar); - } + addMapping(fileName, currentJar); } } @@ -324,8 +317,7 @@ jars.add(currentJar); } else { String name = line; - addToList(name, currentJar, indexMap); - addToList(currentJar, name, jarMap); + addMapping(name, currentJar); } } @@ -354,7 +346,7 @@ if (path != null) { jarName = path.concat(jarName); } - toIndex.add(packageName, jarName); + toIndex.addMapping(packageName, jarName); } } } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/nio/ch/IOUtil.java --- a/jdk/src/share/classes/sun/nio/ch/IOUtil.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/nio/ch/IOUtil.java Tue Jun 26 22:47:23 2012 -0700 @@ -36,6 +36,11 @@ public class IOUtil { + /** + * Max number of iovec structures that readv/writev supports + */ + static final int IOV_MAX; + private IOUtil() { } // No instantiation static int write(FileDescriptor fd, ByteBuffer src, long position, @@ -111,7 +116,8 @@ // Iterate over buffers to populate native iovec array. int count = offset + length; - for (int i=offset; i bufferCache = diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/print/PSPrinterJob.java --- a/jdk/src/share/classes/sun/print/PSPrinterJob.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/print/PSPrinterJob.java Tue Jun 26 22:47:23 2012 -0700 @@ -97,6 +97,7 @@ import java.nio.charset.*; import java.nio.CharBuffer; import java.nio.ByteBuffer; +import java.nio.file.Files; //REMIND: Remove use of this class when IPPPrintService is moved to share directory. import java.lang.reflect.Method; @@ -659,7 +660,7 @@ * is not removed for some reason, request that it is * removed when the VM exits. */ - spoolFile = File.createTempFile("javaprint", ".ps", null); + spoolFile = Files.createTempFile("javaprint", ".ps").toFile(); spoolFile.deleteOnExit(); result = new FileOutputStream(spoolFile); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/print/ServiceDialog.java --- a/jdk/src/share/classes/sun/print/ServiceDialog.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/print/ServiceDialog.java Tue Jun 26 22:47:23 2012 -0700 @@ -429,6 +429,7 @@ ValidatingFileChooser jfc = new ValidatingFileChooser(); jfc.setApproveButtonText(getMsg("button.ok")); jfc.setDialogTitle(getMsg("dialog.printtofile")); + jfc.setDialogType(JFileChooser.SAVE_DIALOG); jfc.setSelectedFile(fileDest); int returnVal = jfc.showDialog(this, null); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/rmi/server/Activation.java --- a/jdk/src/share/classes/sun/rmi/server/Activation.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/rmi/server/Activation.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -43,6 +43,7 @@ import java.net.Socket; import java.net.SocketAddress; import java.net.SocketException; +import java.nio.file.Files; import java.nio.channels.Channel; import java.nio.channels.ServerSocketChannel; import java.rmi.AccessException; @@ -1940,7 +1941,7 @@ new PrivilegedExceptionAction() { public Void run() throws IOException { File file = - File.createTempFile("rmid-err", null, null); + Files.createTempFile("rmid-err", null).toFile(); PrintStream errStream = new PrintStream(new FileOutputStream(file)); System.setErr(errStream); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/security/provider/certpath/BasicChecker.java --- a/jdk/src/share/classes/sun/security/provider/certpath/BasicChecker.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/security/provider/certpath/BasicChecker.java Tue Jun 26 22:47:23 2012 -0700 @@ -90,6 +90,7 @@ this.date = date; this.sigProvider = sigProvider; this.sigOnly = sigOnly; + this.prevPubKey = trustedPubKey; } /** diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/security/ssl/SSLEngineImpl.java --- a/jdk/src/share/classes/sun/security/ssl/SSLEngineImpl.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/security/ssl/SSLEngineImpl.java Tue Jun 26 22:47:23 2012 -0700 @@ -1119,6 +1119,7 @@ * handle a few more records, so the sequence number * of the last record cannot be wrapped. */ + hsStatus = getHSStatus(hsStatus); if (connectionState < cs_ERROR && !isInboundDone() && (hsStatus == HandshakeStatus.NOT_HANDSHAKING)) { if (checkSequenceNumber(readMAC, @@ -1287,6 +1288,7 @@ * handle a few more records, so the sequence number * of the last record cannot be wrapped. */ + hsStatus = getHSStatus(hsStatus); if (connectionState < cs_ERROR && !isOutboundDone() && (hsStatus == HandshakeStatus.NOT_HANDSHAKING)) { if (checkSequenceNumber(writeMAC, eor.contentType())) { diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/security/x509/CRLExtensions.java --- a/jdk/src/share/classes/sun/security/x509/CRLExtensions.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/security/x509/CRLExtensions.java Tue Jun 26 22:47:23 2012 -0700 @@ -32,8 +32,10 @@ import java.security.cert.CRLException; import java.security.cert.CertificateException; import java.util.Collection; +import java.util.Collections; import java.util.Enumeration; -import java.util.Hashtable; +import java.util.Map; +import java.util.TreeMap; import sun.security.util.*; @@ -61,7 +63,8 @@ */ public class CRLExtensions { - private Hashtable map = new Hashtable(); + private Map map = Collections.synchronizedMap( + new TreeMap()); private boolean unsupportedCritExt = false; /** @@ -214,7 +217,7 @@ * @return an enumeration of the extensions in this CRL. */ public Enumeration getElements() { - return map.elements(); + return Collections.enumeration(map.values()); } /** diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/security/x509/CertificateExtensions.java --- a/jdk/src/share/classes/sun/security/x509/CertificateExtensions.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/security/x509/CertificateExtensions.java Tue Jun 26 22:47:23 2012 -0700 @@ -57,7 +57,8 @@ private static final Debug debug = Debug.getInstance("x509"); - private Hashtable map = new Hashtable(); + private Map map = Collections.synchronizedMap( + new TreeMap()); private boolean unsupportedCritExt = false; private Map unparseableExtensions; @@ -118,7 +119,7 @@ if (ext.isCritical() == false) { // ignore errors parsing non-critical extensions if (unparseableExtensions == null) { - unparseableExtensions = new HashMap(); + unparseableExtensions = new TreeMap(); } unparseableExtensions.put(ext.getExtensionId().toString(), new UnparseableExtension(ext, e)); @@ -219,6 +220,12 @@ return (obj); } + // Similar to get(String), but throw no exception, might return null. + // Used in X509CertImpl::getExtension(OID). + Extension getExtension(String name) { + return map.get(name); + } + /** * Delete the attribute value. * @param name the extension name used in the lookup. @@ -246,7 +253,7 @@ * attribute. */ public Enumeration getElements() { - return map.elements(); + return Collections.enumeration(map.values()); } /** diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/security/x509/X509CRLEntryImpl.java --- a/jdk/src/share/classes/sun/security/x509/X509CRLEntryImpl.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/src/share/classes/sun/security/x509/X509CRLEntryImpl.java Tue Jun 26 22:47:23 2012 -0700 @@ -30,14 +30,7 @@ import java.security.cert.CRLReason; import java.security.cert.X509CRLEntry; import java.math.BigInteger; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.HashSet; +import java.util.*; import javax.security.auth.x500.X500Principal; @@ -74,7 +67,8 @@ * @author Hemma Prafullchandra */ -public class X509CRLEntryImpl extends X509CRLEntry { +public class X509CRLEntryImpl extends X509CRLEntry + implements Comparable { private SerialNumber serialNumber = null; private Date revocationDate = null; @@ -195,9 +189,14 @@ * @exception CRLException if an encoding error occurs. */ public byte[] getEncoded() throws CRLException { + return getEncoded0().clone(); + } + + // Called internally to avoid clone + private byte[] getEncoded0() throws CRLException { if (revokedCert == null) this.encode(new DerOutputStream()); - return revokedCert.clone(); + return revokedCert; } @Override @@ -351,7 +350,7 @@ if (extensions == null) { return null; } - Set extSet = new HashSet(); + Set extSet = new TreeSet<>(); for (Extension ex : extensions.getAllExtensions()) { if (ex.isCritical()) { extSet.add(ex.getExtensionId().toString()); @@ -372,7 +371,7 @@ if (extensions == null) { return null; } - Set extSet = new HashSet(); + Set extSet = new TreeSet<>(); for (Extension ex : extensions.getAllExtensions()) { if (!ex.isCritical()) { extSet.add(ex.getExtensionId().toString()); @@ -500,16 +499,39 @@ getExtension(PKIXExtensions.CertificateIssuer_Id); } + /** + * Returns all extensions for this entry in a map + * @return the extension map, can be empty, but not null + */ public Map getExtensions() { if (extensions == null) { return Collections.emptyMap(); } Collection exts = extensions.getAllExtensions(); - HashMap map = - new HashMap(exts.size()); + Map map = new TreeMap<>(); for (Extension ext : exts) { map.put(ext.getId(), ext); } return map; } + + @Override + public int compareTo(X509CRLEntryImpl that) { + int compSerial = getSerialNumber().compareTo(that.getSerialNumber()); + if (compSerial != 0) { + return compSerial; + } + try { + byte[] thisEncoded = this.getEncoded0(); + byte[] thatEncoded = that.getEncoded0(); + for (int i=0; i - * An implmentation for X509 CRL (Certificate Revocation List). + * An implementation for X509 CRL (Certificate Revocation List). *

* The X.509 v2 CRL format is described below in ASN.1: *

@@ -103,7 +103,8 @@
     private X500Principal    issuerPrincipal = null;
     private Date             thisUpdate = null;
     private Date             nextUpdate = null;
-    private Map revokedCerts = new LinkedHashMap();
+    private Map revokedMap = new TreeMap<>();
+    private List revokedList = new LinkedList<>();
     private CRLExtensions    extensions = null;
     private final static boolean isExplicit = true;
     private static final long YR_2050 = 2524636800000L;
@@ -222,7 +223,8 @@
                 badCert.setCertificateIssuer(crlIssuer, badCertIssuer);
                 X509IssuerSerial issuerSerial = new X509IssuerSerial
                     (badCertIssuer, badCert.getSerialNumber());
-                this.revokedCerts.put(issuerSerial, badCert);
+                this.revokedMap.put(issuerSerial, badCert);
+                this.revokedList.add(badCert);
                 if (badCert.hasExtensions()) {
                     this.version = 1;
                 }
@@ -304,8 +306,8 @@
                     tmp.putGeneralizedTime(nextUpdate);
             }
 
-            if (!revokedCerts.isEmpty()) {
-                for (X509CRLEntry entry : revokedCerts.values()) {
+            if (!revokedList.isEmpty()) {
+                for (X509CRLEntry entry : revokedList) {
                     ((X509CRLEntryImpl)entry).encode(rCerts);
                 }
                 tmp.write(DerValue.tag_Sequence, rCerts);
@@ -489,14 +491,14 @@
             sb.append("\nThis Update: " + thisUpdate.toString() + "\n");
         if (nextUpdate != null)
             sb.append("Next Update: " + nextUpdate.toString() + "\n");
-        if (revokedCerts.isEmpty())
+        if (revokedList.isEmpty())
             sb.append("\nNO certificates have been revoked\n");
         else {
-            sb.append("\nRevoked Certificates: " + revokedCerts.size());
+            sb.append("\nRevoked Certificates: " + revokedList.size());
             int i = 1;
-            for (Iterator iter = revokedCerts.values().iterator();
-                                             iter.hasNext(); i++)
-                sb.append("\n[" + i + "] " + iter.next().toString());
+            for (X509CRLEntry entry: revokedList) {
+                sb.append("\n[" + i++ + "] " + entry.toString());
+            }
         }
         if (extensions != null) {
             Collection allExts = extensions.getAllExtensions();
@@ -542,12 +544,12 @@
      * false otherwise.
      */
     public boolean isRevoked(Certificate cert) {
-        if (revokedCerts.isEmpty() || (!(cert instanceof X509Certificate))) {
+        if (revokedMap.isEmpty() || (!(cert instanceof X509Certificate))) {
             return false;
         }
         X509Certificate xcert = (X509Certificate) cert;
         X509IssuerSerial issuerSerial = new X509IssuerSerial(xcert);
-        return revokedCerts.containsKey(issuerSerial);
+        return revokedMap.containsKey(issuerSerial);
     }
 
     /**
@@ -637,24 +639,24 @@
      * @see X509CRLEntry
      */
     public X509CRLEntry getRevokedCertificate(BigInteger serialNumber) {
-        if (revokedCerts.isEmpty()) {
+        if (revokedMap.isEmpty()) {
             return null;
         }
         // assume this is a direct CRL entry (cert and CRL issuer are the same)
         X509IssuerSerial issuerSerial = new X509IssuerSerial
             (getIssuerX500Principal(), serialNumber);
-        return revokedCerts.get(issuerSerial);
+        return revokedMap.get(issuerSerial);
     }
 
     /**
      * Gets the CRL entry for the given certificate.
      */
     public X509CRLEntry getRevokedCertificate(X509Certificate cert) {
-        if (revokedCerts.isEmpty()) {
+        if (revokedMap.isEmpty()) {
             return null;
         }
         X509IssuerSerial issuerSerial = new X509IssuerSerial(cert);
-        return revokedCerts.get(issuerSerial);
+        return revokedMap.get(issuerSerial);
     }
 
     /**
@@ -666,10 +668,10 @@
      * @see X509CRLEntry
      */
     public Set getRevokedCertificates() {
-        if (revokedCerts.isEmpty()) {
+        if (revokedList.isEmpty()) {
             return null;
         } else {
-            return new HashSet(revokedCerts.values());
+            return new TreeSet(revokedList);
         }
     }
 
@@ -905,7 +907,7 @@
         if (extensions == null) {
             return null;
         }
-        Set extSet = new HashSet();
+        Set extSet = new TreeSet<>();
         for (Extension ex : extensions.getAllExtensions()) {
             if (ex.isCritical()) {
                 extSet.add(ex.getExtensionId().toString());
@@ -926,7 +928,7 @@
         if (extensions == null) {
             return null;
         }
-        Set extSet = new HashSet();
+        Set extSet = new TreeSet<>();
         for (Extension ex : extensions.getAllExtensions()) {
             if (!ex.isCritical()) {
                 extSet.add(ex.getExtensionId().toString());
@@ -1103,7 +1105,8 @@
                 entry.setCertificateIssuer(crlIssuer, badCertIssuer);
                 X509IssuerSerial issuerSerial = new X509IssuerSerial
                     (badCertIssuer, entry.getSerialNumber());
-                revokedCerts.put(issuerSerial, entry);
+                revokedMap.put(issuerSerial, entry);
+                revokedList.add(entry);
             }
         }
 
@@ -1207,7 +1210,8 @@
     /**
      * Immutable X.509 Certificate Issuer DN and serial number pair
      */
-    private final static class X509IssuerSerial {
+    private final static class X509IssuerSerial
+            implements Comparable {
         final X500Principal issuer;
         final BigInteger serial;
         volatile int hashcode = 0;
@@ -1286,5 +1290,13 @@
             }
             return hashcode;
         }
+
+        @Override
+        public int compareTo(X509IssuerSerial another) {
+            int cissuer = issuer.toString()
+                    .compareTo(another.issuer.toString());
+            if (cissuer != 0) return cissuer;
+            return this.serial.compareTo(another.serial);
+        }
     }
 }
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/security/x509/X509CertImpl.java
--- a/jdk/src/share/classes/sun/security/x509/X509CertImpl.java	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/classes/sun/security/x509/X509CertImpl.java	Tue Jun 26 22:47:23 2012 -0700
@@ -1202,7 +1202,7 @@
             if (exts == null) {
                 return null;
             }
-            Set extSet = new HashSet();
+            Set extSet = new TreeSet<>();
             for (Extension ex : exts.getAllExtensions()) {
                 if (ex.isCritical()) {
                     extSet.add(ex.getExtensionId().toString());
@@ -1232,7 +1232,7 @@
             if (exts == null) {
                 return null;
             }
-            Set extSet = new HashSet();
+            Set extSet = new TreeSet<>();
             for (Extension ex : exts.getAllExtensions()) {
                 if (!ex.isCritical()) {
                     extSet.add(ex.getExtensionId().toString());
@@ -1266,10 +1266,14 @@
             if (extensions == null) {
                 return null;
             } else {
-                for (Extension ex : extensions.getAllExtensions()) {
-                    if (ex.getExtensionId().equals((Object)oid)) {
+                Extension ex = extensions.getExtension(oid.toString());
+                if (ex != null) {
+                    return ex;
+                }
+                for (Extension ex2: extensions.getAllExtensions()) {
+                    if (ex2.getExtensionId().equals((Object)oid)) {
                         //XXXX May want to consider cloning this
-                        return ex;
+                        return ex2;
                     }
                 }
                 /* no such extension in this certificate */
@@ -1465,10 +1469,10 @@
         if (names.isEmpty()) {
             return Collections.>emptySet();
         }
-        Set> newNames = new HashSet>();
+        List> newNames = new ArrayList<>();
         for (GeneralName gname : names.names()) {
             GeneralNameInterface name = gname.getName();
-            List nameEntry = new ArrayList(2);
+            List nameEntry = new ArrayList<>(2);
             nameEntry.add(Integer.valueOf(name.getType()));
             switch (name.getType()) {
             case GeneralNameInterface.NAME_RFC822:
@@ -1526,12 +1530,12 @@
             }
         }
         if (mustClone) {
-            Set> namesCopy = new HashSet>();
+            List> namesCopy = new ArrayList<>();
             for (List nameEntry : altNames) {
                 Object nameObject = nameEntry.get(1);
                 if (nameObject instanceof byte[]) {
                     List nameEntryCopy =
-                                        new ArrayList(nameEntry);
+                                        new ArrayList<>(nameEntry);
                     nameEntryCopy.set(1, ((byte[])nameObject).clone());
                     namesCopy.add(Collections.unmodifiableList(nameEntryCopy));
                 } else {
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/tools/jar/Main.java
--- a/jdk/src/share/classes/sun/tools/jar/Main.java	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/classes/sun/tools/jar/Main.java	Tue Jun 26 22:47:23 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -137,7 +137,7 @@
         File dir = file.getParentFile();
         if (dir == null)
             dir = new File(".");
-        return File.createTempFile("jartmp", null, dir);
+        return Files.createTempFile(dir.toPath(), "jartmp", null).toFile();
     }
 
     private boolean ok;
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/classes/sun/tools/native2ascii/Main.java
--- a/jdk/src/share/classes/sun/tools/native2ascii/Main.java	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/classes/sun/tools/native2ascii/Main.java	Tue Jun 26 22:47:23 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -71,6 +71,7 @@
 import java.nio.charset.CharsetEncoder;
 import java.nio.charset.Charset;
 import java.nio.charset.IllegalCharsetNameException;
+import java.nio.file.Files;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.UnsupportedCharsetException;
 import sun.tools.native2ascii.A2NFilter;
@@ -240,9 +241,7 @@
             if (tempDir == null)
                 tempDir = new File(System.getProperty("user.dir"));
 
-            tempFile = File.createTempFile("_N2A",
-                                           ".TMP",
-                                            tempDir);
+            tempFile = Files.createTempFile(tempDir.toPath(), "_N2A", ".TMP").toFile();
             tempFile.deleteOnExit();
 
             try {
@@ -292,9 +291,7 @@
             File tempDir = f.getParentFile();
             if (tempDir == null)
                 tempDir = new File(System.getProperty("user.dir"));
-            tempFile =  File.createTempFile("_N2A",
-                                            ".TMP",
-                                            tempDir);
+            tempFile =  Files.createTempFile(tempDir.toPath(), "_N2A", ".TMP").toFile();
             tempFile.deleteOnExit();
 
             try {
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/demo/jvmti/hprof/hprof_table.c
--- a/jdk/src/share/demo/jvmti/hprof/hprof_table.c	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/demo/jvmti/hprof/hprof_table.c	Tue Jun 26 22:47:23 2012 -0700
@@ -120,7 +120,7 @@
     TableIndex     table_incr;          /* Suggested increment size. */
     TableIndex     hash_bucket_count;   /* Number of hash buckets. */
     int            elem_size;           /* Size of element. */
-    int            info_size;           /* Size of info structure. */
+    int            info_size;           /* Size of info structure (can be 0). */
     void          *freed_bv;            /* Freed element bit vector */
     int            freed_count;         /* Count of freed'd elements */
     TableIndex     freed_start;         /* First freed in table */
@@ -208,9 +208,6 @@
 {
     TableElement *element;
 
-    if ( ltable->info_size == 0 ) {
-        return NULL;
-    }
     element = (TableElement*)ELEMENT_PTR(ltable,index);
     return element->info;
 }
@@ -760,7 +757,11 @@
                 void *info;
 
                 get_key(ltable, index, &key_ptr, &key_len);
-                info = get_info(ltable, index);
+                if ( ltable->info_size == 0 ) {
+                    info = NULL;
+                } else {
+                    info = get_info(ltable, index);
+                }
                 (*func)(SANITY_ADD_HARE(index, ltable->hare), key_ptr, key_len, info, arg);
                 if ( is_freed_entry(ltable, index) ) {
                     fcount++;
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/lib/security/java.security
--- a/jdk/src/share/lib/security/java.security	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/lib/security/java.security	Tue Jun 26 22:47:23 2012 -0700
@@ -132,10 +132,10 @@
 # corresponding RuntimePermission ("defineClassInPackage."+package) has
 # been granted.
 #
-# by default, no packages are restricted for definition, and none of
-# the class loaders supplied with the JDK call checkPackageDefinition.
+# by default, none of the class loaders supplied with the JDK call
+# checkPackageDefinition.
 #
-#package.definition=
+package.definition=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.
 
 #
 # Determines whether this properties file can be appended to
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/lib/security/java.security-macosx
--- a/jdk/src/share/lib/security/java.security-macosx	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/lib/security/java.security-macosx	Tue Jun 26 22:47:23 2012 -0700
@@ -133,10 +133,10 @@
 # corresponding RuntimePermission ("defineClassInPackage."+package) has
 # been granted.
 #
-# by default, no packages are restricted for definition, and none of
-# the class loaders supplied with the JDK call checkPackageDefinition.
+# by default, none of the class loaders supplied with the JDK call
+# checkPackageDefinition.
 #
-#package.definition=
+package.definition=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,apple.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.
 
 #
 # Determines whether this properties file can be appended to
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/lib/security/java.security-solaris
--- a/jdk/src/share/lib/security/java.security-solaris	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/lib/security/java.security-solaris	Tue Jun 26 22:47:23 2012 -0700
@@ -134,10 +134,10 @@
 # corresponding RuntimePermission ("defineClassInPackage."+package) has
 # been granted.
 #
-# by default, no packages are restricted for definition, and none of
-# the class loaders supplied with the JDK call checkPackageDefinition.
+# by default, none of the class loaders supplied with the JDK call
+# checkPackageDefinition.
 #
-#package.definition=
+package.definition=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.
 
 #
 # Determines whether this properties file can be appended to
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/lib/security/java.security-windows
--- a/jdk/src/share/lib/security/java.security-windows	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/lib/security/java.security-windows	Tue Jun 26 22:47:23 2012 -0700
@@ -133,10 +133,10 @@
 # corresponding RuntimePermission ("defineClassInPackage."+package) has
 # been granted.
 #
-# by default, no packages are restricted for definition, and none of
-# the class loaders supplied with the JDK call checkPackageDefinition.
+# by default, none of the class loaders supplied with the JDK call
+# checkPackageDefinition.
 #
-#package.definition=
+package.definition=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.
 
 #
 # Determines whether this properties file can be appended to
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/native/java/net/net_util.c
--- a/jdk/src/share/native/java/net/net_util.c	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/native/java/net/net_util.c	Tue Jun 26 22:47:23 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -68,6 +68,8 @@
     */
     IPv6_available = IPv6_supported() & (!preferIPv4Stack);
     initLocalAddrTable ();
+    parseExclusiveBindProperty(env);
+
     return JNI_VERSION_1_2;
 }
 
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/native/java/net/net_util.h
--- a/jdk/src/share/native/java/net/net_util.h	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/native/java/net/net_util.h	Tue Jun 26 22:47:23 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -120,6 +120,7 @@
 NET_SockaddrToInetAddress(JNIEnv *env, struct sockaddr *him, int *port);
 
 void initLocalAddrTable ();
+void parseExclusiveBindProperty(JNIEnv *env);
 
 void
 NET_SetTrafficClass(struct sockaddr *him, int trafficClass);
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c
--- a/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c	Tue Jun 26 22:47:23 2012 -0700
@@ -337,7 +337,7 @@
     /* Save the data currently in the buffer */
     offset = src->pub.bytes_in_buffer;
     if (src->pub.next_input_byte > src->inbuf) {
-        memcpy(src->inbuf, src->pub.next_input_byte, offset);
+        memmove(src->inbuf, src->pub.next_input_byte, offset);
     }
     RELEASE_ARRAYS(env, src);
     buflen = (*env)->GetArrayLength(env, src->hInputBuffer) - offset;
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/native/sun/font/layout/LookupProcessor.cpp
--- a/jdk/src/share/native/sun/font/layout/LookupProcessor.cpp	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/native/sun/font/layout/LookupProcessor.cpp	Tue Jun 26 22:47:23 2012 -0700
@@ -95,6 +95,10 @@
 
         if (selectMask != 0) {
             const LookupTable *lookupTable = lookupListTable->getLookupTable(lookup);
+
+            if (!lookupTable)
+                continue;
+
             le_uint16 lookupFlags = SWAPW(lookupTable->lookupFlags);
 
             glyphIterator.reset(lookupFlags, selectMask);
@@ -136,6 +140,9 @@
     for (le_uint16 lookup = 0; lookup < lookupCount; lookup += 1) {
         le_uint16 lookupListIndex = SWAPW(featureTable->lookupListIndexArray[lookup]);
 
+        if (lookupListIndex >= lookupSelectCount)
+            continue;
+
         lookupSelectArray[lookupListIndex] |= featureMask;
         lookupOrderArray[store++] = lookupListIndex;
     }
@@ -147,7 +154,7 @@
         Offset scriptListOffset, Offset featureListOffset, Offset lookupListOffset,
         LETag scriptTag, LETag languageTag, const FeatureMap *featureMap, le_int32 featureMapCount, le_bool orderFeatures,
         LEErrorCode& success)
-    : lookupListTable(NULL), featureListTable(NULL), lookupSelectArray(NULL),
+    : lookupListTable(NULL), featureListTable(NULL), lookupSelectArray(NULL), lookupSelectCount(0),
       lookupOrderArray(NULL), lookupOrderCount(0)
 {
     const ScriptListTable *scriptListTable = NULL;
@@ -195,6 +202,8 @@
         lookupSelectArray[i] = 0;
     }
 
+    lookupSelectCount = lookupListCount;
+
     le_int32 count, order = 0;
     le_int32 featureReferences = 0;
     const FeatureTable *featureTable = NULL;
@@ -211,6 +220,10 @@
         le_uint16 featureIndex = SWAPW(langSysTable->featureIndexArray[feature]);
 
         featureTable = featureListTable->getFeatureTable(featureIndex, &featureTag);
+
+        if (!featureTable)
+            continue;
+
         featureReferences += SWAPW(featureTable->lookupCount);
     }
 
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/share/native/sun/font/layout/LookupProcessor.h
--- a/jdk/src/share/native/sun/font/layout/LookupProcessor.h	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/share/native/sun/font/layout/LookupProcessor.h	Tue Jun 26 22:47:23 2012 -0700
@@ -90,6 +90,7 @@
     const FeatureListTable  *featureListTable;
 
     FeatureMask            *lookupSelectArray;
+    le_uint32              lookupSelectCount;
 
     le_uint16               *lookupOrderArray;
     le_uint32               lookupOrderCount;
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/solaris/classes/sun/font/FcFontConfiguration.java
--- a/jdk/src/solaris/classes/sun/font/FcFontConfiguration.java	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/solaris/classes/sun/font/FcFontConfiguration.java	Tue Jun 26 22:47:23 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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
@@ -33,6 +33,7 @@
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.nio.charset.Charset;
+import java.nio.file.Files;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Properties;
@@ -387,7 +388,7 @@
             File fcInfoFile = getFcInfoFile();
             File dir = fcInfoFile.getParentFile();
             dir.mkdirs();
-            File tempFile = File.createTempFile("fcinfo", null, dir);
+            File tempFile = Files.createTempFile(dir.toPath(), "fcinfo", null).toFile();
             FileOutputStream fos = new FileOutputStream(tempFile);
             props.store(fos,
                       "JDK Font Configuration Generated File: *Do Not Edit*");
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/solaris/classes/sun/print/CUPSPrinter.java
--- a/jdk/src/solaris/classes/sun/print/CUPSPrinter.java	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/solaris/classes/sun/print/CUPSPrinter.java	Tue Jun 26 22:47:23 2012 -0700
@@ -278,14 +278,26 @@
                                          is);
                     is.close();
 
-                    if (responseMap.length > 0) {
+                    if (responseMap != null && responseMap.length > 0) {
                         defaultMap = responseMap[0];
                     }
 
                     if (defaultMap == null) {
                         os.close();
                         urlConnection.disconnect();
-                        return null;
+
+                        /* CUPS on OS X, as initially configured, considers the
+                         * default printer to be the last one used that's
+                         * presently available. So if no default was
+                         * reported, exec lpstat -d which has all the Apple
+                         * special behaviour for this built in.
+                         */
+                         if (UnixPrintServiceLookup.isMac()) {
+                             return UnixPrintServiceLookup.
+                                                   getDefaultPrinterNameSysV();
+                         } else {
+                             return null;
+                         }
                     }
 
                     AttributeClass attribClass = (AttributeClass)
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/solaris/classes/sun/print/UnixPrintJob.java
--- a/jdk/src/solaris/classes/sun/print/UnixPrintJob.java	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/solaris/classes/sun/print/UnixPrintJob.java	Tue Jun 26 22:47:23 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -42,6 +42,7 @@
 import java.io.Reader;
 import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
+import java.nio.file.Files;
 import java.util.Vector;
 
 import javax.print.CancelablePrintJob;
@@ -938,7 +939,7 @@
                      * is not removed for some reason, request that it is
                      * removed when the VM exits.
                      */
-                    spoolFile = File.createTempFile("javaprint", ".ps", null);
+                    spoolFile = Files.createTempFile("javaprint", ".ps").toFile();
                     spoolFile.deleteOnExit();
                 }
                 result = new FileOutputStream(spoolFile);
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
--- a/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java	Tue Jun 26 22:47:23 2012 -0700
@@ -51,6 +51,7 @@
 import java.io.File;
 import java.io.FileReader;
 import java.net.URL;
+import java.nio.file.Files;
 
 /*
  * Remind: This class uses solaris commands. We also need a linux
@@ -114,6 +115,10 @@
             new sun.security.action.GetPropertyAction("os.name"));
     }
 
+    static boolean isMac() {
+        return osname.startsWith("Mac");
+    }
+
     static boolean isSysV() {
         return osname.equals("SunOS");
     }
@@ -212,7 +217,7 @@
                 }
             }
         } else {
-            if (isSysV()) {
+            if (isMac() || isSysV()) {
                 printers = getAllPrinterNamesSysV();
             } else { //BSD
                 printers = getAllPrinterNamesBSD();
@@ -361,7 +366,7 @@
         if (name == null || name.equals("") || !checkPrinterName(name)) {
             return null;
         }
-        if (isSysV()) {
+        if (isMac() || isSysV()) {
             printer = getNamedPrinterNameSysV(name);
         } else {
             printer = getNamedPrinterNameBSD(name);
@@ -523,7 +528,7 @@
         if (CUPSPrinter.isCupsRunning()) {
             defaultPrinter = CUPSPrinter.getDefaultPrinter();
         } else {
-            if (isSysV()) {
+            if (isMac() || isSysV()) {
                 defaultPrinter = getDefaultPrinterNameSysV();
             } else {
                 defaultPrinter = getDefaultPrinterNameBSD();
@@ -644,7 +649,7 @@
         return names;
     }
 
-    private String getDefaultPrinterNameSysV() {
+    static String getDefaultPrinterNameSysV() {
         String defaultPrinter = "lp";
         String command = "/usr/bin/lpstat -d";
 
@@ -714,7 +719,7 @@
 
                         Process proc;
                         BufferedReader bufferedReader = null;
-                        File f = File.createTempFile("prn","xc");
+                        File f = Files.createTempFile("prn","xc").toFile();
                         cmd[2] = cmd[2]+">"+f.getAbsolutePath();
 
                         proc = Runtime.getRuntime().exec(cmd);
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/solaris/demo/jvmti/hprof/hprof_md.c
--- a/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c	Tue Jun 26 22:47:23 2012 -0700
@@ -119,9 +119,13 @@
 
     /* create a socket */
     fd = socket(AF_INET, SOCK_STREAM, 0);
+    if ( fd < 0 ) {
+        return -1;
+    }
 
     /* find remote host's addr from name */
     if ((hentry = gethostbyname(hostname)) == NULL) {
+        (void)close(fd);
         return -1;
     }
     (void)memset((char *)&s, 0, sizeof(s));
@@ -134,6 +138,7 @@
 
     /* now try connecting */
     if (-1 == connect(fd, (struct sockaddr*)&s, sizeof(s))) {
+        (void)close(fd);
         return 0;
     }
     return fd;
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/solaris/native/java/net/net_util_md.c
--- a/jdk/src/solaris/native/java/net/net_util_md.c	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/solaris/native/java/net/net_util_md.c	Tue Jun 26 22:47:23 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -76,7 +76,7 @@
 getnameinfo_f getnameinfo_ptr = NULL;
 
 /*
- * EXCLBIND socket options only on Solaris 8 & 9.
+ * EXCLBIND socket options only on Solaris
  */
 #if defined(__solaris__) && !defined(TCP_EXCLBIND)
 #define TCP_EXCLBIND            0x21
@@ -131,6 +131,7 @@
 static int init_tcp_max_buf, init_udp_max_buf;
 static int tcp_max_buf;
 static int udp_max_buf;
+static int useExclBind = 0;
 
 /*
  * Get the specified parameter from the specified driver. The value
@@ -765,6 +766,26 @@
 
 #endif
 
+void parseExclusiveBindProperty(JNIEnv *env) {
+#ifdef __solaris__
+    jstring s, flagSet;
+    jclass iCls;
+    jmethodID mid;
+
+    s = (*env)->NewStringUTF(env, "sun.net.useExclusiveBind");
+    CHECK_NULL(s);
+    iCls = (*env)->FindClass(env, "java/lang/System");
+    CHECK_NULL(iCls);
+    mid = (*env)->GetStaticMethodID(env, iCls, "getProperty",
+                "(Ljava/lang/String;)Ljava/lang/String;");
+    CHECK_NULL(mid);
+    flagSet = (*env)->CallStaticObjectMethod(env, iCls, mid, s);
+    if (flagSet != NULL) {
+        useExclBind = 1;
+    }
+#endif
+}
+
 /* In the case of an IPv4 Inetaddress this method will return an
  * IPv4 mapped address where IPv6 is available and v4MappedAddress is TRUE.
  * Otherwise it will return a sockaddr_in structure for an IPv4 InetAddress.
@@ -1478,8 +1499,8 @@
  * Linux allows a socket to bind to 127.0.0.255 which must be
  * caught.
  *
- * On Solaris 8/9 with IPv6 enabled we must use an exclusive
- * bind to guaranteed a unique port number across the IPv4 and
+ * On Solaris with IPv6 enabled we must use an exclusive
+ * bind to guarantee a unique port number across the IPv4 and
  * IPv6 port spaces.
  *
  */
@@ -1509,10 +1530,10 @@
 
 #if defined(__solaris__) && defined(AF_INET6)
     /*
-     * Solaris 8/9 have seperate IPv4 and IPv6 port spaces so we
+     * Solaris has separate IPv4 and IPv6 port spaces so we
      * use an exclusive bind when SO_REUSEADDR is not used to
      * give the illusion of a unified port space.
-     * This also avoid problems with IPv6 sockets connecting
+     * This also avoids problems with IPv6 sockets connecting
      * to IPv4 mapped addresses whereby the socket conversion
      * results in a late bind that fails because the
      * corresponding IPv4 port is in use.
@@ -1521,11 +1542,12 @@
         int arg, len;
 
         len = sizeof(arg);
-        if (getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&arg,
-                       &len) == 0) {
-            if (arg == 0) {
+        if (useExclBind || getsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
+                       (char *)&arg, &len) == 0) {
+            if (useExclBind || arg == 0) {
                 /*
-                 * SO_REUSEADDR is disabled so enable TCP_EXCLBIND or
+                 * SO_REUSEADDR is disabled or sun.net.useExclusiveBind
+                 * property is true so enable TCP_EXCLBIND or
                  * UDP_EXCLBIND
                  */
                 len = sizeof(arg);
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c
--- a/jdk/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c	Tue Jun 26 22:47:23 2012 -0700
@@ -94,9 +94,6 @@
 {
     jint fd = fdval(env, fdo);
     struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
-    if (len > 16) {
-        len = 16;
-    }
     return convertLongReturnVal(env, readv(fd, iov, len), JNI_TRUE);
 }
 
@@ -126,9 +123,6 @@
 {
     jint fd = fdval(env, fdo);
     struct iovec *iov = (struct iovec *)jlong_to_ptr(address);
-    if (len > 16) {
-        len = 16;
-    }
     return convertLongReturnVal(env, writev(fd, iov, len), JNI_FALSE);
 }
 
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/solaris/native/sun/nio/ch/IOUtil.c
--- a/jdk/src/solaris/native/sun/nio/ch/IOUtil.c	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/solaris/native/sun/nio/ch/IOUtil.c	Tue Jun 26 22:47:23 2012 -0700
@@ -136,6 +136,16 @@
     }
 }
 
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_IOUtil_iovMax(JNIEnv *env, jclass this)
+{
+    jlong iov_max = sysconf(_SC_IOV_MAX);
+    if (iov_max == -1)
+        iov_max = 16;
+    return (jint)iov_max;
+}
+
+
 /* Declared in nio_util.h for use elsewhere in NIO */
 
 jint
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/windows/native/java/net/net_util_md.c
--- a/jdk/src/windows/native/java/net/net_util_md.c	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/windows/native/java/net/net_util_md.c	Tue Jun 26 22:47:23 2012 -0700
@@ -126,6 +126,7 @@
 }
 
 void initLocalAddrTable () {}
+void parseExclusiveBindProperty (JNIEnv *env) {}
 
 /*
  * Since winsock doesn't have the equivalent of strerror(errno)
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/windows/native/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.c
--- a/jdk/src/windows/native/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.c	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/windows/native/sun/net/www/protocol/http/ntlm/NTLMAuthSequence.c	Tue Jun 26 22:47:23 2012 -0700
@@ -151,7 +151,7 @@
 
     VOID        *pInput = 0;
     DWORD            inputLen;
-    CHAR         buffOut[512];
+    CHAR         buffOut[1024];
     jboolean         isCopy;
     SECURITY_STATUS      ss;
     SecBufferDesc        OutBuffDesc;
@@ -178,7 +178,7 @@
     OutBuffDesc.cBuffers  = 1;
     OutBuffDesc.pBuffers  = &OutSecBuff;
 
-    OutSecBuff.cbBuffer   = 512;
+    OutSecBuff.cbBuffer   = 1024;
     OutSecBuff.BufferType = SECBUFFER_TOKEN;
     OutSecBuff.pvBuffer   = buffOut;
 
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/windows/native/sun/nio/ch/IOUtil.c
--- a/jdk/src/windows/native/sun/nio/ch/IOUtil.c	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/windows/native/sun/nio/ch/IOUtil.c	Tue Jun 26 22:47:23 2012 -0700
@@ -41,9 +41,6 @@
 /* field id for jint 'fd' in java.io.FileDescriptor used for socket fds */
 static jfieldID fd_fdID;
 
-/* false for 95/98/ME, true for NT/W2K */
-static jboolean onNT = JNI_FALSE;
-
 JNIEXPORT jboolean JNICALL
 Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed
 (JNIEnv *env, jclass clazz, jbyteArray randArray);
@@ -55,13 +52,6 @@
 JNIEXPORT void JNICALL
 Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz)
 {
-    OSVERSIONINFO ver;
-    ver.dwOSVersionInfoSize = sizeof(ver);
-    GetVersionEx(&ver);
-    if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) {
-        onNT = JNI_TRUE;
-    }
-
     clazz = (*env)->FindClass(env, "java/io/FileDescriptor");
     fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I");
     handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J");
@@ -80,6 +70,13 @@
                                                                     randArray);
 }
 
+JNIEXPORT jint JNICALL
+Java_sun_nio_ch_IOUtil_iovMax(JNIEnv *env, jclass this)
+{
+    return 16;
+}
+
+
 jint
 convertReturnVal(JNIEnv *env, jint n, jboolean reading)
 {
@@ -205,9 +202,3 @@
 {
     return (*env)->GetLongField(env, fdo, handle_fdID);
 }
-
-jboolean
-isNT()
-{
-    return onNT;
-}
diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/src/windows/native/sun/nio/ch/SocketDispatcher.c
--- a/jdk/src/windows/native/sun/nio/ch/SocketDispatcher.c	Tue Jun 26 15:28:21 2012 -0700
+++ b/jdk/src/windows/native/sun/nio/ch/SocketDispatcher.c	Tue Jun 26 22:47:23 2012 -0700
@@ -97,10 +97,6 @@
         return IOS_THROWN;
     }
 
-    if ((isNT() == JNI_FALSE) && (len > 16)) {
-        len = 16;
-    }
-
     /* copy iovec into WSABUF */
     for(i=0; i MAX_BUFFER_SIZE)
-        len = MAX_BUFFER_SIZE;
+    do {
+        /* limit size */
+        jint len = total - count;
+        if (len > MAX_BUFFER_SIZE)
+            len = MAX_BUFFER_SIZE;
 
-    /* copy iovec into WSABUF */
-    buf.buf = (char *)address;
-    buf.len = (u_long)len;
+        /* copy iovec into WSABUF */
+        buf.buf = (char *)address;
+        buf.len = (u_long)len;
+
+        /* write from the buffer */
+        i = WSASend((SOCKET)fd,     /* Socket */
+                    &buf,           /* pointers to the buffers */
+                    (DWORD)1,       /* number of buffers to process */
+                    &written,       /* receives number of bytes written */
+                    0,              /* no flags */
+                    0,              /* no overlapped sockets */
+                    0);             /* no completion routine */
 
-    /* read into the buffers */
-    i = WSASend((SOCKET)fd, /* Socket */
-            &buf,           /* pointers to the buffers */
-            (DWORD)1,       /* number of buffers to process */
-            &written,       /* receives number of bytes written */
-            0,              /* no flags */
-            0,              /* no overlapped sockets */
-            0);             /* no completion routine */
+        if (i == SOCKET_ERROR) {
+            if (count > 0) {
+                /* can't throw exception when some bytes have been written */
+                break;
+            } else {
+               int theErr = (jint)WSAGetLastError();
+               if (theErr == WSAEWOULDBLOCK) {
+                   return IOS_UNAVAILABLE;
+               }
+               JNU_ThrowIOExceptionWithLastError(env, "Write failed");
+               return IOS_THROWN;
+            }
+        }
 
-    if (i == SOCKET_ERROR) {
-        int theErr = (jint)WSAGetLastError();
-        if (theErr == WSAEWOULDBLOCK) {
-            return IOS_UNAVAILABLE;
-        }
-        JNU_ThrowIOExceptionWithLastError(env, "Write failed");
-        return IOS_THROWN;
-    }
+        count += written;
+        address += written;
 
-    return convertReturnVal(env, (jint)written, JNI_FALSE);
+    } while ((count < total) && (written == MAX_BUFFER_SIZE));
+
+    return count;
 }
 
 JNIEXPORT jlong JNICALL
@@ -195,10 +204,6 @@
         return IOS_THROWN;
     }
 
-    if ((isNT() == JNI_FALSE) && (len > 16)) {
-        len = 16;
-    }
-
     /* copy iovec into WSABUF */
     for(i=0; i THIS_CLASS = AccessControlTest.class;
+    // How much output?
+    static int verbosity = 0;
+    static {
+        String vstr = System.getProperty(THIS_CLASS.getSimpleName()+".verbosity");
+        if (vstr == null)
+            vstr = System.getProperty(THIS_CLASS.getName()+".verbosity");
+        if (vstr != null)  verbosity = Integer.parseInt(vstr);
+    }
+
+    private class LookupCase implements Comparable {
+        final Lookup   lookup;
+        final Class lookupClass;
+        final int      lookupModes;
+        public LookupCase(Lookup lookup) {
+            this.lookup = lookup;
+            this.lookupClass = lookup.lookupClass();
+            this.lookupModes = lookup.lookupModes();
+            assert(lookupString().equals(lookup.toString()));
+            numberOf(lookupClass().getClassLoader()); // assign CL#
+        }
+        public LookupCase(Class lookupClass, int lookupModes) {
+            this.lookup = null;
+            this.lookupClass = lookupClass;
+            this.lookupModes = lookupModes;
+            numberOf(lookupClass().getClassLoader()); // assign CL#
+        }
+
+        public final Class lookupClass() { return lookupClass; }
+        public final int      lookupModes() { return lookupModes; }
+
+        public Lookup lookup() { lookup.getClass(); return lookup; }
+
+        @Override
+        public int compareTo(LookupCase that) {
+            Class c1 = this.lookupClass();
+            Class c2 = that.lookupClass();
+            if (c1 != c2) {
+                int cmp = c1.getName().compareTo(c2.getName());
+                if (cmp != 0)  return cmp;
+                cmp = numberOf(c1.getClassLoader()) - numberOf(c2.getClassLoader());
+                assert(cmp != 0);
+                return cmp;
+            }
+            return -(this.lookupModes() - that.lookupModes());
+        }
+
+        @Override
+        public boolean equals(Object that) {
+            return (that instanceof LookupCase && equals((LookupCase)that));
+        }
+        public boolean equals(LookupCase that) {
+            return (this.lookupClass() == that.lookupClass() &&
+                    this.lookupModes() == that.lookupModes());
+        }
+
+        @Override
+        public int hashCode() {
+            return lookupClass().hashCode() + (lookupModes() * 31);
+        }
+
+        /** Simulate all assertions in the spec. for Lookup.toString. */
+        private String lookupString() {
+            String name = lookupClass.getName();
+            String suffix = "";
+            if (lookupModes == 0)
+                suffix = "/noaccess";
+            else if (lookupModes == PUBLIC)
+                suffix = "/public";
+            else if (lookupModes == (PUBLIC|PACKAGE))
+                suffix = "/package";
+            else if (lookupModes == (PUBLIC|PACKAGE|PRIVATE))
+                suffix = "/private";
+            else if (lookupModes == (PUBLIC|PACKAGE|PRIVATE|PROTECTED))
+                suffix = "";
+            else
+                suffix = "/#"+Integer.toHexString(lookupModes);
+            return name+suffix;
+        }
+
+        /** Simulate all assertions from the spec. for Lookup.in:
+         * 
+ * Creates a lookup on the specified new lookup class. + * [A1] The resulting object will report the specified + * class as its own {@link #lookupClass lookupClass}. + *

+ * [A2] However, the resulting {@code Lookup} object is guaranteed + * to have no more access capabilities than the original. + * In particular, access capabilities can be lost as follows:

    + *
  • [A3] If the new lookup class differs from the old one, + * protected members will not be accessible by virtue of inheritance. + * (Protected members may continue to be accessible because of package sharing.) + *
  • [A4] If the new lookup class is in a different package + * than the old one, protected and default (package) members will not be accessible. + *
  • [A5] If the new lookup class is not within the same package member + * as the old one, private members will not be accessible. + *
  • [A6] If the new lookup class is not accessible to the old lookup class, + * using the original access modes, + * then no members, not even public members, will be accessible. + * [A7] (In all other cases, public members will continue to be accessible.) + *
+ * Other than the above cases, the new lookup will have the same + * access capabilities as the original. [A8] + *
+ */ + public LookupCase in(Class c2) { + Class c1 = lookupClass(); + int m1 = lookupModes(); + int changed = 0; + boolean samePackage = (c1.getClassLoader() == c2.getClassLoader() && + packagePrefix(c1).equals(packagePrefix(c2))); + boolean sameTopLevel = (topLevelClass(c1) == topLevelClass(c2)); + boolean sameClass = (c1 == c2); + assert(samePackage || !sameTopLevel); + assert(sameTopLevel || !sameClass); + boolean accessible = sameClass; // [A6] + if ((m1 & PACKAGE) != 0) accessible |= samePackage; + if ((m1 & PUBLIC ) != 0) accessible |= (c2.getModifiers() & PUBLIC) != 0; + if (!accessible) { + // Different package and no access to c2; lose all access. + changed |= (PUBLIC|PACKAGE|PRIVATE|PROTECTED); // [A6] + } + if (!samePackage) { + // Different package; lose PACKAGE and lower access. + changed |= (PACKAGE|PRIVATE|PROTECTED); // [A4] + } + if (!sameTopLevel) { + // Different top-level class. Lose PRIVATE and lower access. + changed |= (PRIVATE|PROTECTED); // [A5] + } + if (!sameClass) { + changed |= (PROTECTED); // [A3] + } else { + assert(changed == 0); // [A8] (no deprivation if same class) + } + if (accessible) assert((changed & PUBLIC) == 0); // [A7] + int m2 = m1 & ~changed; + LookupCase l2 = new LookupCase(c2, m2); + assert(l2.lookupClass() == c2); // [A1] + assert((m1 | m2) == m1); // [A2] (no elevation of access) + return l2; + } + + @Override + public String toString() { + String s = lookupClass().getSimpleName(); + String lstr = lookupString(); + int sl = lstr.indexOf('/'); + if (sl >= 0) s += lstr.substring(sl); + ClassLoader cld = lookupClass().getClassLoader(); + if (cld != THIS_LOADER) s += "/loader#"+numberOf(cld); + return s; + } + + /** Predict the success or failure of accessing this method. */ + public boolean willAccess(Method m) { + Class c1 = lookupClass(); + Class c2 = m.getDeclaringClass(); + LookupCase lc = this.in(c2); + int m1 = lc.lookupModes(); + int m2 = fixMods(m.getModifiers()); + // privacy is strictly enforced on lookups + if (c1 != c2) m1 &= ~PRIVATE; + // protected access is sometimes allowed + if ((m2 & PROTECTED) != 0) { + int prev = m2; + m2 |= PACKAGE; // it acts like a package method also + if ((lookupModes() & PROTECTED) != 0 && + c2.isAssignableFrom(c1)) + m2 |= PUBLIC; // from a subclass, it acts like a public method also + } + if (verbosity >= 2) + System.out.println(this+" willAccess "+lc+" m1="+m1+" m2="+m2+" => "+((m2 & m1) != 0)); + return (m2 & m1) != 0; + } + } + + private static Class topLevelClass(Class cls) { + Class c = cls; + for (Class ec; (ec = c.getEnclosingClass()) != null; ) + c = ec; + assert(c.getEnclosingClass() == null); + assert(c == cls || cls.getEnclosingClass() != null); + return c; + } + + private static String packagePrefix(Class c) { + while (c.isArray()) c = c.getComponentType(); + String s = c.getName(); + assert(s.indexOf('/') < 0); + return s.substring(0, s.lastIndexOf('.')+1); + } + + + private final TreeSet CASES = new TreeSet<>(); + private final TreeMap> CASE_EDGES = new TreeMap<>(); + private final ArrayList LOADERS = new ArrayList<>(); + private final ClassLoader THIS_LOADER = this.getClass().getClassLoader(); + { if (THIS_LOADER != null) LOADERS.add(THIS_LOADER); } // #1 + + private LookupCase lookupCase(String name) { + for (LookupCase lc : CASES) { + if (lc.toString().equals(name)) + return lc; + } + throw new AssertionError(name); + } + + private int numberOf(ClassLoader cl) { + if (cl == null) return 0; + int i = LOADERS.indexOf(cl); + if (i < 0) { + i = LOADERS.size(); + LOADERS.add(cl); + } + return i+1; + } + + private void addLookupEdge(LookupCase l1, Class c2, LookupCase l2) { + TreeSet edges = CASE_EDGES.get(l2); + if (edges == null) CASE_EDGES.put(l2, edges = new TreeSet<>()); + if (edges.add(l1)) { + Class c1 = l1.lookupClass(); + assert(l2.lookupClass() == c2); // [A1] + int m1 = l1.lookupModes(); + int m2 = l2.lookupModes(); + assert((m1 | m2) == m1); // [A2] (no elevation of access) + LookupCase expect = l1.in(c2); + if (!expect.equals(l2)) + System.out.println("*** expect "+l1+" => "+expect+" but got "+l2); + assertEquals(expect, l2); + } + } + + private void makeCases(Lookup[] originalLookups) { + // make initial set of lookup test cases + CASES.clear(); LOADERS.clear(); CASE_EDGES.clear(); + ArrayList> classes = new ArrayList<>(); + for (Lookup l : originalLookups) { + CASES.add(new LookupCase(l)); + classes.remove(l.lookupClass()); // no dups please + classes.add(l.lookupClass()); + } + System.out.println("loaders = "+LOADERS); + int rounds = 0; + for (int lastCount = -1; lastCount != CASES.size(); ) { + lastCount = CASES.size(); // if CASES grow in the loop we go round again + for (LookupCase lc1 : CASES.toArray(new LookupCase[0])) { + for (Class c2 : classes) { + LookupCase lc2 = new LookupCase(lc1.lookup().in(c2)); + addLookupEdge(lc1, c2, lc2); + CASES.add(lc2); + } + } + rounds++; + } + System.out.println("filled in "+CASES.size()+" cases from "+originalLookups.length+" original cases in "+rounds+" rounds"); + if (false) { + System.out.println("CASES: {"); + for (LookupCase lc : CASES) { + System.out.println(lc); + Set edges = CASE_EDGES.get(lc); + if (edges != null) + for (LookupCase prev : edges) { + System.out.println("\t"+prev); + } + } + System.out.println("}"); + } + } + + @Test public void test() { + makeCases(lookups()); + if (verbosity > 0) { + verbosity += 9; + Method pro_in_self = targetMethod(THIS_CLASS, PROTECTED, methodType(void.class)); + testOneAccess(lookupCase("AccessControlTest/public"), pro_in_self, "find"); + testOneAccess(lookupCase("Remote_subclass/public"), pro_in_self, "find"); + testOneAccess(lookupCase("Remote_subclass"), pro_in_self, "find"); + verbosity -= 9; + } + Set> targetClassesDone = new HashSet<>(); + for (LookupCase targetCase : CASES) { + Class targetClass = targetCase.lookupClass(); + if (!targetClassesDone.add(targetClass)) continue; // already saw this one + String targetPlace = placeName(targetClass); + if (targetPlace == null) continue; // Object, String, not a target + for (int targetAccess : ACCESS_CASES) { + MethodType methodType = methodType(void.class); + Method method = targetMethod(targetClass, targetAccess, methodType); + // Try to access target method from various contexts. + for (LookupCase sourceCase : CASES) { + testOneAccess(sourceCase, method, "find"); + testOneAccess(sourceCase, method, "unreflect"); + } + } + } + System.out.println("tested "+testCount+" access scenarios; "+testCountFails+" accesses were denied"); + } + + private int testCount, testCountFails; + + private void testOneAccess(LookupCase sourceCase, Method method, String kind) { + Class targetClass = method.getDeclaringClass(); + String methodName = method.getName(); + MethodType methodType = methodType(method.getReturnType(), method.getParameterTypes()); + boolean willAccess = sourceCase.willAccess(method); + boolean didAccess = false; + ReflectiveOperationException accessError = null; + try { + switch (kind) { + case "find": + if ((method.getModifiers() & Modifier.STATIC) != 0) + sourceCase.lookup().findStatic(targetClass, methodName, methodType); + else + sourceCase.lookup().findVirtual(targetClass, methodName, methodType); + break; + case "unreflect": + sourceCase.lookup().unreflect(method); + break; + default: + throw new AssertionError(kind); + } + didAccess = true; + } catch (ReflectiveOperationException ex) { + accessError = ex; + } + if (willAccess != didAccess) { + System.out.println(sourceCase+" => "+targetClass.getSimpleName()+"."+methodName+methodType); + System.out.println("fail on "+method+" ex="+accessError); + assertEquals(willAccess, didAccess); + } + testCount++; + if (!didAccess) testCountFails++; + } + + static Method targetMethod(Class targetClass, int targetAccess, MethodType methodType) { + String methodName = accessName(targetAccess)+placeName(targetClass); + if (verbosity >= 2) + System.out.println(targetClass.getSimpleName()+"."+methodName+methodType); + try { + Method method = targetClass.getDeclaredMethod(methodName, methodType.parameterArray()); + assertEquals(method.getReturnType(), methodType.returnType()); + int haveMods = method.getModifiers(); + assert(Modifier.isStatic(haveMods)); + assert(targetAccess == fixMods(haveMods)); + return method; + } catch (NoSuchMethodException ex) { + throw new AssertionError(methodName, ex); + } + } + + static String placeName(Class cls) { + // return "self", "sibling", "nestmate", etc. + if (cls == AccessControlTest.class) return "self"; + String cln = cls.getSimpleName(); + int under = cln.lastIndexOf('_'); + if (under < 0) return null; + return cln.substring(under+1); + } + static String accessName(int acc) { + switch (acc) { + case PUBLIC: return "pub_in_"; + case PROTECTED: return "pro_in_"; + case PACKAGE: return "pkg_in_"; + case PRIVATE: return "pri_in_"; + } + assert(false); + return "?"; + } + private static final int[] ACCESS_CASES = { + PUBLIC, PACKAGE, PRIVATE, PROTECTED + }; + /** Return one of the ACCESS_CASES. */ + static int fixMods(int mods) { + mods &= (PUBLIC|PRIVATE|PROTECTED); + switch (mods) { + case PUBLIC: case PRIVATE: case PROTECTED: return mods; + case 0: return PACKAGE; + } + throw new AssertionError(mods); + } + + static Lookup[] lookups() { + ArrayList tem = new ArrayList<>(); + Collections.addAll(tem, + AccessControlTest.lookup_in_self(), + Inner_nestmate.lookup_in_nestmate(), + AccessControlTest_sibling.lookup_in_sibling()); + if (true) { + Collections.addAll(tem,Acquaintance_remote.lookups()); + } else { + try { + Class remc = Class.forName("test.java.lang.invoke.AccessControlTest_subpkg.Acquaintance_remote"); + Lookup[] remls = (Lookup[]) remc.getMethod("lookups").invoke(null); + Collections.addAll(tem, remls); + } catch (ReflectiveOperationException ex) { + throw new LinkageError("reflection failed", ex); + } + } + tem.add(publicLookup()); + tem.add(publicLookup().in(String.class)); + tem.add(publicLookup().in(List.class)); + return tem.toArray(new Lookup[0]); + } + + static Lookup lookup_in_self() { + return MethodHandles.lookup(); + } + static public void pub_in_self() { } + static protected void pro_in_self() { } + static /*package*/ void pkg_in_self() { } + static private void pri_in_self() { } + + static class Inner_nestmate { + static Lookup lookup_in_nestmate() { + return MethodHandles.lookup(); + } + static public void pub_in_nestmate() { } + static protected void pro_in_nestmate() { } + static /*package*/ void pkg_in_nestmate() { } + static private void pri_in_nestmate() { } + } +} +class AccessControlTest_sibling { + static Lookup lookup_in_sibling() { + return MethodHandles.lookup(); + } + static public void pub_in_sibling() { } + static protected void pro_in_sibling() { } + static /*package*/ void pkg_in_sibling() { } + static private void pri_in_sibling() { } +} + +// This guy tests access from outside the package: +/* +package test.java.lang.invoke.AccessControlTest_subpkg; +public class Acquaintance_remote { + public static Lookup[] lookups() { ... + } + ... +} +*/ diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/lang/invoke/AccessControlTest_subpkg/Acquaintance_remote.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/lang/invoke/AccessControlTest_subpkg/Acquaintance_remote.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,42 @@ +package test.java.lang.invoke.AccessControlTest_subpkg; +import test.java.lang.invoke.AccessControlTest; +import java.lang.invoke.*; +import static java.lang.invoke.MethodHandles.*; + +// This guy tests access from outside the package test.java.lang.invoke: +public class Acquaintance_remote { + public static Lookup[] lookups() { + return new Lookup[] { + Acquaintance_remote.lookup_in_remote(), + Remote_subclass.lookup_in_subclass(), + Remote_hidden.lookup_in_hidden() + }; + } + + public static Lookup lookup_in_remote() { + return MethodHandles.lookup(); + } + static public void pub_in_remote() { } + static protected void pro_in_remote() { } + static /*package*/ void pkg_in_remote() { } + static private void pri_in_remote() { } + + static public class Remote_subclass extends AccessControlTest { + static Lookup lookup_in_subclass() { + return MethodHandles.lookup(); + } + static public void pub_in_subclass() { } + static protected void pro_in_subclass() { } + static /*package*/ void pkg_in_subclass() { } + static private void pri_in_subclass() { } + } + static /*package*/ class Remote_hidden { + static Lookup lookup_in_hidden() { + return MethodHandles.lookup(); + } + static public void pub_in_hidden() { } + static protected void pro_in_hidden() { } + static /*package*/ void pkg_in_hidden() { } + static private void pri_in_hidden() { } + } +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/net/Socket/setReuseAddress/Basic.java --- a/jdk/test/java/net/Socket/setReuseAddress/Basic.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/test/java/net/Socket/setReuseAddress/Basic.java Tue Jun 26 22:47:23 2012 -0700 @@ -26,6 +26,8 @@ * @bug 4476378 * @summary Check the specific behaviour of the setReuseAddress(boolean) * method. + * @run main Basic + * @run main/othervm -Dsun.net.useExclusiveBind Basic */ import java.net.*; @@ -170,7 +172,12 @@ s2.bind( new InetSocketAddress(s1.getLocalPort()) ); passed(); } catch (BindException e) { - failed(); + if (System.getProperty("sun.net.useExclusiveBind") != null) { + // exclusive bind enabled - expected result + passed(); + } else { + failed(); + } } s2.close(); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/net/Socket/setReuseAddress/Restart.java --- a/jdk/test/java/net/Socket/setReuseAddress/Restart.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/test/java/net/Socket/setReuseAddress/Restart.java Tue Jun 26 22:47:23 2012 -0700 @@ -26,6 +26,8 @@ * @bug 4476378 * @summary Check that SO_REUSEADDR allows a server to restart * after a crash. + * @run main Restart + * @run main/othervm -Dsun.net.useExclusiveBind Restart */ import java.net.*; @@ -57,6 +59,12 @@ // close the client socket s1.close(); + } catch (BindException be) { + if (System.getProperty("sun.net.useExclusiveBind") != null) { + // exclusive bind, expected exception + } else { + throw be; + } } finally { if (ss != null) ss.close(); if (s1 != null) s1.close(); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/nio/channels/AsyncCloseAndInterrupt.java --- a/jdk/test/java/nio/channels/AsyncCloseAndInterrupt.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/test/java/nio/channels/AsyncCloseAndInterrupt.java Tue Jun 26 22:47:23 2012 -0700 @@ -644,9 +644,9 @@ initPipes(); initFile(); - if (TestUtil.onME()) { + if (TestUtil.onWindows()) { log.println("WARNING: Cannot test FileChannel transfer operations" - + " on Windows 95/98/ME"); + + " on Windows"); } else { test(diskFileChannelFactory, TRANSFER_TO); test(diskFileChannelFactory, TRANSFER_FROM); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/nio/channels/SocketChannel/AdaptSocket.java --- a/jdk/test/java/nio/channels/SocketChannel/AdaptSocket.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/test/java/nio/channels/SocketChannel/AdaptSocket.java Tue Jun 26 22:47:23 2012 -0700 @@ -28,9 +28,7 @@ import java.io.*; import java.net.*; -import java.nio.*; import java.nio.channels.*; -import java.nio.charset.*; public class AdaptSocket { @@ -136,9 +134,8 @@ out.println("timeout: " + so.getSoTimeout()); testRead(so, shouldTimeout); - if (!TestUtil.onME()) - for (int i = 0; i < 4; i++) - testRead(so, shouldTimeout); + for (int i = 0; i < 4; i++) + testRead(so, shouldTimeout); sc.close(); } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/nio/channels/SocketChannel/CloseDuringWrite.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/nio/channels/SocketChannel/CloseDuringWrite.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,97 @@ +/* + * Copyright (c) 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 + * @summary Test asynchronous close during a blocking write + */ + +import java.io.Closeable; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.*; +import java.net.*; +import java.util.concurrent.*; +import java.util.Random; + +public class CloseDuringWrite { + + static final Random rand = new Random(); + + /** + * A task that closes a Closeable + */ + static class Closer implements Callable { + final Closeable c; + Closer(Closeable c) { + this.c = c; + } + public Void call() throws IOException { + c.close(); + return null; + } + } + + public static void main(String[] args) throws Exception { + ScheduledExecutorService pool = Executors.newSingleThreadScheduledExecutor(); + try { + try (ServerSocketChannel ssc = ServerSocketChannel.open()) { + ssc.bind(new InetSocketAddress(0)); + InetAddress lh = InetAddress.getLocalHost(); + int port = ssc.socket().getLocalPort(); + SocketAddress sa = new InetSocketAddress(lh, port); + + ByteBuffer bb = ByteBuffer.allocate(2*1024*1024); + + for (int i=0; i<20; i++) { + try (SocketChannel source = SocketChannel.open(sa); + SocketChannel sink = ssc.accept()) + { + // schedule channel to be closed + Closer c = new Closer(source); + int when = 1000 + rand.nextInt(2000); + Future result = pool.schedule(c, when, TimeUnit.MILLISECONDS); + + // the write should either succeed or else throw a + // ClosedChannelException (more likely an + // AsynchronousCloseException) + try { + for (;;) { + int limit = rand.nextInt(bb.capacity()); + bb.position(0); + bb.limit(limit); + int n = source.write(bb); + System.out.format("wrote %d, expected %d%n", n, limit); + } + } catch (ClosedChannelException expected) { + System.out.println(expected + " (expected)"); + } finally { + result.get(); + } + } + } + } + } finally { + pool.shutdown(); + } + } +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/nio/channels/SocketChannel/ShortWrite.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/nio/channels/SocketChannel/ShortWrite.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,136 @@ +/* + * Copyright (c) 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 7176630 + * @summary Check for short writes on SocketChannels configured in blocking mode + */ + +import java.net.*; +import java.nio.ByteBuffer; +import java.nio.channels.*; +import java.util.concurrent.*; +import java.util.Random; +import java.util.zip.CRC32; + +public class ShortWrite { + + static final Random rand = new Random(); + + /** + * Returns a checksum on the remaining bytes in the given buffer. + */ + static long computeChecksum(ByteBuffer bb) { + CRC32 crc32 = new CRC32(); + crc32.update(bb); + return crc32.getValue(); + } + + /** + * A task that reads the expected number of bytes and returns the CRC32 + * of those bytes. + */ + static class Reader implements Callable { + final SocketChannel sc; + final ByteBuffer buf; + + Reader(SocketChannel sc, int expectedSize) { + this.sc = sc; + this.buf = ByteBuffer.allocate(expectedSize); + } + + public Long call() throws Exception { + while (buf.hasRemaining()) { + int n = sc.read(buf); + if (n == -1) + throw new RuntimeException("Premature EOF encountered"); + } + buf.flip(); + return computeChecksum(buf); + } + } + + /** + * Run test with a write of the given number of bytes. + */ + static void test(ExecutorService pool, + SocketChannel source, + SocketChannel sink, + int size) + throws Exception + { + System.out.println(size); + + // random bytes in the buffer + ByteBuffer buf = ByteBuffer.allocate(size); + rand.nextBytes(buf.array()); + + // submit task to read the bytes + Future result = pool.submit(new Reader(sink, size)); + + // write the bytes + int n = source.write(buf); + if (n != size) + throw new RuntimeException("Short write detected"); + + // check the bytes that were received match + buf.rewind(); + long expected = computeChecksum(buf); + long actual = result.get(); + if (actual != expected) + throw new RuntimeException("Checksum did not match"); + } + + + public static void main(String[] args) throws Exception { + ExecutorService pool = Executors.newSingleThreadExecutor(); + try { + try (ServerSocketChannel ssc = ServerSocketChannel.open()) { + ssc.bind(new InetSocketAddress(0)); + InetAddress lh = InetAddress.getLocalHost(); + int port = ssc.socket().getLocalPort(); + SocketAddress sa = new InetSocketAddress(lh, port); + + try (SocketChannel source = SocketChannel.open(sa); + SocketChannel sink = ssc.accept()) + { + // run tests on sizes around 128k as that is the problem + // area on Windows. + int BOUNDARY = 128 * 1024; + for (int size=(BOUNDARY-2); size<=(BOUNDARY+2); size++) { + test(pool, source, sink, size); + } + + // run tests on random sizes + for (int i=0; i<20; i++) { + int size = rand.nextInt(1024*1024); + test(pool, source, sink, size); + } + } + } + + } finally { + pool.shutdown(); + } + } +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/nio/channels/TestUtil.java --- a/jdk/test/java/nio/channels/TestUtil.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/test/java/nio/channels/TestUtil.java Tue Jun 26 22:47:23 2012 -0700 @@ -81,20 +81,6 @@ private static String osName = System.getProperty("os.name"); - // Examines os.name property to determine if running on 95/98/ME. - // - // Returns true if running on windows95/98/ME. - // - static boolean onME() { - if (osName.startsWith("Windows")) { - if (osName.indexOf("9") > 0) - return true; - if (osName.indexOf("M") > 0) - return true; - } - return false; - } - static boolean onSolaris() { return osName.startsWith("SunOS"); } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/security/cert/CertPathBuilder/zeroLengthPath/ZeroLengthPath.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/security/cert/CertPathBuilder/zeroLengthPath/ZeroLengthPath.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 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 4442566 7176326 + * @summary check that we can build and validate a zero-length + * certpath when a trust anchor cert satisfies the target constraints + */ +import java.io.ByteArrayInputStream; +import java.security.cert.*; +import java.util.Collections; + +public class ZeroLengthPath { + + private static final String ANCHOR = + "-----BEGIN CERTIFICATE-----\n" + + "MIIBFzCBwgIBATANBgkqhkiG9w0BAQQFADAXMRUwEwYDVQQDEwxUcnVzdCBBbmNo\n" + + "b3IwHhcNMDIxMTA3MTE1NzAzWhcNMjIxMTA3MTE1NzAzWjAXMRUwEwYDVQQDEwxU\n" + + "cnVzdCBBbmNob3IwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA9uCj12hwDgC1n9go\n" + + "0ozQAVMM+DfX0vpKOemyGNp+ycSLfAq3pxBcUKbQhjSRL7YjPkEL8XC6pRLwyEoF\n" + + "osWweQIDAQABMA0GCSqGSIb3DQEBBAUAA0EAzZta5M1qbbozj7jWnNyTgB4HUpzv\n" + + "4eP0VYQb1pQY1/xEMczaRt+RuoIDnHCq5a1vOiwk6ZbdG6GlJKx9lj0oMQ==\n" + + "-----END CERTIFICATE-----"; + + + public static void main(String[] args) throws Exception { + + ByteArrayInputStream is = new ByteArrayInputStream(ANCHOR.getBytes()); + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + X509Certificate cert = (X509Certificate)cf.generateCertificate(is); + + X509CertSelector xcs = new X509CertSelector(); + xcs.setSubject(cert.getSubjectX500Principal().getName()); + PKIXBuilderParameters p = new PKIXBuilderParameters + (Collections.singleton(new TrustAnchor(cert, null)), xcs); + CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX"); + CertPath cp = buildCertPath(cpb, p); + validateCertPath(cp, p); + } + + private static CertPath buildCertPath(CertPathBuilder cpb, + PKIXBuilderParameters params) + throws Exception + { + CertPathBuilderResult res = cpb.build(params); + if (res.getCertPath().getCertificates().size() != 0) { + throw new Exception("built path is not zero-length"); + } + return res.getCertPath(); + } + + private static void validateCertPath(CertPath cp, PKIXParameters params) + throws Exception + { + CertPathValidator cpv = CertPathValidator.getInstance("PKIX"); + CertPathValidatorResult cpvr = cpv.validate(cp, params); + } +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/util/Map/Collisions.java --- a/jdk/test/java/util/Map/Collisions.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/test/java/util/Map/Collisions.java Tue Jun 26 22:47:23 2012 -0700 @@ -68,7 +68,7 @@ return Integer.toString(value); } } - private static final int ITEMS = 10000; + private static final int ITEMS = 5000; private static final Object KEYS[][]; static { @@ -133,8 +133,8 @@ private static void realMain(String[] args) throws Throwable { for (Object[] keys_desc : KEYS) { - Map[] MAPS = (Map[]) new Map[]{ -// new Hashtable<>(), + Map[] MAPS = (Map[]) new Map[]{ + new Hashtable<>(), new HashMap<>(), new IdentityHashMap<>(), new LinkedHashMap<>(), @@ -144,51 +144,69 @@ new ConcurrentSkipListMap<>() }; - for (Map map : MAPS) { + for (Map map : MAPS) { String desc = (String) keys_desc[0]; Object[] keys = (Object[]) keys_desc[1]; + try { testMap(map, desc, keys); + } catch(Exception all) { + unexpected("Failed for " + map.getClass().getName() + " with " + desc, all); + } } } } - private static void testMap(Map map, String keys_desc, T[] keys) { - System.err.println(map.getClass() + " : " + keys_desc); + private static void testMap(Map map, String keys_desc, T[] keys) { + System.out.println(map.getClass() + " : " + keys_desc); + System.out.flush(); testInsertion(map, keys_desc, keys); if (keys[0] instanceof HashableInteger) { - testIntegerIteration((Map) map, (HashableInteger[]) keys); + testIntegerIteration((Map) map, (HashableInteger[]) keys); } else { - testStringIteration((Map) map, (String[]) keys); + testStringIteration((Map) map, (String[]) keys); } testContainsKey(map, keys_desc, keys); testRemove(map, keys_desc, keys); + map.clear(); + testInsertion(map, keys_desc, keys); + testKeysIteratorRemove(map, keys_desc, keys); + + map.clear(); + testInsertion(map, keys_desc, keys); + testValuesIteratorRemove(map, keys_desc, keys); + + map.clear(); + testInsertion(map, keys_desc, keys); + testEntriesIteratorRemove(map, keys_desc, keys); + check(map.isEmpty()); } - private static void testInsertion(Map map, String keys_desc, T[] keys) { + private static void testInsertion(Map map, String keys_desc, T[] keys) { check("map empty", (map.size() == 0) && map.isEmpty()); for (int i = 0; i < keys.length; i++) { check(String.format("insertion: map expected size m%d != i%d", map.size(), i), map.size() == i); - check(String.format("insertion: put(%s[%d])", keys_desc, i), null == map.put(keys[i], true)); + check(String.format("insertion: put(%s[%d])", keys_desc, i), null == map.put(keys[i], keys[i])); check(String.format("insertion: containsKey(%s[%d])", keys_desc, i), map.containsKey(keys[i])); + check(String.format("insertion: containsValue(%s[%d])", keys_desc, i), map.containsValue(keys[i])); } check(String.format("map expected size m%d != k%d", map.size(), keys.length), map.size() == keys.length); } - private static void testIntegerIteration(Map map, HashableInteger[] keys) { + private static void testIntegerIteration(Map map, HashableInteger[] keys) { check(String.format("map expected size m%d != k%d", map.size(), keys.length), map.size() == keys.length); BitSet all = new BitSet(keys.length); - for (Map.Entry each : map.entrySet()) { + for (Map.Entry each : map.entrySet()) { check("Iteration: key already seen", !all.get(each.getKey().value)); all.set(each.getKey().value); } @@ -205,7 +223,7 @@ check("Iteration: some keys not visited", all.isEmpty()); int count = 0; - for (Boolean each : map.values()) { + for (HashableInteger each : map.values()) { count++; } @@ -213,12 +231,12 @@ map.size() == count); } - private static void testStringIteration(Map map, String[] keys) { + private static void testStringIteration(Map map, String[] keys) { check(String.format("map expected size m%d != k%d", map.size(), keys.length), map.size() == keys.length); BitSet all = new BitSet(keys.length); - for (Map.Entry each : map.entrySet()) { + for (Map.Entry each : map.entrySet()) { String key = each.getKey(); boolean longKey = key.length() > 5; int index = key.hashCode() + (longKey ? keys.length / 2 : 0); @@ -240,7 +258,7 @@ check("some keys not visited", all.isEmpty()); int count = 0; - for (Boolean each : map.values()) { + for (String each : map.values()) { count++; } @@ -248,14 +266,14 @@ map.size() == keys.length); } - private static void testContainsKey(Map map, String keys_desc, T[] keys) { + private static void testContainsKey(Map map, String keys_desc, T[] keys) { for (int i = 0; i < keys.length; i++) { T each = keys[i]; check("containsKey: " + keys_desc + "[" + i + "]" + each, map.containsKey(each)); } } - private static void testRemove(Map map, String keys_desc, T[] keys) { + private static void testRemove(Map map, String keys_desc, T[] keys) { check(String.format("remove: map expected size m%d != k%d", map.size(), keys.length), map.size() == keys.length); @@ -267,6 +285,56 @@ check(String.format("remove: map empty. size=%d", map.size()), (map.size() == 0) && map.isEmpty()); } + + private static void testKeysIteratorRemove(Map map, String keys_desc, T[] keys) { + check(String.format("remove: map expected size m%d != k%d", map.size(), keys.length), + map.size() == keys.length); + + Iterator each = map.keySet().iterator(); + while (each.hasNext()) { + T t = each.next(); + each.remove(); + check("not removed: " + each, !map.containsKey(t) ); + } + + check(String.format("remove: map empty. size=%d", map.size()), + (map.size() == 0) && map.isEmpty()); + } + + private static void testValuesIteratorRemove(Map map, String keys_desc, T[] keys) { + check(String.format("remove: map expected size m%d != k%d", map.size(), keys.length), + map.size() == keys.length); + + Iterator each = map.values().iterator(); + while (each.hasNext()) { + T t = each.next(); + each.remove(); + check("not removed: " + each, !map.containsValue(t) ); + } + + check(String.format("remove: map empty. size=%d", map.size()), + (map.size() == 0) && map.isEmpty()); + } + + private static void testEntriesIteratorRemove(Map map, String keys_desc, T[] keys) { + check(String.format("remove: map expected size m%d != k%d", map.size(), keys.length), + map.size() == keys.length); + + Iterator> each = map.entrySet().iterator(); + while (each.hasNext()) { + Map.Entry t = each.next(); + T key = t.getKey(); + T value = t.getValue(); + each.remove(); + check("not removed: " + each, (map instanceof IdentityHashMap) || !map.entrySet().contains(t) ); + check("not removed: " + each, !map.containsKey(key) ); + check("not removed: " + each, !map.containsValue(value)); + } + + check(String.format("remove: map empty. size=%d", map.size()), + (map.size() == 0) && map.isEmpty()); + } + //--------------------- Infrastructure --------------------------- static volatile int passed = 0, failed = 0; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/util/spi/ResourceBundleControlProvider/UserDefaultControlTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/spi/ResourceBundleControlProvider/UserDefaultControlTest.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 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 6959653 + * @summary Test ResourceBundle.Control provided using SPI. + * @build UserDefaultControlTest + * @run shell UserDefaultControlTest.sh + */ + +import java.io.*; +import java.net.*; +import java.util.*; + +public class UserDefaultControlTest { + public static void main(String[] args) { + ResourceBundle rb = ResourceBundle.getBundle("com.foo.XmlRB", Locale.ROOT); + String type = rb.getString("type"); + if (!type.equals("XML")) { + throw new RuntimeException("Root Locale: type: got " + type + + ", expected XML (ASCII)"); + } + + rb = ResourceBundle.getBundle("com.foo.XmlRB", Locale.JAPAN); + type = rb.getString("type"); + // Expect fullwidth "XML" + if (!type.equals("\uff38\uff2d\uff2c")) { + throw new RuntimeException("Locale.JAPAN: type: got " + type + + ", expected \uff38\uff2d\uff2c (fullwidth XML)"); + } + + try { + rb = ResourceBundle.getBundle("com.bar.XmlRB", Locale.JAPAN); + throw new RuntimeException("com.bar.XmlRB test failed."); + } catch (MissingResourceException e) { + // OK + } + } +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/util/spi/ResourceBundleControlProvider/UserDefaultControlTest.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/spi/ResourceBundleControlProvider/UserDefaultControlTest.sh Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,24 @@ +# +# Copyright (c) 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. +# + +${TESTJAVA}/bin/java -Djava.ext.dirs=${TESTSRC} -cp ${TESTCLASSES} UserDefaultControlTest \ No newline at end of file diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/util/spi/ResourceBundleControlProvider/providersrc/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/spi/ResourceBundleControlProvider/providersrc/Makefile Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,63 @@ +# +# Copyright (c) 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. 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. +# + +# +# Makefile for building a ResourceBundleControlProvider jar file for testing. +# +# Usage: make JDK_HOME=... all install +# + +DESTDIR = .. +TMPDIR = tmp +SERVICESDIR = $(TMPDIR)/META-INF/services +TARGETJAR = rbcontrolprovider.jar +BINDIR = $(JDK_HOME)/bin + + +all: $(TARGETJAR) + +install: all + cp $(TARGETJAR) $(DESTDIR) + +SERVICES = java.util.spi.ResourceBundleControlProvider + +FILES_JAVA = UserControlProvider.java \ + UserXMLControl.java + +RESOURCE_FILES = XmlRB.xml \ + XmlRB_ja.xml + +$(TARGETJAR): $(SERVICES) $(FILES_JAVA) $(RESOURCE_FILES) + rm -rf $(TMPDIR) $@ + mkdir -p $(SERVICESDIR) + $(BINDIR)/javac -d $(TMPDIR) $(FILES_JAVA) + cp $(SERVICES) $(SERVICESDIR) + cp $(RESOURCE_FILES) $(TMPDIR)/com/foo + $(BINDIR)/jar cvf $@ -C $(TMPDIR) . + +clean: + rm -rf $(TMPDIR) $(TARGETJAR) + +.PHONY: all install clean diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/util/spi/ResourceBundleControlProvider/providersrc/UserControlProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/spi/ResourceBundleControlProvider/providersrc/UserControlProvider.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 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. 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. + */ + +package com.foo; + +import java.util.ResourceBundle; +import java.util.spi.ResourceBundleControlProvider; + +public class UserControlProvider implements ResourceBundleControlProvider { + static final ResourceBundle.Control XMLCONTROL = new UserXMLControl(); + + public ResourceBundle.Control getControl(String baseName) { + System.out.println(getClass().getName()+".getControl called for " + baseName); + + // Throws a NPE if baseName is null. + if (baseName.startsWith("com.foo.Xml")) { + System.out.println("\treturns " + XMLCONTROL); + return XMLCONTROL; + } + System.out.println("\treturns null"); + return null; + } +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/util/spi/ResourceBundleControlProvider/providersrc/UserXMLControl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/spi/ResourceBundleControlProvider/providersrc/UserXMLControl.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 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. + */ + +package com.foo; + +import java.io.*; +import java.net.*; +import java.util.*; +import static java.util.ResourceBundle.Control.*; + +public class UserXMLControl extends ResourceBundle.Control { + @Override + public List getFormats(String baseName) { + if (baseName == null) { + throw new NullPointerException(); + } + return Arrays.asList("xml"); + } + + @Override + public ResourceBundle newBundle(String baseName, Locale locale, + String format, + ClassLoader loader, + boolean reload) + throws IllegalAccessException, + InstantiationException, IOException { + if (baseName == null || locale == null + || format == null || loader == null) { + throw new NullPointerException(); + } + ResourceBundle bundle = null; + if (format.equals("xml")) { + String bundleName = toBundleName(baseName, locale); + String resourceName = toResourceName(bundleName, format); + URL url = loader.getResource(resourceName); + if (url != null) { + URLConnection connection = url.openConnection(); + if (connection != null) { + if (reload) { + // disable caches if reloading + connection.setUseCaches(false); + } + try (InputStream stream = connection.getInputStream()) { + if (stream != null) { + BufferedInputStream bis = new BufferedInputStream(stream); + bundle = new XMLResourceBundle(bis); + } + } + } + } + } + return bundle; + } + + private static class XMLResourceBundle extends ResourceBundle { + private Properties props; + + XMLResourceBundle(InputStream stream) throws IOException { + props = new Properties(); + props.loadFromXML(stream); + } + + protected Object handleGetObject(String key) { + if (key == null) { + throw new NullPointerException(); + } + return props.get(key); + } + + public Enumeration getKeys() { + // Not implemented + return null; + } + } +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/util/spi/ResourceBundleControlProvider/providersrc/XmlRB.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/spi/ResourceBundleControlProvider/providersrc/XmlRB.xml Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,40 @@ + + + + + + + + + + +]> + + + Test data for UserDefaultControlTest.java + XML + diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/util/spi/ResourceBundleControlProvider/providersrc/XmlRB_ja.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/spi/ResourceBundleControlProvider/providersrc/XmlRB_ja.xml Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,40 @@ + + + + + + + + + + +]> + + + Test data for UserDefaultControlTest.java + XML + diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/util/spi/ResourceBundleControlProvider/providersrc/java.util.spi.ResourceBundleControlProvider --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/spi/ResourceBundleControlProvider/providersrc/java.util.spi.ResourceBundleControlProvider Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,1 @@ +com.foo.UserControlProvider diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/java/util/spi/ResourceBundleControlProvider/rbcontrolprovider.jar Binary file jdk/test/java/util/spi/ResourceBundleControlProvider/rbcontrolprovider.jar has changed diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/javax/swing/JCheckBox/4449413/bug4449413.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JCheckBox/4449413/bug4449413.html Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,17 @@ + + +When the applet starts, you'll see eight controls with black backgrounds. +Four enabled (on the left side) and four disabled (on the right side) +checkboxes and radiobuttons. + +1. If at least one of the controls' check marks is not visible: + the test fails. + +2. Uncheck the "Use Ocean Theme" check box. + If now at least one of the controls' check marks is not visible: + the test fails. + + + + + diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/javax/swing/JCheckBox/4449413/bug4449413.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JCheckBox/4449413/bug4449413.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,111 @@ +/* + * Copyright (c) 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 4449413 + * @summary Tests that checkbox and radiobuttons' check marks are visible when background is black + * @author Ilya Boyandin + * @run applet/manual=yesno bug4449413.html + */ + +import javax.swing.*; +import javax.swing.plaf.metal.*; +import java.awt.event.*; +import java.awt.*; +import sun.awt.OSInfo; + +public class bug4449413 extends JApplet { + + @Override + public void init() { + + try { + + if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) { + UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); + } + + final MetalTheme oceanTheme = (MetalTheme) sun.awt.AppContext.getAppContext().get("currentMetalTheme"); + + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + getContentPane().setLayout(new FlowLayout()); + final JPanel panel = new JPanel(); + + JCheckBox box = new JCheckBox("Use Ocean theme", true); + getContentPane().add(box); + box.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + MetalLookAndFeel.setCurrentTheme(oceanTheme); + } else { + MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()); + } + SwingUtilities.updateComponentTreeUI(panel); + } + }); + + getContentPane().add(panel); + panel.setLayout(new GridLayout(4, 6, 10, 15)); + for (int k = 0; k <= 3; k++) { + for (int j = 1; j >= 0; j--) { + AbstractButton b = createButton(j, k); + panel.add(b); + } + } + } + }); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + static AbstractButton createButton(int enabled, int type) { + AbstractButton b = null; + switch (type) { + case 0: + b = new JRadioButton("RadioButton"); + break; + case 1: + b = new JCheckBox("CheckBox"); + break; + case 2: + b = new JRadioButtonMenuItem("RBMenuItem"); + break; + case 3: + b = new JCheckBoxMenuItem("CBMenuItem"); + break; + } + b.setBackground(Color.black); + b.setForeground(Color.white); + b.setEnabled(enabled == 1); + b.setSelected(true); + return b; + } +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/javax/swing/plaf/synth/7143614/bug7143614.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/plaf/synth/7143614/bug7143614.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,97 @@ +/* + * Copyright (c) 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 7143614 + * @summary Issues with Synth Look&Feel + * @author Pavel Porvatov + */ + +import sun.awt.SunToolkit; + +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicButtonUI; +import javax.swing.plaf.synth.SynthConstants; +import javax.swing.plaf.synth.SynthLookAndFeel; +import java.lang.reflect.Method; + +public class bug7143614 { + private static Method setSelectedUIMethod; + + private static ComponentUI componentUI = new BasicButtonUI(); + + public static void main(String[] args) throws Exception { + setSelectedUIMethod = SynthLookAndFeel.class.getDeclaredMethod("setSelectedUI", ComponentUI.class, + boolean.class, boolean.class, boolean.class, boolean.class); + setSelectedUIMethod.setAccessible(true); + + setSelectedUIMethod.invoke(null, componentUI, true, true, true, true); + + validate(); + + Thread thread = new ThreadInAnotherAppContext(); + + thread.start(); + thread.join(); + + validate(); + + System.out.println("Test bug7143614 passed."); + } + + private static void validate() throws Exception { + Method getSelectedUIMethod = SynthLookAndFeel.class.getDeclaredMethod("getSelectedUI"); + + getSelectedUIMethod.setAccessible(true); + + Method getSelectedUIStateMethod = SynthLookAndFeel.class.getDeclaredMethod("getSelectedUIState"); + + getSelectedUIStateMethod.setAccessible(true); + + if (getSelectedUIMethod.invoke(null) != componentUI) { + throw new RuntimeException("getSelectedUI returns invalid value"); + } + if (((Integer) getSelectedUIStateMethod.invoke(null)).intValue() != + (SynthConstants.SELECTED | SynthConstants.FOCUSED)) { + throw new RuntimeException("getSelectedUIState returns invalid value"); + } + + } + + private static class ThreadInAnotherAppContext extends Thread { + public ThreadInAnotherAppContext() { + super(new ThreadGroup("7143614"), "ThreadInAnotherAppContext"); + } + + public void run() { + SunToolkit.createNewAppContext(); + + try { + setSelectedUIMethod.invoke(null, null, false, false, false, false); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/javax/swing/text/html/parser/Parser/7165725/bug7165725.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/text/html/parser/Parser/7165725/bug7165725.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,305 @@ +/* + * Copyright (c) 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 7165725 + @summary Tests if HTML parser can handle successive script tags in a line + and it does not call false text callback after script tags. + @run main bug7165725 +*/ + +import sun.awt.SunToolkit; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.swing.*; +import javax.swing.text.AbstractDocument.AbstractElement; +import javax.swing.text.AbstractDocument; +import javax.swing.text.Document; +import javax.swing.text.MutableAttributeSet; +import javax.swing.text.html.HTML; +import javax.swing.text.html.HTMLDocument; +import javax.swing.text.html.HTMLEditorKit; +import javax.swing.text.html.parser.ParserDelegator; + +public class bug7165725 extends JFrame { + private static class GoldenElement { + + private String goldenName; + private List goldenChildren; + + GoldenElement(String goldenName, GoldenElement... goldenChildren){ + this.goldenName = goldenName; + if (goldenChildren != null) { + this.goldenChildren = Arrays.asList(goldenChildren); + } else { + this.goldenChildren = new ArrayList<>(); + } + } + + // throws RuntimeException if not ok + public void checkStructureEquivalence(AbstractDocument.AbstractElement elem) { + String name = elem.getName(); + if (!goldenName.equals(name)) { + throw new RuntimeException("Bad structure: expected element name is '" + goldenName + "' but the actual name was '" + name + "'."); + } + int goldenChildCount = goldenChildren.size(); + int childCount = elem.getChildCount(); + if (childCount != goldenChildCount) { + System.out.print("D: children: "); + for (int i = 0; i < childCount; i++) { + System.out.print(" " + elem.getElement(i).getName()); + } + System.out.println(""); + System.out.print("D: goldenChildren: "); + for (GoldenElement ge : goldenChildren) { + System.out.print(" " + ge.goldenName); + } + System.out.println(""); + + throw new RuntimeException("Bad structure: expected child count of element '" + goldenName + "' is '" + goldenChildCount + "' but the actual count was '" + childCount + "'."); + } + for (int i = 0; i < childCount; i++) { + AbstractDocument.AbstractElement nextElem = (AbstractDocument.AbstractElement) elem.getElement(i); + GoldenElement goldenElement = goldenChildren.get(i); + goldenElement.checkStructureEquivalence(nextElem); + } + } + } + + private JEditorPane editorPane; + public void execute(final String urlStr, final GoldenElement goldenElement) throws Exception { + System.out.println(); + System.out.println("***** TEST: " + urlStr + " *****"); + System.out.println(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + try { + editorPane = new JEditorPane(); + editorPane.setEditorKit(new HTMLEditorKit() { + public Document createDefaultDocument() { + AbstractDocument doc = + (AbstractDocument) super.createDefaultDocument(); + doc.setAsynchronousLoadPriority(-1); + return doc; + } + }); + editorPane.setPage(new URL(urlStr)); + } catch (IOException ex) { + throw new RuntimeException("Test failed", ex); + } + editorPane.setEditable(false); + JScrollPane scroller = new JScrollPane(); + JViewport vp = scroller.getViewport(); + vp.add(editorPane); + add(scroller, BorderLayout.CENTER); + setDefaultCloseOperation(EXIT_ON_CLOSE); + setSize(400, 400); + setLocationRelativeTo(null); + setVisible(true); + } + }); + + ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + HTMLDocument doc = (HTMLDocument) editorPane.getDocument(); + doc.dump(System.out); + goldenElement.checkStructureEquivalence((AbstractElement) doc.getDefaultRootElement()); + dispose(); + } + }); + + System.out.println(); + System.out.println("*********************************"); + System.out.println(); + } + + public static void main(String[] args) throws Exception { + + String dirURL = getDirURL(); + + System.out.println("dirURL = " + dirURL); + + new bug7165725().execute(dirURL + "successive-script-tag.html", createSuccessiveScriptTags()); + new bug7165725().execute(dirURL + "false-text-after-script.html", createFalseTextAfterScript()); + + checkByCallbackForSuccessiveScript(); + checkByCallbackForFalseTextAfterScript(); + + System.out.println(); + System.out.println(); + System.out.println("Test passed."); + } + + static String getDirURL() { + return "file:///" + + new File(System.getProperty("test.src", ".")).getAbsolutePath() + + File.separator; + } + + static String getParsedContentOneLine(String path) throws Exception { + File f = new File(path); + FileReader fr = new FileReader(f); + ParserDelegator pd = new ParserDelegator(); + SBParserCallback sbcallback = new SBParserCallback(); + pd.parse(fr, sbcallback, true); + fr.close(); + return sbcallback.getStringOneLine(); + } + + static String getParsedContentOneLine(URL url) throws Exception { + return getParsedContentOneLine(url.getPath()); + } + + static void checkByCallbackForSuccessiveScript() throws Exception { + String content = getParsedContentOneLine(new URL(getDirURL() + "successive-script-tag.html")); + if (!content.matches(".* + + + diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/javax/swing/text/html/parser/Parser/7165725/successive-script-tag.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/text/html/parser/Parser/7165725/successive-script-tag.html Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,8 @@ + + +my title + + + + + diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/sun/misc/JarIndex/JarIndexMergeForClassLoaderTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/misc/JarIndex/JarIndexMergeForClassLoaderTest.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,222 @@ +/* + * Copyright (c) 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 6901992 + * @summary InvalidJarIndexException due to bug in sun.misc.JarIndex.merge() + * Test URLClassLoader usage of the merge method when using indexes + * @author Diego Belfer + */ +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; + +public class JarIndexMergeForClassLoaderTest { + static final String slash = File.separator; + static final String testClassesDir = System.getProperty("test.classes", "."); + static final String jar; + static final boolean debug = true; + static final File tmpFolder = new File(testClassesDir); + + static { + String javaHome = System.getProperty("java.home"); + if (javaHome.endsWith("jre")) { + int index = javaHome.lastIndexOf(slash); + if (index != -1) + javaHome = javaHome.substring(0, index); + } + + jar = javaHome + slash + "bin" + slash + "jar"; + } + + public static void main(String[] args) throws Exception { + // Create the jars file + File jar1 = buildJar1(); + File jar2 = buildJar2(); + File jar3 = buildJar3(); + + // Index jar files in two levels: jar1 -> jar2 -> jar3 + createIndex(jar2.getName(), jar3.getName()); + createIndex(jar1.getName(), jar2.getName()); + + // Get root jar of the URLClassLoader + URL url = jar1.toURI().toURL(); + + URLClassLoader classLoader = new URLClassLoader(new URL[] { url }); + + assertResource(classLoader, "com/jar1/resource.file", "jar1"); + assertResource(classLoader, "com/test/resource1.file", "resource1"); + assertResource(classLoader, "com/jar2/resource.file", "jar2"); + assertResource(classLoader, "com/test/resource2.file", "resource2"); + assertResource(classLoader, "com/test/resource3.file", "resource3"); + + /* + * The following two asserts failed before the fix of the bug 6901992 + */ + // Check that an existing file is found using the merged index + assertResource(classLoader, "com/missing/jar3/resource.file", "jar3"); + // Check that a non existent file in directory which does not contain + // any file is not found and it does not throw InvalidJarIndexException + assertResource(classLoader, "com/missing/nofile", null); + } + + private static File buildJar3() throws FileNotFoundException, IOException { + JarBuilder jar3Builder = new JarBuilder(tmpFolder, "jar3.jar"); + jar3Builder.addResourceFile("com/test/resource3.file", "resource3"); + jar3Builder.addResourceFile("com/missing/jar3/resource.file", "jar3"); + return jar3Builder.build(); + } + + private static File buildJar2() throws FileNotFoundException, IOException { + JarBuilder jar2Builder = new JarBuilder(tmpFolder, "jar2.jar"); + jar2Builder.addResourceFile("com/jar2/resource.file", "jar2"); + jar2Builder.addResourceFile("com/test/resource2.file", "resource2"); + return jar2Builder.build(); + } + + private static File buildJar1() throws FileNotFoundException, IOException { + JarBuilder jar1Builder = new JarBuilder(tmpFolder, "jar1.jar"); + jar1Builder.addResourceFile("com/jar1/resource.file", "jar1"); + jar1Builder.addResourceFile("com/test/resource1.file", "resource1"); + return jar1Builder.build(); + } + + /* create the index */ + static void createIndex(String parentJar, String childJar) { + // ProcessBuilder is used so that the current directory can be set + // to the directory that directly contains the jars. + debug("Running jar to create the index for: " + parentJar + " and " + + childJar); + ProcessBuilder pb = new ProcessBuilder(jar, "-i", parentJar, childJar); + + pb.directory(tmpFolder); + // pd.inheritIO(); + try { + Process p = pb.start(); + if (p.waitFor() != 0) + throw new RuntimeException("jar indexing failed"); + + if (debug && p != null) { + debugStream(p.getInputStream()); + debugStream(p.getErrorStream()); + } + } catch (InterruptedException | IOException x) { + throw new RuntimeException(x); + } + } + + private static void debugStream(InputStream is) throws IOException { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) { + String line; + while ((line = reader.readLine()) != null) { + debug(line); + } + } + } + + private static void assertResource(URLClassLoader classLoader, String file, + String expectedContent) throws IOException { + InputStream fileStream = classLoader.getResourceAsStream(file); + + if (fileStream == null && expectedContent == null) { + return; + } + if (fileStream == null && expectedContent != null) { + throw new RuntimeException( + buildMessage(file, expectedContent, null)); + } + try { + String actualContent = readAsString(fileStream); + + if (fileStream != null && expectedContent == null) { + throw new RuntimeException(buildMessage(file, null, + actualContent)); + } + if (!expectedContent.equals(actualContent)) { + throw new RuntimeException(buildMessage(file, expectedContent, + actualContent)); + } + } finally { + fileStream.close(); + } + } + + private static String buildMessage(String file, String expectedContent, + String actualContent) { + return "Expected: " + expectedContent + " for: " + file + " was: " + + actualContent; + } + + private static String readAsString(InputStream fileStream) + throws IOException { + byte[] buffer = new byte[1024]; + int count, len = 0; + while ((count = fileStream.read(buffer, len, buffer.length-len)) != -1) + len += count; + return new String(buffer, 0, len, "ASCII"); + } + + static void debug(Object message) { + if (debug) + System.out.println(message); + } + + /* + * Helper class for building jar files + */ + public static class JarBuilder { + private JarOutputStream os; + private File jarFile; + + public JarBuilder(File tmpFolder, String jarName) + throws FileNotFoundException, IOException + { + this.jarFile = new File(tmpFolder, jarName); + this.os = new JarOutputStream(new FileOutputStream(jarFile)); + } + + public void addResourceFile(String pathFromRoot, String content) + throws IOException + { + JarEntry entry = new JarEntry(pathFromRoot); + os.putNextEntry(entry); + os.write(content.getBytes("ASCII")); + os.closeEntry(); + } + + public File build() throws IOException { + os.close(); + return jarFile; + } + } +} + diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/sun/misc/JarIndex/JarIndexMergeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/misc/JarIndex/JarIndexMergeTest.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 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 6901992 + * @compile -XDignore.symbol.file JarIndexMergeTest.java + * @run main JarIndexMergeTest + * @summary InvalidJarIndexException due to bug in sun.misc.JarIndex.merge() + * @author Diego Belfer + */ + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.LinkedList; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; +// implementation specific API +import sun.misc.JarIndex; + +public class JarIndexMergeTest { + static final String slash = File.separator; + static final String testClassesDir = System.getProperty("test.classes", "."); + static final File tmpFolder = new File(testClassesDir); + + public static void main(String[] args) throws Exception { + File jar1 = buildJar1(); + File jar2 = buildJar2(); + + JarIndex jarIndex1 = new JarIndex(new String[] { jar1.getAbsolutePath() }); + JarIndex jarIndex2 = new JarIndex(new String[] { jar2.getAbsolutePath() }); + + jarIndex1.merge(jarIndex2, null); + + assertFileResolved(jarIndex2, "com/test1/resource1.file", + jar1.getAbsolutePath()); + assertFileResolved(jarIndex2, "com/test2/resource2.file", + jar2.getAbsolutePath()); + } + + static void assertFileResolved(JarIndex jarIndex2, String file, + String jarName) { + @SuppressWarnings("unchecked") + LinkedList jarLists = (LinkedList)jarIndex2.get(file); + if (jarLists == null || jarLists.size() == 0 || + !jarName.equals(jarLists.get(0))) { + throw new RuntimeException( + "Unexpected result: the merged index must resolve file: " + + file); + } + } + + private static File buildJar1() throws FileNotFoundException, IOException { + JarBuilder jar1Builder = new JarBuilder(tmpFolder, "jar1-merge.jar"); + jar1Builder.addResourceFile("com/test1/resource1.file", "resource1"); + return jar1Builder.build(); + } + + private static File buildJar2() throws FileNotFoundException, IOException { + JarBuilder jar2Builder = new JarBuilder(tmpFolder, "jar2-merge.jar"); + jar2Builder.addResourceFile("com/test2/resource2.file", "resource2"); + return jar2Builder.build(); + } + + /* + * Helper class for building jar files + */ + public static class JarBuilder { + private JarOutputStream os; + private File jarFile; + + public JarBuilder(File tmpFolder, String jarName) + throws FileNotFoundException, IOException + { + this.jarFile = new File(tmpFolder, jarName); + this.os = new JarOutputStream(new FileOutputStream(jarFile)); + } + + public void addResourceFile(String pathFromRoot, String content) + throws IOException + { + JarEntry entry = new JarEntry(pathFromRoot); + os.putNextEntry(entry); + os.write(content.getBytes("ASCII")); + os.closeEntry(); + } + + public File build() throws IOException { + os.close(); + return jarFile; + } + } +} + diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/sun/security/krb5/auto/TcpTimeout.java --- a/jdk/test/sun/security/krb5/auto/TcpTimeout.java Tue Jun 26 15:28:21 2012 -0700 +++ b/jdk/test/sun/security/krb5/auto/TcpTimeout.java Tue Jun 26 22:47:23 2012 -0700 @@ -48,49 +48,60 @@ k.addPrincipalRandKey("krbtgt/" + OneKDC.REALM); // Start two listener that does not communicate, simulate timeout - int p1 = new ServerSocket(0).getLocalPort(); - int p2 = new ServerSocket(0).getLocalPort(); + ServerSocket ss1 = null; + ServerSocket ss2 = null; - FileWriter fw = new FileWriter("alternative-krb5.conf"); + try { + ss1 = new ServerSocket(0); + ss2 = new ServerSocket(0); + int p1 = ss1.getLocalPort(); + int p2 = ss2.getLocalPort(); + + FileWriter fw = new FileWriter("alternative-krb5.conf"); - fw.write("[libdefaults]\n" + - "udp_preference_limit = 1\n" + - "max_retries = 2\n" + - "default_realm = " + OneKDC.REALM + "\n" + - "kdc_timeout = 5000\n"); - fw.write("[realms]\n" + OneKDC.REALM + " = {\n" + - "kdc = " + OneKDC.KDCHOST + ":" + p1 + "\n" + - "kdc = " + OneKDC.KDCHOST + ":" + p2 + "\n" + - "kdc = " + OneKDC.KDCHOST + ":" + p3 + "\n" + - "}\n"); + fw.write("[libdefaults]\n" + + "udp_preference_limit = 1\n" + + "max_retries = 2\n" + + "default_realm = " + OneKDC.REALM + "\n" + + "kdc_timeout = 5000\n"); + fw.write("[realms]\n" + OneKDC.REALM + " = {\n" + + "kdc = " + OneKDC.KDCHOST + ":" + p1 + "\n" + + "kdc = " + OneKDC.KDCHOST + ":" + p2 + "\n" + + "kdc = " + OneKDC.KDCHOST + ":" + p3 + "\n" + + "}\n"); - fw.close(); - System.setProperty("java.security.krb5.conf", "alternative-krb5.conf"); - Config.refresh(); - - System.out.println("Ports opened on " + p1 + ", " + p2 + ", " + p3); + fw.close(); + System.setProperty("java.security.krb5.conf", + "alternative-krb5.conf"); + Config.refresh(); - // The correct behavior should be: - // 5 sec on p1, 5 sec on p1, fail - // 5 sec on p2, 5 sec on p2, fail - // p3 ok, p3 ok again for preauth. - int count = 6; + System.out.println("Ports opened on " + p1 + ", " + p2 + ", " + p3); + + // The correct behavior should be: + // 5 sec on p1, 5 sec on p1, fail + // 5 sec on p2, 5 sec on p2, fail + // p3 ok, p3 ok again for preauth. + int count = 6; + + ByteArrayOutputStream bo = new ByteArrayOutputStream(); + PrintStream oldout = System.out; + System.setOut(new PrintStream(bo)); + Context c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false); + System.setOut(oldout); - ByteArrayOutputStream bo = new ByteArrayOutputStream(); - PrintStream oldout = System.out; - System.setOut(new PrintStream(bo)); - Context c = Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false); - System.setOut(oldout); - - String[] lines = new String(bo.toByteArray()).split("\n"); - for (String line: lines) { - if (line.startsWith(">>> KDCCommunication")) { - System.out.println(line); - count--; + String[] lines = new String(bo.toByteArray()).split("\n"); + for (String line: lines) { + if (line.startsWith(">>> KDCCommunication")) { + System.out.println(line); + count--; + } } - } - if (count != 0) { - throw new Exception("Retry count is " + count + " less"); + if (count != 0) { + throw new Exception("Retry count is " + count + " less"); + } + } finally { + if (ss1 != null) ss1.close(); + if (ss2 != null) ss2.close(); } } } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 jdk/test/sun/security/x509/X509CRLImpl/OrderAndDup.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/security/x509/X509CRLImpl/OrderAndDup.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 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 7143872 + * @summary Improve certificate extension processing + */ +import java.io.ByteArrayInputStream; +import java.math.BigInteger; +import java.security.KeyPairGenerator; +import java.security.cert.CertificateFactory; +import java.security.cert.X509CRLEntry; +import java.util.Date; +import sun.security.util.DerInputStream; +import sun.security.util.DerValue; +import sun.security.x509.*; + +public class OrderAndDup { + public static void main(String[] args) throws Exception { + + // Generate 20 serial numbers with dup and a special order + int count = 20; + BigInteger[] serials = new BigInteger[count]; + for (int i=0; i(directories.keySet()); + allDirs = new java.util.LinkedHashSet(directories.keySet()); } return allDirs; @@ -572,7 +573,7 @@ // Add each of the files if (entryCount > 0) { - directories = new HashMap(); + directories = new LinkedHashMap(); ArrayList entryList = new ArrayList(); int pos = 2; for (int i = 0; i < entryCount; i++) { @@ -867,7 +868,7 @@ if (zipFile.lastModified() != fileStamp) { ret = false; } else { - directories = new HashMap(); + directories = new LinkedHashMap(); int numDirs = raf.readInt(); for (int nDirs = 0; nDirs < numDirs; nDirs++) { int dirNameBytesLen = raf.readInt(); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/jvm/CRTable.java --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/CRTable.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/CRTable.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -31,7 +31,7 @@ import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.List; import com.sun.tools.javac.tree.JCTree.*; -import com.sun.tools.javac.parser.EndPosTable; +import com.sun.tools.javac.tree.EndPosTable; /** This class contains the CharacterRangeTable for some method * and the hashtable for mapping trees or lists of trees to their diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -37,7 +37,7 @@ import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.jvm.Code.*; import com.sun.tools.javac.jvm.Items.*; -import com.sun.tools.javac.parser.EndPosTable; +import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree.*; import static com.sun.tools.javac.code.Flags.*; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/model/JavacElements.java --- a/langtools/src/share/classes/com/sun/tools/javac/model/JavacElements.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/model/JavacElements.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -28,11 +28,14 @@ import java.lang.annotation.Annotation; import java.lang.annotation.Inherited; import java.util.Map; + import javax.lang.model.SourceVersion; import javax.lang.model.element.*; import javax.lang.model.type.DeclaredType; import javax.lang.model.util.Elements; import javax.tools.JavaFileObject; +import static javax.lang.model.util.ElementFilter.methodsIn; + import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.TypeTags; @@ -47,9 +50,7 @@ import com.sun.tools.javac.tree.TreeScanner; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.Name; - import static com.sun.tools.javac.tree.JCTree.Tag.*; -import static javax.lang.model.util.ElementFilter.methodsIn; /** * Utility methods for operating on program elements. @@ -361,7 +362,7 @@ JCCompilationUnit toplevel = treeTop.snd; if (toplevel.docComments == null) return null; - return toplevel.docComments.get(tree); + return toplevel.docComments.getCommentText(tree); } public PackageElement getPackageOf(Element e) { diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/parser/EndPosTable.java --- a/langtools/src/share/classes/com/sun/tools/javac/parser/EndPosTable.java Tue Jun 26 15:28:21 2012 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2011, 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. - */ -package com.sun.tools.javac.parser; - -import com.sun.tools.javac.tree.JCTree; - -/** - * Specifies the methods to access a mappings of syntax trees to end positions. - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own - * risk. This code and its internal interfaces are subject to change - * or deletion without notice.

- */ -public interface EndPosTable { - - /** - * This method will return the end position of a given tree, otherwise a - * Positions.NOPOS will be returned. - * @param tree JCTree - * @return position of the source tree or Positions.NOPOS for non-existent mapping - */ - public int getEndPos(JCTree tree); - - /** - * Give an old tree and a new tree, the old tree will be replaced with - * the new tree, the position of the new tree will be that of the old - * tree. - * not exist. - * @param oldtree a JCTree to be replaced - * @param newtree a JCTree to be replaced with - * @return position of the old tree or Positions.NOPOS for non-existent mapping - */ - public int replaceTree(JCTree oldtree, JCTree newtree); -} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java --- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -571,7 +571,7 @@ reader.scanCommentChar(); } while (reader.ch != CR && reader.ch != LF && reader.bp < reader.buflen); if (reader.bp < reader.buflen) { - comments = addDocReader(comments, processComment(pos, reader.bp, CommentStyle.LINE)); + comments = addComment(comments, processComment(pos, reader.bp, CommentStyle.LINE)); } break; } else if (reader.ch == '*') { @@ -597,7 +597,7 @@ } if (reader.ch == '/') { reader.scanChar(); - comments = addDocReader(comments, processComment(pos, reader.bp, style)); + comments = addComment(comments, processComment(pos, reader.bp, style)); break; } else { lexError(pos, "unclosed.comment"); @@ -693,10 +693,10 @@ } } //where - List addDocReader(List docReaders, Comment docReader) { - return docReaders == null ? - List.of(docReader) : - docReaders.prepend(docReader); + List addComment(List comments, Comment comment) { + return comments == null ? + List.of(comment) : + comments.prepend(comment); } /** Return the position where a lexical error occurred; @@ -780,6 +780,10 @@ return null; } + public int getSourcePos(int pos) { + return -1; + } + public CommentStyle getStyle() { return cs; } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java --- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Jun 26 22:47:23 2012 -0700 @@ -117,7 +117,7 @@ this.allowMethodReferences = source.allowMethodReferences() && fac.options.isSet("allowMethodReferences"); this.keepDocComments = keepDocComments; - docComments = keepDocComments ? new HashMap() : null; + docComments = newDocCommentTable(keepDocComments); this.keepLineMap = keepLineMap; this.errorTree = F.Erroneous(); endPosTable = newEndPosTable(keepEndPositions); @@ -128,6 +128,11 @@ ? new SimpleEndPosTable() : new EmptyEndPosTable(); } + + protected DocCommentTable newDocCommentTable(boolean keepDocComments) { + return keepDocComments ? new SimpleDocCommentTable() : null; + } + /** Switch: Should generics be recognized? */ boolean allowGenerics; @@ -417,21 +422,21 @@ /* ---------- doc comments --------- */ - /** A hashtable to store all documentation comments + /** A table to store all documentation comments * indexed by the tree nodes they refer to. * defined only if option flag keepDocComment is set. */ - private final Map docComments; + private final DocCommentTable docComments; /** Make an entry into docComments hashtable, * provided flag keepDocComments is set and given doc comment is non-null. * @param tree The tree to be used as index in the hashtable * @param dc The doc comment to associate with the tree, or null. */ - void attach(JCTree tree, String dc) { + void attach(JCTree tree, Comment dc) { if (keepDocComments && dc != null) { // System.out.println("doc comment = ");System.out.println(dc);//DEBUG - docComments.put(tree, dc); + docComments.putComment(tree, dc); } } @@ -1858,7 +1863,7 @@ return List.of(parseStatement()); case MONKEYS_AT: case FINAL: { - String dc = token.comment(CommentStyle.JAVADOC); + Comment dc = token.comment(CommentStyle.JAVADOC); JCModifiers mods = modifiersOpt(); if (token.kind == INTERFACE || token.kind == CLASS || @@ -1875,13 +1880,13 @@ } } case ABSTRACT: case STRICTFP: { - String dc = token.comment(CommentStyle.JAVADOC); + Comment dc = token.comment(CommentStyle.JAVADOC); JCModifiers mods = modifiersOpt(); return List.of(classOrInterfaceOrEnumDeclaration(mods, dc)); } case INTERFACE: case CLASS: - String dc = token.comment(CommentStyle.JAVADOC); + Comment dc = token.comment(CommentStyle.JAVADOC); return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc)); case ENUM: case ASSERT: @@ -2418,7 +2423,7 @@ JCExpression type, Name name, boolean reqInit, - String dc, + Comment dc, T vdefs) { vdefs.append(variableDeclaratorRest(pos, mods, type, name, reqInit, dc)); @@ -2434,7 +2439,7 @@ /** VariableDeclarator = Ident VariableDeclaratorRest * ConstantDeclarator = Ident ConstantDeclaratorRest */ - JCVariableDecl variableDeclarator(JCModifiers mods, JCExpression type, boolean reqInit, String dc) { + JCVariableDecl variableDeclarator(JCModifiers mods, JCExpression type, boolean reqInit, Comment dc) { return variableDeclaratorRest(token.pos, mods, type, ident(), reqInit, dc); } @@ -2445,7 +2450,7 @@ * @param dc The documentation comment for the variable declarations, or null. */ JCVariableDecl variableDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name, - boolean reqInit, String dc) { + boolean reqInit, Comment dc) { type = bracketsOpt(type); JCExpression init = null; if (token.kind == EQ) { @@ -2539,7 +2544,7 @@ seenImport = true; defs.append(importDeclaration()); } else { - String docComment = token.comment(CommentStyle.JAVADOC); + Comment docComment = token.comment(CommentStyle.JAVADOC); if (firstTypeDecl && !seenImport && !seenPackage) { docComment = firstToken.comment(CommentStyle.JAVADOC); consumedToplevelDoc = true; @@ -2597,7 +2602,7 @@ /** TypeDeclaration = ClassOrInterfaceOrEnumDeclaration * | ";" */ - JCTree typeDeclaration(JCModifiers mods, String docComment) { + JCTree typeDeclaration(JCModifiers mods, Comment docComment) { int pos = token.pos; if (mods == null && token.kind == SEMI) { nextToken(); @@ -2612,7 +2617,7 @@ * @param mods Any modifiers starting the class or interface declaration * @param dc The documentation comment for the class, or null. */ - JCStatement classOrInterfaceOrEnumDeclaration(JCModifiers mods, String dc) { + JCStatement classOrInterfaceOrEnumDeclaration(JCModifiers mods, Comment dc) { if (token.kind == CLASS) { return classDeclaration(mods, dc); } else if (token.kind == INTERFACE) { @@ -2656,7 +2661,7 @@ * @param mods The modifiers starting the class declaration * @param dc The documentation comment for the class, or null. */ - protected JCClassDecl classDeclaration(JCModifiers mods, String dc) { + protected JCClassDecl classDeclaration(JCModifiers mods, Comment dc) { int pos = token.pos; accept(CLASS); Name name = ident(); @@ -2685,7 +2690,7 @@ * @param mods The modifiers starting the interface declaration * @param dc The documentation comment for the interface, or null. */ - protected JCClassDecl interfaceDeclaration(JCModifiers mods, String dc) { + protected JCClassDecl interfaceDeclaration(JCModifiers mods, Comment dc) { int pos = token.pos; accept(INTERFACE); Name name = ident(); @@ -2708,7 +2713,7 @@ * @param mods The modifiers starting the enum declaration * @param dc The documentation comment for the enum, or null. */ - protected JCClassDecl enumDeclaration(JCModifiers mods, String dc) { + protected JCClassDecl enumDeclaration(JCModifiers mods, Comment dc) { int pos = token.pos; accept(ENUM); Name name = ident(); @@ -2767,7 +2772,7 @@ /** EnumeratorDeclaration = AnnotationsOpt [TypeArguments] IDENTIFIER [ Arguments ] [ "{" ClassBody "}" ] */ JCTree enumeratorDeclaration(Name enumName) { - String dc = token.comment(CommentStyle.JAVADOC); + Comment dc = token.comment(CommentStyle.JAVADOC); int flags = Flags.PUBLIC|Flags.STATIC|Flags.FINAL|Flags.ENUM; if (token.deprecatedFlag()) { flags |= Flags.DEPRECATED; @@ -2856,7 +2861,7 @@ nextToken(); return List.nil(); } else { - String dc = token.comment(CommentStyle.JAVADOC); + Comment dc = token.comment(CommentStyle.JAVADOC); int pos = token.pos; JCModifiers mods = modifiersOpt(); if (token.kind == CLASS || @@ -2936,7 +2941,7 @@ Name name, List typarams, boolean isInterface, boolean isVoid, - String dc) { + Comment dc) { List params = formalParameters(); if (!isVoid) type = bracketsOpt(type); List thrown = List.nil(); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java --- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 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 @@ -62,19 +62,54 @@ @Override protected Comment processComment(int pos, int endPos, CommentStyle style) { char[] buf = reader.getRawCharacters(pos, endPos); - return new JavadocComment(new ColReader(fac, buf, buf.length), style); + return new JavadocComment(new DocReader(fac, buf, buf.length, pos), style); } /** * This is a specialized version of UnicodeReader that keeps track of the - * column position within a given character stream (used for Javadoc processing). + * column position within a given character stream (used for Javadoc processing), + * and which builds a table for mapping positions in the comment string to + * positions in the source file. */ - static class ColReader extends UnicodeReader { + static class DocReader extends UnicodeReader { int col; + int startPos; - ColReader(ScannerFactory fac, char[] input, int inputLength) { + /** + * A buffer for building a table for mapping positions in {@link #sbuf} + * to positions in the source buffer. + * + * The array is organized as a series of pairs of integers: the first + * number in each pair specifies a position in the comment text, + * the second number in each pair specifies the corresponding position + * in the source buffer. The pairs are sorted in ascending order. + * + * Since the mapping function is generally continuous, with successive + * positions in the string corresponding to successive positions in the + * source buffer, the table only needs to record discontinuities in + * the mapping. The values of intermediate positions can be inferred. + * + * Discontinuities may occur in a number of places: when a newline + * is followed by whitespace and asterisks (which are ignored), + * when a tab is expanded into spaces, and when unicode escapes + * are used in the source buffer. + * + * Thus, to find the source position of any position, p, in the comment + * string, find the index, i, of the pair whose string offset + * ({@code pbuf[i] }) is closest to but not greater than p. Then, + * {@code sourcePos(p) = pbuf[i+1] + (p - pbuf[i]) }. + */ + int[] pbuf = new int[128]; + + /** + * The index of the next empty slot in the pbuf buffer. + */ + int pp = 0; + + DocReader(ScannerFactory fac, char[] input, int inputLength, int startPos) { super(fac, input, inputLength); + this.startPos = startPos; } @Override @@ -147,19 +182,43 @@ break; } } + + @Override + public void putChar(char ch, boolean scan) { + // At this point, bp is the position of the current character in buf, + // and sp is the position in sbuf where this character will be put. + // Record a new entry in pbuf if pbuf is empty or if sp and its + // corresponding source position are not equidistant from the + // corresponding values in the latest entry in the pbuf array. + // (i.e. there is a discontinuity in the map function.) + if ((pp == 0) + || (sp - pbuf[pp - 2] != (startPos + bp) - pbuf[pp - 1])) { + if (pp + 1 >= pbuf.length) { + int[] new_pbuf = new int[pbuf.length * 2]; + System.arraycopy(pbuf, 0, new_pbuf, 0, pbuf.length); + pbuf = new_pbuf; + } + pbuf[pp] = sp; + pbuf[pp + 1] = startPos + bp; + pp += 2; + } + super.putChar(ch, scan); + } } - protected class JavadocComment extends JavaTokenizer.BasicComment { + protected class JavadocComment extends JavaTokenizer.BasicComment { /** * Translated and stripped contents of doc comment */ private String docComment = null; + private int[] docPosns = null; - JavadocComment(ColReader comment_reader, CommentStyle cs) { - super(comment_reader, cs); + JavadocComment(DocReader reader, CommentStyle cs) { + super(reader, cs); } + @Override public String getText() { if (!scanned && cs == CommentStyle.JAVADOC) { scanDocComment(); @@ -168,6 +227,33 @@ } @Override + public int getSourcePos(int pos) { + // Binary search to find the entry for which the string index is + // less than pos. Since docPosns is a list of pairs of integers + // we must make sure the index is always even. + // If we find an exact match for pos, the other item in the pair + // gives the source pos; otherwise, compute the source position + // relative to the best match found in the array. + if (pos < 0 || pos >= docComment.length()) + throw new StringIndexOutOfBoundsException(); + if (docPosns == null) + return -1; + int start = 0; + int end = docPosns.length; + while (start < end - 2) { + // find an even index midway between start and end + int index = ((start + end) / 4) * 2; + if (docPosns[index] < pos) + start = index; + else if (docPosns[index] == pos) + return docPosns[index + 1]; + else + end = index; + } + return docPosns[start + 1] + (pos - docPosns[start]); + } + + @Override @SuppressWarnings("fallthrough") protected void scanDocComment() { try { @@ -209,7 +295,8 @@ // whitespace, then it consumes any stars, then it // puts the rest of the line into our buffer. while (comment_reader.bp < comment_reader.buflen) { - + int begin_bp = comment_reader.bp; + char begin_ch = comment_reader.ch; // The wsLoop consumes whitespace from the beginning // of each line. wsLoop: @@ -263,10 +350,10 @@ break outerLoop; } } else if (! firstLine) { - //The current line does not begin with a '*' so we will indent it. - for (int i = 1; i < comment_reader.col; i++) { - comment_reader.putChar(' ', false); - } + // The current line does not begin with a '*' so we will + // treat it as comment + comment_reader.bp = begin_bp; + comment_reader.ch = begin_ch; } // The textLoop processes the rest of the characters // on the line, adding them to our buffer. @@ -334,11 +421,14 @@ // Store the text of the doc comment docComment = comment_reader.chars(); + docPosns = new int[comment_reader.pp]; + System.arraycopy(comment_reader.pbuf, 0, docPosns, 0, docPosns.length); } else { docComment = ""; } } finally { scanned = true; + comment_reader = null; if (docComment != null && docComment.matches("(?sm).*^\\s*@deprecated( |$).*")) { deprecatedFlag = true; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/parser/SimpleDocCommentTable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/src/share/classes/com/sun/tools/javac/parser/SimpleDocCommentTable.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1999, 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. 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. + */ + +package com.sun.tools.javac.parser; + +import java.util.HashMap; +import java.util.Map; + +import com.sun.tools.javac.parser.Tokens.Comment; +import com.sun.tools.javac.tree.DocCommentTable; +import com.sun.tools.javac.tree.JCTree; + + +/** + * + *

This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own risk. + * This code and its internal interfaces are subject to change or + * deletion without notice. + */ +public class SimpleDocCommentTable implements DocCommentTable { + Map table; + + SimpleDocCommentTable() { + table = new HashMap(); + } + + public boolean hasComment(JCTree tree) { + return table.containsKey(tree); + } + + public Comment getComment(JCTree tree) { + return table.get(tree); + } + + public String getCommentText(JCTree tree) { + Comment c = getComment(tree); + return (c == null) ? null : c.getText(); + } + + public void putComment(JCTree tree, Comment c) { + table.put(tree, c); + } + +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/parser/Tokens.java --- a/langtools/src/share/classes/com/sun/tools/javac/parser/Tokens.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/parser/Tokens.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -294,6 +294,7 @@ } String getText(); + int getSourcePos(int index); CommentStyle getStyle(); boolean isDeprecated(); } @@ -371,11 +372,11 @@ * Preserve classic semantics - if multiple javadocs are found on the token * the last one is returned */ - public String comment(Comment.CommentStyle style) { - List readers = getReaders(Comment.CommentStyle.JAVADOC); - return readers.isEmpty() ? + public Comment comment(Comment.CommentStyle style) { + List comments = getComments(Comment.CommentStyle.JAVADOC); + return comments.isEmpty() ? null : - readers.head.getText(); + comments.head; } /** @@ -383,22 +384,22 @@ * javadoc comment attached to this token contains the '@deprecated' string */ public boolean deprecatedFlag() { - for (Comment r : getReaders(Comment.CommentStyle.JAVADOC)) { - if (r.isDeprecated()) { + for (Comment c : getComments(Comment.CommentStyle.JAVADOC)) { + if (c.isDeprecated()) { return true; } } return false; } - private List getReaders(Comment.CommentStyle style) { + private List getComments(Comment.CommentStyle style) { if (comments == null) { return List.nil(); } else { ListBuffer buf = ListBuffer.lb(); - for (Comment r : comments) { - if (r.getStyle() == style) { - buf.add(r); + for (Comment c : comments) { + if (c.getStyle() == style) { + buf.add(c); } } return buf.toList(); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/tree/DocCommentTable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/src/share/classes/com/sun/tools/javac/tree/DocCommentTable.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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. 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. + */ +package com.sun.tools.javac.tree; + +import com.sun.tools.javac.parser.Tokens.Comment; + +/** + * A table giving the doc comment, if any, for any tree node. + * + *

This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own + * risk. This code and its internal interfaces are subject to change + * or deletion without notice. + */ +public interface DocCommentTable { + /** + * Check if a tree node has a corresponding doc comment. + */ + public boolean hasComment(JCTree tree); + + /** + * Get the Comment token containing the doc comment, if any, for a tree node. + */ + public Comment getComment(JCTree tree); + + /** + * Get the plain text of the doc comment, if any, for a tree node. + */ + public String getCommentText(JCTree tree); + + /** + * Set the Comment to be associated with a tree node. + */ + public void putComment(JCTree tree, Comment c); +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/tree/EndPosTable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/src/share/classes/com/sun/tools/javac/tree/EndPosTable.java Tue Jun 26 22:47:23 2012 -0700 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2011, 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. 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. + */ + +package com.sun.tools.javac.tree; + +/** + * Specifies the methods to access a mappings of syntax trees to end positions. + *

This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own + * risk. This code and its internal interfaces are subject to change + * or deletion without notice.

+ */ +public interface EndPosTable { + + /** + * This method will return the end position of a given tree, otherwise a + * Positions.NOPOS will be returned. + * @param tree JCTree + * @return position of the source tree or Positions.NOPOS for non-existent mapping + */ + public int getEndPos(JCTree tree); + + /** + * Give an old tree and a new tree, the old tree will be replaced with + * the new tree, the position of the new tree will be that of the old + * tree. + * not exist. + * @param oldtree a JCTree to be replaced + * @param newtree a JCTree to be replaced with + * @return position of the old tree or Positions.NOPOS for non-existent mapping + */ + public int replaceTree(JCTree oldtree, JCTree newtree); +} diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java --- a/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -25,25 +25,23 @@ package com.sun.tools.javac.tree; +import java.io.IOException; +import java.io.StringWriter; import java.util.*; -import java.io.IOException; -import java.io.StringWriter; import javax.lang.model.element.Modifier; import javax.lang.model.type.TypeKind; import javax.tools.JavaFileObject; -import com.sun.tools.javac.util.*; -import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; -import com.sun.tools.javac.util.List; +import com.sun.source.tree.*; +import com.sun.source.tree.LambdaExpressionTree.BodyKind; +import com.sun.source.tree.MemberReferenceTree.ReferenceMode; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Scope.*; import com.sun.tools.javac.code.Symbol.*; -import com.sun.tools.javac.parser.EndPosTable; -import com.sun.source.tree.*; -import com.sun.source.tree.LambdaExpressionTree.BodyKind; -import com.sun.source.tree.MemberReferenceTree.ReferenceMode; - +import com.sun.tools.javac.util.*; +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; +import com.sun.tools.javac.util.List; import static com.sun.tools.javac.code.BoundKind.*; import static com.sun.tools.javac.tree.JCTree.Tag.*; @@ -491,7 +489,7 @@ public ImportScope namedImportScope; public StarImportScope starImportScope; public Position.LineMap lineMap = null; - public Map docComments = null; + public DocCommentTable docComments = null; public EndPosTable endPositions = null; protected JCCompilationUnit(List packageAnnotations, JCExpression pid, diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/tree/Pretty.java --- a/langtools/src/share/classes/com/sun/tools/javac/tree/Pretty.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/tree/Pretty.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -29,14 +29,12 @@ import java.util.*; import com.sun.source.tree.MemberReferenceTree.ReferenceMode; - +import com.sun.tools.javac.code.*; +import com.sun.tools.javac.code.Symbol.*; +import com.sun.tools.javac.parser.Tokens.Comment; +import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.List; -import com.sun.tools.javac.code.*; - -import com.sun.tools.javac.code.Symbol.*; -import com.sun.tools.javac.tree.JCTree.*; - import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.ANNOTATION; import static com.sun.tools.javac.tree.JCTree.Tag.*; @@ -78,10 +76,10 @@ */ Name enclClassName; - /** A hashtable mapping trees to their documentation comments + /** A table mapping trees to their documentation comments * (can be null) */ - Map docComments = null; + DocCommentTable docComments = null; /** Align code to be indented to left margin. */ @@ -233,7 +231,7 @@ */ public void printDocComment(JCTree tree) throws IOException { if (docComments != null) { - String dc = docComments.get(tree); + String dc = docComments.getCommentText(tree); if (dc != null) { print("/**"); println(); int pos = 0; @@ -480,7 +478,7 @@ public void visitVarDef(JCVariableDecl tree) { try { - if (docComments != null && docComments.get(tree) != null) { + if (docComments != null && docComments.hasComment(tree)) { println(); align(); } printDocComment(tree); diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java --- a/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Tue Jun 26 22:47:23 2012 -0700 @@ -25,15 +25,14 @@ package com.sun.tools.javac.tree; + import com.sun.source.tree.Tree; +import com.sun.tools.javac.code.*; import com.sun.tools.javac.comp.AttrContext; import com.sun.tools.javac.comp.Env; +import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; -import com.sun.tools.javac.code.*; -import com.sun.tools.javac.parser.EndPosTable; -import com.sun.tools.javac.tree.JCTree.*; - import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.tree.JCTree.Tag.*; import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK; @@ -282,6 +281,13 @@ return (lit.typetag == TypeTags.BOT); } + public static String getCommentText(Env env, JCTree tree) { + DocCommentTable docComments = (tree.hasTag(JCTree.Tag.TOPLEVEL)) + ? ((JCCompilationUnit) tree).docComments + : env.toplevel.docComments; + return (docComments == null) ? null : docComments.getCommentText(tree); + } + /** The position of the first statement in a block, or the position of * the block itself if it is empty. */ diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -32,7 +32,7 @@ import javax.tools.JavaFileObject; import com.sun.tools.javac.file.JavacFileManager; -import com.sun.tools.javac.parser.EndPosTable; +import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import static com.sun.tools.javac.util.LayoutCharacters.*; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -35,7 +35,7 @@ import com.sun.tools.javac.api.DiagnosticFormatter; import com.sun.tools.javac.code.Lint.LintCategory; -import com.sun.tools.javac.parser.EndPosTable; +import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javac/util/Log.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -37,7 +37,7 @@ import com.sun.tools.javac.api.DiagnosticFormatter; import com.sun.tools.javac.main.Main; import com.sun.tools.javac.main.Option; -import com.sun.tools.javac.parser.EndPosTable; +import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java --- a/langtools/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -25,14 +25,17 @@ package com.sun.tools.javadoc; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; -import com.sun.tools.javac.util.List; + +import javax.tools.JavaFileObject; + import com.sun.tools.javac.code.Kinds; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.comp.Enter; import com.sun.tools.javac.tree.JCTree.*; -import javax.tools.JavaFileObject; +import com.sun.tools.javac.tree.TreeInfo; +import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; +import com.sun.tools.javac.util.List; /** * Javadoc's own enter phase does a few things above and beyond that @@ -77,7 +80,7 @@ public void visitTopLevel(JCCompilationUnit tree) { super.visitTopLevel(tree); if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) { - String comment = tree.docComments.get(tree); + String comment = TreeInfo.getCommentText(env, tree); docenv.makePackageDoc(tree.packge, comment, tree); } } @@ -87,7 +90,7 @@ super.visitClassDef(tree); if (tree.sym == null) return; if (tree.sym.kind == Kinds.TYP || tree.sym.kind == Kinds.ERR) { - String comment = env.toplevel.docComments.get(tree); + String comment = TreeInfo.getCommentText(env, tree); ClassSymbol c = tree.sym; docenv.makeClassDoc(c, comment, tree, env.toplevel.lineMap); } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/src/share/classes/com/sun/tools/javadoc/JavadocMemberEnter.java --- a/langtools/src/share/classes/com/sun/tools/javadoc/JavadocMemberEnter.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javadoc/JavadocMemberEnter.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -25,13 +25,14 @@ package com.sun.tools.javadoc; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.Position; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Kinds; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.comp.MemberEnter; import com.sun.tools.javac.tree.JCTree.*; +import com.sun.tools.javac.tree.TreeInfo; +import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.Position; /** * Javadoc's own memberEnter phase does a few things above and beyond that @@ -61,11 +62,12 @@ docenv = DocEnv.instance(context); } + @Override public void visitMethodDef(JCMethodDecl tree) { super.visitMethodDef(tree); MethodSymbol meth = tree.sym; if (meth == null || meth.kind != Kinds.MTH) return; - String docComment = env.toplevel.docComments.get(tree); + String docComment = TreeInfo.getCommentText(env, tree); Position.LineMap lineMap = env.toplevel.lineMap; if (meth.isConstructor()) docenv.makeConstructorDoc(meth, docComment, tree, lineMap); @@ -75,12 +77,13 @@ docenv.makeMethodDoc(meth, docComment, tree, lineMap); } + @Override public void visitVarDef(JCVariableDecl tree) { super.visitVarDef(tree); if (tree.sym != null && tree.sym.kind == Kinds.VAR && !isParameter(tree.sym)) { - String docComment = env.toplevel.docComments.get(tree); + String docComment = TreeInfo.getCommentText(env, tree); Position.LineMap lineMap = env.toplevel.lineMap; docenv.makeFieldDoc(tree.sym, docComment, tree, lineMap); } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/test/tools/javac/6304921/TestLog.java --- a/langtools/test/tools/javac/6304921/TestLog.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/test/tools/javac/6304921/TestLog.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -33,9 +33,9 @@ import javax.tools.JavaFileObject; import javax.tools.SimpleJavaFileObject; import com.sun.tools.javac.file.JavacFileManager; -import com.sun.tools.javac.parser.EndPosTable; import com.sun.tools.javac.parser.Parser; import com.sun.tools.javac.parser.ParserFactory; +import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.TreeScanner; import com.sun.tools.javac.util.Context; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/test/tools/javac/failover/CheckAttributedTree.java --- a/langtools/test/tools/javac/failover/CheckAttributedTree.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/test/tools/javac/failover/CheckAttributedTree.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -68,7 +68,7 @@ import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.parser.EndPosTable; +import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.tree.JCTree.JCImport; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/test/tools/javac/parser/JavacParserTest.java --- a/langtools/test/tools/javac/parser/JavacParserTest.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/test/tools/javac/parser/JavacParserTest.java Tue Jun 26 22:47:23 2012 -0700 @@ -23,7 +23,7 @@ /* * @test - * @bug 7073631 7159445 + * @bug 7073631 7159445 7156633 * @summary tests error and diagnostics positions * @author Jan Lahoda */ @@ -49,11 +49,17 @@ import com.sun.tools.javac.api.JavacTaskImpl; import com.sun.tools.javac.tree.JCTree; import java.io.IOException; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Method; import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; +import java.util.regex.Pattern; import javax.tools.Diagnostic; import javax.tools.DiagnosticCollector; import javax.tools.DiagnosticListener; @@ -63,13 +69,15 @@ import javax.tools.ToolProvider; public class JavacParserTest extends TestCase { - final JavaCompiler tool; - public JavacParserTest(String testName) { - tool = ToolProvider.getSystemJavaCompiler(); - System.out.println("java.home=" + System.getProperty("java.home")); + static final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); + + private JavacParserTest(){} + + public static void main(String... args) throws Exception { + new JavacParserTest().run(args); } - static class MyFileObject extends SimpleJavaFileObject { + class MyFileObject extends SimpleJavaFileObject { private String text; @@ -86,11 +94,11 @@ /* * converts Windows to Unix style LFs for comparing strings */ - private String normalize(String in) { + String normalize(String in) { return in.replace(System.getProperty("line.separator"), "\n"); } - public CompilationUnitTree getCompilationUnitTree(String code) throws IOException { + CompilationUnitTree getCompilationUnitTree(String code) throws IOException { JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); @@ -98,7 +106,7 @@ return cut; } - public List getErroneousTreeValues(ErroneousTree node) { + List getErroneousTreeValues(ErroneousTree node) { List values = new ArrayList<>(); if (node.getErrorTrees() != null) { @@ -112,7 +120,8 @@ return values; } - public void testPositionForSuperConstructorCalls() throws IOException { + @Test + void testPositionForSuperConstructorCalls() throws IOException { assert tool != null; String code = "package test; public class Test {public Test() {super();}}"; @@ -149,12 +158,12 @@ methodStartPos, pos.getStartPosition(cut, mit.getMethodSelect())); assertEquals("testPositionForSuperConstructorCalls", methodEndPos, pos.getEndPosition(cut, mit.getMethodSelect())); - } - public void testPositionForEnumModifiers() throws IOException { - - String code = "package test; public enum Test {A;}"; + @Test + void testPositionForEnumModifiers() throws IOException { + final String theString = "public"; + String code = "package test; " + theString + " enum Test {A;}"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); @@ -163,19 +172,21 @@ ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); ModifiersTree mt = clazz.getModifiers(); - + int spos = code.indexOf(theString); + int epos = spos + theString.length(); assertEquals("testPositionForEnumModifiers", - 38 - 24, pos.getStartPosition(cut, mt)); + spos, pos.getStartPosition(cut, mt)); assertEquals("testPositionForEnumModifiers", - 44 - 24, pos.getEndPosition(cut, mt)); + epos, pos.getEndPosition(cut, mt)); } - public void testNewClassWithEnclosing() throws IOException { + @Test + void testNewClassWithEnclosing() throws IOException { - + final String theString = "Test.this.new d()"; String code = "package test; class Test { " + "class d {} private void method() { " + - "Object o = Test.this.new d(); } }"; + "Object o = " + theString + "; } }"; JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, null, Arrays.asList(new MyFileObject(code))); @@ -186,13 +197,16 @@ ExpressionTree est = ((VariableTree) ((MethodTree) clazz.getMembers().get(1)).getBody().getStatements().get(0)).getInitializer(); + final int spos = code.indexOf(theString); + final int epos = spos + theString.length(); assertEquals("testNewClassWithEnclosing", - 97 - 24, pos.getStartPosition(cut, est)); + spos, pos.getStartPosition(cut, est)); assertEquals("testNewClassWithEnclosing", - 114 - 24, pos.getEndPosition(cut, est)); + epos, pos.getEndPosition(cut, est)); } - public void testPreferredPositionForBinaryOp() throws IOException { + @Test + void testPreferredPositionForBinaryOp() throws IOException { String code = "package test; public class Test {" + "private void test() {" @@ -211,7 +225,581 @@ condStartPos, condJC.pos); } - public void testPositionBrokenSource126732a() throws IOException { + @Test + void testErrorRecoveryForEnhancedForLoop142381() throws IOException { + + String code = "package test; class Test { " + + "private void method() { " + + "java.util.Set s = null; for (a : s) {} } }"; + + final List> errors = + new LinkedList>(); + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, + new DiagnosticListener() { + public void report(Diagnostic diagnostic) { + errors.add(diagnostic); + } + }, null, null, Arrays.asList(new MyFileObject(code))); + + CompilationUnitTree cut = ct.parse().iterator().next(); + + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); + StatementTree forStatement = + ((MethodTree) clazz.getMembers().get(0)).getBody().getStatements().get(1); + + assertEquals("testErrorRecoveryForEnhancedForLoop142381", + Kind.ENHANCED_FOR_LOOP, forStatement.getKind()); + assertFalse("testErrorRecoveryForEnhancedForLoop142381", errors.isEmpty()); + } + + @Test + void testPositionAnnotationNoPackage187551() throws IOException { + + String code = "\n@interface Test {}"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + + CompilationUnitTree cut = ct.parse().iterator().next(); + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); + Trees t = Trees.instance(ct); + + assertEquals("testPositionAnnotationNoPackage187551", + 1, t.getSourcePositions().getStartPosition(cut, clazz)); + } + + @Test + void testPositionsSane1() throws IOException { + performPositionsSanityTest("package test; class Test { " + + "private void method() { " + + "java.util.List> l; " + + "} }"); + } + + @Test + void testPositionsSane2() throws IOException { + performPositionsSanityTest("package test; class Test { " + + "private void method() { " + + "java.util.List> l; " + + "} }"); + } + + @Test + void testPositionsSane3() throws IOException { + performPositionsSanityTest("package test; class Test { " + + "private void method() { " + + "java.util.List> l; } }"); + } + + private void performPositionsSanityTest(String code) throws IOException { + + final List> errors = + new LinkedList>(); + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, + new DiagnosticListener() { + + public void report(Diagnostic diagnostic) { + errors.add(diagnostic); + } + }, null, null, Arrays.asList(new MyFileObject(code))); + + final CompilationUnitTree cut = ct.parse().iterator().next(); + final Trees trees = Trees.instance(ct); + + new TreeScanner() { + + private long parentStart = 0; + private long parentEnd = Integer.MAX_VALUE; + + @Override + public Void scan(Tree node, Void p) { + if (node == null) { + return null; + } + + long start = trees.getSourcePositions().getStartPosition(cut, node); + + if (start == (-1)) { + return null; // synthetic tree + } + assertTrue(node.toString() + ":" + start + "/" + parentStart, + parentStart <= start); + + long prevParentStart = parentStart; + + parentStart = start; + + long end = trees.getSourcePositions().getEndPosition(cut, node); + + assertTrue(node.toString() + ":" + end + "/" + parentEnd, + end <= parentEnd); + + long prevParentEnd = parentEnd; + + parentEnd = end; + + super.scan(node, p); + + parentStart = prevParentStart; + parentEnd = prevParentEnd; + + return null; + } + + private void assertTrue(String message, boolean b) { + if (!b) fail(message); + } + }.scan(cut, null); + } + + @Test + void testCorrectWilcardPositions1() throws IOException { + performWildcardPositionsTest("package test; import java.util.List; " + + "class Test { private void method() { List> l; } }", + + Arrays.asList("List> l;", + "List>", + "List", + "? extends List", + "List", + "List", + "? extends String", + "String")); + } + + @Test + void testCorrectWilcardPositions2() throws IOException { + performWildcardPositionsTest("package test; import java.util.List; " + + "class Test { private void method() { List> l; } }", + Arrays.asList("List> l;", + "List>", + "List", + "? super List", + "List", + "List", + "? super String", + "String")); + } + + @Test + void testCorrectWilcardPositions3() throws IOException { + performWildcardPositionsTest("package test; import java.util.List; " + + "class Test { private void method() { List> l; } }", + + Arrays.asList("List> l;", + "List>", + "List", + "? super List", + "List", + "List", + "?")); + } + + @Test + void testCorrectWilcardPositions4() throws IOException { + performWildcardPositionsTest("package test; import java.util.List; " + + "class Test { private void method() { " + + "List>> l; } }", + + Arrays.asList("List>> l;", + "List>>", + "List", + "? extends List>", + "List>", + "List", + "? extends List", + "List", + "List", + "? extends String", + "String")); + } + + @Test + void testCorrectWilcardPositions5() throws IOException { + performWildcardPositionsTest("package test; import java.util.List; " + + "class Test { private void method() { " + + "List>> l; } }", + Arrays.asList("List>> l;", + "List>>", + "List", + "? extends List>", + "List>", + "List", + "? extends List", + "List", + "List", + "? extends String", + "String")); + } + + void performWildcardPositionsTest(final String code, + List golden) throws IOException { + + final List> errors = + new LinkedList>(); + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, + new DiagnosticListener() { + public void report(Diagnostic diagnostic) { + errors.add(diagnostic); + } + }, null, null, Arrays.asList(new MyFileObject(code))); + + final CompilationUnitTree cut = ct.parse().iterator().next(); + final List content = new LinkedList(); + final Trees trees = Trees.instance(ct); + + new TreeScanner() { + @Override + public Void scan(Tree node, Void p) { + if (node == null) { + return null; + } + long start = trees.getSourcePositions().getStartPosition(cut, node); + + if (start == (-1)) { + return null; // synthetic tree + } + long end = trees.getSourcePositions().getEndPosition(cut, node); + String s = code.substring((int) start, (int) end); + content.add(s); + + return super.scan(node, p); + } + }.scan(((MethodTree) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0)).getBody().getStatements().get(0), null); + + assertEquals("performWildcardPositionsTest",golden.toString(), + content.toString()); + } + + @Test + void testStartPositionForMethodWithoutModifiers() throws IOException { + + String code = "package t; class Test { void t() {} }"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + CompilationUnitTree cut = ct.parse().iterator().next(); + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); + MethodTree mt = (MethodTree) clazz.getMembers().get(0); + Trees t = Trees.instance(ct); + int start = (int) t.getSourcePositions().getStartPosition(cut, mt); + int end = (int) t.getSourcePositions().getEndPosition(cut, mt); + + assertEquals("testStartPositionForMethodWithoutModifiers", + " void t() {}", code.substring(start, end)); + } + + @Test + void testVariableInIfThen1() throws IOException { + + String code = "package t; class Test { " + + "private static void t(String name) { " + + "if (name != null) String nn = name.trim(); } }"; + + DiagnosticCollector coll = + new DiagnosticCollector(); + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, + null, Arrays.asList(new MyFileObject(code))); + + ct.parse(); + + List codes = new LinkedList(); + + for (Diagnostic d : coll.getDiagnostics()) { + codes.add(d.getCode()); + } + + assertEquals("testVariableInIfThen1", + Arrays.asList("compiler.err.variable.not.allowed"), + codes); + } + + @Test + void testVariableInIfThen2() throws IOException { + + String code = "package t; class Test { " + + "private static void t(String name) { " + + "if (name != null) class X {} } }"; + DiagnosticCollector coll = + new DiagnosticCollector(); + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, + null, Arrays.asList(new MyFileObject(code))); + + ct.parse(); + + List codes = new LinkedList(); + + for (Diagnostic d : coll.getDiagnostics()) { + codes.add(d.getCode()); + } + + assertEquals("testVariableInIfThen2", + Arrays.asList("compiler.err.class.not.allowed"), codes); + } + + @Test + void testVariableInIfThen3() throws IOException { + + String code = "package t; class Test { "+ + "private static void t() { " + + "if (true) abstract class F {} }}"; + DiagnosticCollector coll = + new DiagnosticCollector(); + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, + null, Arrays.asList(new MyFileObject(code))); + + ct.parse(); + + List codes = new LinkedList(); + + for (Diagnostic d : coll.getDiagnostics()) { + codes.add(d.getCode()); + } + + assertEquals("testVariableInIfThen3", + Arrays.asList("compiler.err.class.not.allowed"), codes); + } + + @Test + void testVariableInIfThen4() throws IOException { + + String code = "package t; class Test { "+ + "private static void t(String name) { " + + "if (name != null) interface X {} } }"; + DiagnosticCollector coll = + new DiagnosticCollector(); + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, + null, Arrays.asList(new MyFileObject(code))); + + ct.parse(); + + List codes = new LinkedList(); + + for (Diagnostic d : coll.getDiagnostics()) { + codes.add(d.getCode()); + } + + assertEquals("testVariableInIfThen4", + Arrays.asList("compiler.err.class.not.allowed"), codes); + } + + @Test + void testVariableInIfThen5() throws IOException { + + String code = "package t; class Test { "+ + "private static void t() { " + + "if (true) } }"; + DiagnosticCollector coll = + new DiagnosticCollector(); + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, + null, Arrays.asList(new MyFileObject(code))); + + ct.parse(); + + List codes = new LinkedList(); + + for (Diagnostic d : coll.getDiagnostics()) { + codes.add(d.getCode()); + } + + assertEquals("testVariableInIfThen5", + Arrays.asList("compiler.err.illegal.start.of.stmt"), + codes); + } + + // see javac bug #6882235, NB bug #98234: + @Test + void testMissingExponent() throws IOException { + + String code = "\nclass Test { { System.err.println(0e); } }"; + + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, + null, Arrays.asList(new MyFileObject(code))); + + assertNotNull(ct.parse().iterator().next()); + } + + @Test + void testTryResourcePos() throws IOException { + + final String code = "package t; class Test { " + + "{ try (java.io.InputStream in = null) { } } }"; + + CompilationUnitTree cut = getCompilationUnitTree(code); + + new TreeScanner() { + @Override + public Void visitVariable(VariableTree node, Void p) { + if ("in".contentEquals(node.getName())) { + JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; + assertEquals("testTryResourcePos", "in = null) { } } }", + code.substring(var.pos)); + } + return super.visitVariable(node, p); + } + }.scan(cut, null); + } + + @Test + void testVarPos() throws IOException { + + final String code = "package t; class Test { " + + "{ java.io.InputStream in = null; } }"; + + CompilationUnitTree cut = getCompilationUnitTree(code); + + new TreeScanner() { + + @Override + public Void visitVariable(VariableTree node, Void p) { + if ("in".contentEquals(node.getName())) { + JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; + assertEquals("testVarPos","in = null; } }", + code.substring(var.pos)); + } + return super.visitVariable(node, p); + } + }.scan(cut, null); + } + + // expected erroneous tree: int x = y;(ERROR); + @Test + void testOperatorMissingError() throws IOException { + + String code = "package test; public class ErrorTest { " + + "void method() { int x = y z } }"; + CompilationUnitTree cut = getCompilationUnitTree(code); + final List values = new ArrayList<>(); + final List expectedValues = + new ArrayList<>(Arrays.asList("[z]")); + + new TreeScanner() { + @Override + public Void visitErroneous(ErroneousTree node, Void p) { + values.add(getErroneousTreeValues(node).toString()); + return null; + + } + }.scan(cut, null); + + assertEquals("testSwitchError: The Erroneous tree " + + "error values: " + values + + " do not match expected error values: " + + expectedValues, values, expectedValues); + } + + // expected erroneous tree: String s = (ERROR); + @Test + void testMissingParenthesisError() throws IOException { + + String code = "package test; public class ErrorTest { " + + "void f() {String s = new String; } }"; + CompilationUnitTree cut = getCompilationUnitTree(code); + final List values = new ArrayList<>(); + final List expectedValues = + new ArrayList<>(Arrays.asList("[new String()]")); + + new TreeScanner() { + @Override + public Void visitErroneous(ErroneousTree node, Void p) { + values.add(getErroneousTreeValues(node).toString()); + return null; + } + }.scan(cut, null); + + assertEquals("testSwitchError: The Erroneous tree " + + "error values: " + values + + " do not match expected error values: " + + expectedValues, values, expectedValues); + } + + // expected erroneous tree: package test; (ERROR)(ERROR) + @Test + void testMissingClassError() throws IOException { + + String code = "package Test; clas ErrorTest { " + + "void f() {String s = new String(); } }"; + CompilationUnitTree cut = getCompilationUnitTree(code); + final List values = new ArrayList<>(); + final List expectedValues = + new ArrayList<>(Arrays.asList("[, clas]", "[]")); + + new TreeScanner() { + @Override + public Void visitErroneous(ErroneousTree node, Void p) { + values.add(getErroneousTreeValues(node).toString()); + return null; + } + }.scan(cut, null); + + assertEquals("testSwitchError: The Erroneous tree " + + "error values: " + values + + " do not match expected error values: " + + expectedValues, values, expectedValues); + } + + // expected erroneous tree: void m1(int i) {(ERROR);{(ERROR);} + @Test + void testSwitchError() throws IOException { + + String code = "package test; public class ErrorTest { " + + "int numDays; void m1(int i) { switchh {i} { case 1: " + + "numDays = 31; break; } } }"; + CompilationUnitTree cut = getCompilationUnitTree(code); + final List values = new ArrayList<>(); + final List expectedValues = + new ArrayList<>(Arrays.asList("[switchh]", "[i]")); + + new TreeScanner() { + @Override + public Void visitErroneous(ErroneousTree node, Void p) { + values.add(getErroneousTreeValues(node).toString()); + return null; + } + }.scan(cut, null); + + assertEquals("testSwitchError: The Erroneous tree " + + "error values: " + values + + " do not match expected error values: " + + expectedValues, values, expectedValues); + } + + // expected erroneous tree: class ErrorTest {(ERROR) + @Test + void testMethodError() throws IOException { + + String code = "package Test; class ErrorTest { " + + "static final void f) {String s = new String(); } }"; + CompilationUnitTree cut = cut = getCompilationUnitTree(code); + + final List values = new ArrayList<>(); + final List expectedValues = + new ArrayList<>(Arrays.asList("[\nstatic final void f();]")); + + new TreeScanner() { + @Override + public Void visitErroneous(ErroneousTree node, Void p) { + values.add(normalize(getErroneousTreeValues(node).toString())); + return null; + } + }.scan(cut, null); + + assertEquals("testMethodError: The Erroneous tree " + + "error value: " + values + + " does not match expected error values: " + + expectedValues, values, expectedValues); + } + + /* + * The following tests do not work just yet with nb-javac nor javac, + * they need further investigation, see CR: 7167356 + */ + + void testPositionBrokenSource126732a() throws IOException { String[] commands = new String[]{ "return Runnable()", "do { } while (true)", @@ -250,7 +838,7 @@ } } - public void testPositionBrokenSource126732b() throws IOException { + void testPositionBrokenSource126732b() throws IOException { String[] commands = new String[]{ "break", "break A", @@ -291,246 +879,7 @@ } } - public void testErrorRecoveryForEnhancedForLoop142381() throws IOException { - - String code = "package test; class Test { " + - "private void method() { " + - "java.util.Set s = null; for (a : s) {} } }"; - - final List> errors = - new LinkedList>(); - - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, - new DiagnosticListener() { - public void report(Diagnostic diagnostic) { - errors.add(diagnostic); - } - }, null, null, Arrays.asList(new MyFileObject(code))); - - CompilationUnitTree cut = ct.parse().iterator().next(); - - ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); - StatementTree forStatement = - ((MethodTree) clazz.getMembers().get(0)).getBody().getStatements().get(1); - - assertEquals("testErrorRecoveryForEnhancedForLoop142381", - Kind.ENHANCED_FOR_LOOP, forStatement.getKind()); - assertFalse("testErrorRecoveryForEnhancedForLoop142381", errors.isEmpty()); - } - - public void testPositionAnnotationNoPackage187551() throws IOException { - - String code = "\n@interface Test {}"; - - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, - null, Arrays.asList(new MyFileObject(code))); - - CompilationUnitTree cut = ct.parse().iterator().next(); - ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); - Trees t = Trees.instance(ct); - - assertEquals("testPositionAnnotationNoPackage187551", - 1, t.getSourcePositions().getStartPosition(cut, clazz)); - } - - public void testPositionsSane() throws IOException { - performPositionsSanityTest("package test; class Test { " + - "private void method() { " + - "java.util.List> l; " + - "} }"); - performPositionsSanityTest("package test; class Test { " + - "private void method() { " + - "java.util.List> l; " + - "} }"); - performPositionsSanityTest("package test; class Test { " + - "private void method() { " + - "java.util.List> l; } }"); - } - - private void performPositionsSanityTest(String code) throws IOException { - - final List> errors = - new LinkedList>(); - - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, - new DiagnosticListener() { - - public void report(Diagnostic diagnostic) { - errors.add(diagnostic); - } - }, null, null, Arrays.asList(new MyFileObject(code))); - - final CompilationUnitTree cut = ct.parse().iterator().next(); - final Trees trees = Trees.instance(ct); - - new TreeScanner() { - - private long parentStart = 0; - private long parentEnd = Integer.MAX_VALUE; - - @Override - public Void scan(Tree node, Void p) { - if (node == null) { - return null; - } - - long start = trees.getSourcePositions().getStartPosition(cut, node); - - if (start == (-1)) { - return null; //synthetic tree - } - assertTrue(node.toString() + ":" + start + "/" + parentStart, - parentStart <= start); - - long prevParentStart = parentStart; - - parentStart = start; - - long end = trees.getSourcePositions().getEndPosition(cut, node); - - assertTrue(node.toString() + ":" + end + "/" + parentEnd, - end <= parentEnd); - - long prevParentEnd = parentEnd; - - parentEnd = end; - - super.scan(node, p); - - parentStart = prevParentStart; - parentEnd = prevParentEnd; - - return null; - } - - private void assertTrue(String message, boolean b) { - if (!b) fail(message); - } - }.scan(cut, null); - } - - public void testCorrectWilcardPositions() throws IOException { - performWildcardPositionsTest("package test; import java.util.List; " + - "class Test { private void method() { List> l; } }", - - Arrays.asList("List> l;", - "List>", - "List", - "? extends List", - "List", - "List", - "? extends String", - "String")); - performWildcardPositionsTest("package test; import java.util.List; " + - "class Test { private void method() { List> l; } }", - - Arrays.asList("List> l;", - "List>", - "List", - "? super List", - "List", - "List", - "? super String", - "String")); - performWildcardPositionsTest("package test; import java.util.List; " + - "class Test { private void method() { List> l; } }", - - Arrays.asList("List> l;", - "List>", - "List", - "? super List", - "List", - "List", - "?")); - performWildcardPositionsTest("package test; import java.util.List; " + - "class Test { private void method() { " + - "List>> l; } }", - - Arrays.asList("List>> l;", - "List>>", - "List", - "? extends List>", - "List>", - "List", - "? extends List", - "List", - "List", - "? extends String", - "String")); - performWildcardPositionsTest("package test; import java.util.List; " + - "class Test { private void method() { " + - "List>> l; } }", - Arrays.asList("List>> l;", - "List>>", - "List", - "? extends List>", - "List>", - "List", - "? extends List", - "List", - "List", - "? extends String", - "String")); - } - - public void performWildcardPositionsTest(final String code, - List golden) throws IOException { - - final List> errors = - new LinkedList>(); - - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, - new DiagnosticListener() { - public void report(Diagnostic diagnostic) { - errors.add(diagnostic); - } - }, null, null, Arrays.asList(new MyFileObject(code))); - - final CompilationUnitTree cut = ct.parse().iterator().next(); - final List content = new LinkedList(); - final Trees trees = Trees.instance(ct); - - new TreeScanner() { - @Override - public Void scan(Tree node, Void p) { - if (node == null) { - return null; - } - long start = trees.getSourcePositions().getStartPosition(cut, node); - - if (start == (-1)) { - return null; //synthetic tree - } - long end = trees.getSourcePositions().getEndPosition(cut, node); - String s = code.substring((int) start, (int) end); - content.add(s); - - return super.scan(node, p); - } - }.scan(((MethodTree) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0)).getBody().getStatements().get(0), null); - - assertEquals("performWildcardPositionsTest",golden.toString(), - content.toString()); - } - - public void testStartPositionForMethodWithoutModifiers() throws IOException { - - String code = "package t; class Test { void t() {} }"; - - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, - null, Arrays.asList(new MyFileObject(code))); - CompilationUnitTree cut = ct.parse().iterator().next(); - ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); - MethodTree mt = (MethodTree) clazz.getMembers().get(0); - Trees t = Trees.instance(ct); - int start = (int) t.getSourcePositions().getStartPosition(cut, mt); - int end = (int) t.getSourcePositions().getEndPosition(cut, mt); - - assertEquals("testStartPositionForMethodWithoutModifiers", - " void t() {}", code.substring(start, end)); - } - - public void testStartPositionEnumConstantInit() throws IOException { + void testStartPositionEnumConstantInit() throws IOException { String code = "package t; enum Test { AAA; }"; @@ -546,342 +895,34 @@ assertEquals("testStartPositionEnumConstantInit", -1, start); } - public void testVariableInIfThen1() throws IOException { - - String code = "package t; class Test { " + - "private static void t(String name) { " + - "if (name != null) String nn = name.trim(); } }"; - - DiagnosticCollector coll = - new DiagnosticCollector(); - - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, - null, Arrays.asList(new MyFileObject(code))); - - ct.parse(); - - List codes = new LinkedList(); - - for (Diagnostic d : coll.getDiagnostics()) { - codes.add(d.getCode()); - } - - assertEquals("testVariableInIfThen1", - Arrays.asList("compiler.err.variable.not.allowed"), - codes); - } - - public void testVariableInIfThen2() throws IOException { - - String code = "package t; class Test { " + - "private static void t(String name) { " + - "if (name != null) class X {} } }"; - DiagnosticCollector coll = - new DiagnosticCollector(); - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, - null, Arrays.asList(new MyFileObject(code))); - - ct.parse(); - - List codes = new LinkedList(); - - for (Diagnostic d : coll.getDiagnostics()) { - codes.add(d.getCode()); - } - - assertEquals("testVariableInIfThen2", - Arrays.asList("compiler.err.class.not.allowed"), codes); - } - - public void testVariableInIfThen3() throws IOException { - - String code = "package t; class Test { "+ - "private static void t() { " + - "if (true) abstract class F {} }}"; - DiagnosticCollector coll = - new DiagnosticCollector(); - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, - null, Arrays.asList(new MyFileObject(code))); - - ct.parse(); - - List codes = new LinkedList(); - - for (Diagnostic d : coll.getDiagnostics()) { - codes.add(d.getCode()); - } - - assertEquals("testVariableInIfThen3", - Arrays.asList("compiler.err.class.not.allowed"), codes); - } - - public void testVariableInIfThen4() throws IOException { - - String code = "package t; class Test { "+ - "private static void t(String name) { " + - "if (name != null) interface X {} } }"; - DiagnosticCollector coll = - new DiagnosticCollector(); - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, - null, Arrays.asList(new MyFileObject(code))); - - ct.parse(); - - List codes = new LinkedList(); - - for (Diagnostic d : coll.getDiagnostics()) { - codes.add(d.getCode()); - } - - assertEquals("testVariableInIfThen4", - Arrays.asList("compiler.err.class.not.allowed"), codes); - } - - public void testVariableInIfThen5() throws IOException { - - String code = "package t; class Test { "+ - "private static void t() { " + - "if (true) } }"; - DiagnosticCollector coll = - new DiagnosticCollector(); - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, - null, Arrays.asList(new MyFileObject(code))); - - ct.parse(); - - List codes = new LinkedList(); - - for (Diagnostic d : coll.getDiagnostics()) { - codes.add(d.getCode()); - } - - assertEquals("testVariableInIfThen5", - Arrays.asList("compiler.err.illegal.start.of.stmt"), - codes); - } - - //see javac bug #6882235, NB bug #98234: - public void testMissingExponent() throws IOException { - - String code = "\nclass Test { { System.err.println(0e); } }"; - - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, - null, Arrays.asList(new MyFileObject(code))); - - assertNotNull(ct.parse().iterator().next()); - } - - public void testTryResourcePos() throws IOException { - - final String code = "package t; class Test { " + - "{ try (java.io.InputStream in = null) { } } }"; - - CompilationUnitTree cut = getCompilationUnitTree(code); - - new TreeScanner() { - @Override - public Void visitVariable(VariableTree node, Void p) { - if ("in".contentEquals(node.getName())) { - JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; - System.out.println(node.getName() + "," + var.pos); - assertEquals("testTryResourcePos", "in = null) { } } }", - code.substring(var.pos)); + void run(String[] args) throws Exception { + int passed = 0, failed = 0; + final Pattern p = (args != null && args.length > 0) + ? Pattern.compile(args[0]) + : null; + for (Method m : this.getClass().getDeclaredMethods()) { + boolean selected = (p == null) + ? m.isAnnotationPresent(Test.class) + : p.matcher(m.getName()).matches(); + if (selected) { + try { + m.invoke(this, (Object[]) null); + System.out.println(m.getName() + ": OK"); + passed++; + } catch (Throwable ex) { + System.out.printf("Test %s failed: %s %n", m, ex.getCause()); + failed++; } - return super.visitVariable(node, p); - } - }.scan(cut, null); - } - - public void testVarPos() throws IOException { - - final String code = "package t; class Test { " + - "{ java.io.InputStream in = null; } }"; - - CompilationUnitTree cut = getCompilationUnitTree(code); - - new TreeScanner() { - - @Override - public Void visitVariable(VariableTree node, Void p) { - if ("in".contentEquals(node.getName())) { - JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; - assertEquals("testVarPos","in = null; } }", - code.substring(var.pos)); - } - return super.visitVariable(node, p); } - }.scan(cut, null); - } - - // expected erroneous tree: int x = y;(ERROR); - public void testOperatorMissingError() throws IOException { - - String code = "package test; public class ErrorTest { " - + "void method() { int x = y z } }"; - CompilationUnitTree cut = getCompilationUnitTree(code); - final List values = new ArrayList<>(); - final List expectedValues = - new ArrayList<>(Arrays.asList("[z]")); - - new TreeScanner() { - - @Override - public Void visitErroneous(ErroneousTree node, Void p) { - - values.add(getErroneousTreeValues(node).toString()); - return null; - - } - }.scan(cut, null); - - assertEquals("testSwitchError: The Erroneous tree " - + "error values: " + values - + " do not match expected error values: " - + expectedValues, values, expectedValues); - } - - //expected erroneous tree: String s = (ERROR); - public void testMissingParenthesisError() throws IOException { - - String code = "package test; public class ErrorTest { " - + "void f() {String s = new String; } }"; - CompilationUnitTree cut = getCompilationUnitTree(code); - final List values = new ArrayList<>(); - final List expectedValues = - new ArrayList<>(Arrays.asList("[new String()]")); - - new TreeScanner() { - - @Override - public Void visitErroneous(ErroneousTree node, Void p) { - - values.add(getErroneousTreeValues(node).toString()); - return null; - } - }.scan(cut, null); - - assertEquals("testSwitchError: The Erroneous tree " - + "error values: " + values - + " do not match expected error values: " - + expectedValues, values, expectedValues); - } - - //expected erroneous tree: package test; (ERROR)(ERROR) - public void testMissingClassError() throws IOException { - - String code = "package Test; clas ErrorTest { " - + "void f() {String s = new String(); } }"; - CompilationUnitTree cut = getCompilationUnitTree(code); - final List values = new ArrayList<>(); - final List expectedValues = - new ArrayList<>(Arrays.asList("[, clas]", "[]")); - - new TreeScanner() { - - @Override - public Void visitErroneous(ErroneousTree node, Void p) { - - values.add(getErroneousTreeValues(node).toString()); - return null; - } - }.scan(cut, null); - - assertEquals("testSwitchError: The Erroneous tree " - + "error values: " + values - + " do not match expected error values: " - + expectedValues, values, expectedValues); - } - - //expected erroneous tree: void m1(int i) {(ERROR);{(ERROR);} - public void testSwitchError() throws IOException { - - String code = "package test; public class ErrorTest { " - + "int numDays; void m1(int i) { switchh {i} { case 1: " - + "numDays = 31; break; } } }"; - CompilationUnitTree cut = getCompilationUnitTree(code); - final List values = new ArrayList<>(); - final List expectedValues = - new ArrayList<>(Arrays.asList("[switchh]", "[i]")); - - new TreeScanner() { - - @Override - public Void visitErroneous(ErroneousTree node, Void p) { - - values.add(getErroneousTreeValues(node).toString()); - return null; - } - }.scan(cut, null); - - assertEquals("testSwitchError: The Erroneous tree " - + "error values: " + values - + " do not match expected error values: " - + expectedValues, values, expectedValues); - } - - //expected erroneous tree: class ErrorTest {(ERROR) - public void testMethodError() throws IOException { - - String code = "package Test; class ErrorTest { " - + "static final void f) {String s = new String(); } }"; - CompilationUnitTree cut = getCompilationUnitTree(code); - final List values = new ArrayList<>(); - final List expectedValues = - new ArrayList<>(Arrays.asList("[\nstatic final void f();]")); - - new TreeScanner() { - - @Override - public Void visitErroneous(ErroneousTree node, Void p) { - - values.add(normalize(getErroneousTreeValues(node).toString())); - return null; - } - }.scan(cut, null); - - assertEquals("testMethodError: The Erroneous tree " - + "error value: " + values - + " does not match expected error values: " - + expectedValues, values, expectedValues); - } - - void testsNotWorking() throws IOException { - - // Fails with nb-javac, needs further investigation - testPositionBrokenSource126732a(); - testPositionBrokenSource126732b(); - - // Fails, these tests yet to be addressed - testPositionForEnumModifiers(); - testStartPositionEnumConstantInit(); - } - void testPositions() throws IOException { - testPositionsSane(); - testCorrectWilcardPositions(); - testPositionAnnotationNoPackage187551(); - testPositionForSuperConstructorCalls(); - testPreferredPositionForBinaryOp(); - testStartPositionForMethodWithoutModifiers(); - testVarPos(); - testVariableInIfThen1(); - testVariableInIfThen2(); - testVariableInIfThen3(); - testVariableInIfThen4(); - testVariableInIfThen5(); - testMissingExponent(); - testTryResourcePos(); - testOperatorMissingError(); - testMissingParenthesisError(); - testMissingClassError(); - testSwitchError(); - testMethodError(); - testErrorRecoveryForEnhancedForLoop142381(); - } - - public static void main(String... args) throws IOException { - JavacParserTest jpt = new JavacParserTest("JavacParserTest"); - jpt.testPositions(); - System.out.println("PASS"); + } + System.out.printf("Passed: %d, Failed %d%n", passed, failed); + if (failed > 0) { + throw new RuntimeException("Tests failed: " + failed); + } + if (passed == 0 && failed == 0) { + throw new AssertionError("No test(s) selected: passed = " + + passed + ", failed = " + failed + " ??????????"); + } } } @@ -906,8 +947,6 @@ } void assertEquals(String message, Object o1, Object o2) { - System.out.println(o1); - System.out.println(o2); if (o1 != null && o2 != null && !o1.equals(o2)) { fail(message); } @@ -929,4 +968,11 @@ void fail(String message) { throw new RuntimeException(message); } + + /** + * Indicates that the annotated method is a test method. + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public @interface Test {} } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/test/tools/javac/tree/DocCommentToplevelTest.java --- a/langtools/test/tools/javac/tree/DocCommentToplevelTest.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/test/tools/javac/tree/DocCommentToplevelTest.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -29,6 +29,7 @@ import com.sun.source.tree.*; import com.sun.source.util.*; +import com.sun.tools.javac.tree.DocCommentTable; import com.sun.tools.javac.tree.JCTree; import java.net.URI; @@ -137,16 +138,16 @@ new TreeScanner() { - Map docComments; + DocCommentTable docComments; @Override public ClassTree visitCompilationUnit(CompilationUnitTree node, Void unused) { docComments = ((JCTree.JCCompilationUnit)node).docComments; boolean expectedComment = tdk == ToplevelDocKind.HAS_DOC && (pk != PackageKind.NO_PKG || ik != ImportKind.ZERO); - boolean foundComment = docComments.get(node) != null; + boolean foundComment = docComments.hasComment((JCTree) node); if (expectedComment != foundComment) { - error("Unexpected comment " + docComments.get(node) + " on toplevel"); + error("Unexpected comment " + docComments.getComment((JCTree) node) + " on toplevel"); } return super.visitCompilationUnit(node, null); } @@ -156,9 +157,9 @@ boolean expectedComment = tdk == ToplevelDocKind.HAS_DOC && pk == PackageKind.NO_PKG && ik == ImportKind.ZERO && node.getSimpleName().toString().equals("First"); - boolean foundComment = docComments.get(node) != null; + boolean foundComment = docComments.hasComment((JCTree) node); if (expectedComment != foundComment) { - error("Unexpected comment " + docComments.get(node) + " on class " + node.getSimpleName()); + error("Unexpected comment " + docComments.getComment((JCTree) node) + " on class " + node.getSimpleName()); } return super.visitClass(node, unused); } diff -r 2c1fa96ba3d7 -r a2cf86579ad4 langtools/test/tools/javac/tree/TreePosTest.java --- a/langtools/test/tools/javac/tree/TreePosTest.java Tue Jun 26 15:28:21 2012 -0700 +++ b/langtools/test/tools/javac/tree/TreePosTest.java Tue Jun 26 22:47:23 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -73,7 +73,7 @@ import com.sun.source.util.JavacTask; import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.parser.EndPosTable; +import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.tree.JCTree.JCNewClass; diff -r 2c1fa96ba3d7 -r a2cf86579ad4 test/Makefile --- a/test/Makefile Tue Jun 26 15:28:21 2012 -0700 +++ b/test/Makefile Tue Jun 26 22:47:23 2012 -0700 @@ -74,7 +74,8 @@ jdk_rmi \ jdk_sound \ jdk_swing \ - jdk_tools1 jdk_tools2 + jdk_tools1 jdk_tools2 \ + jdk_jfr # All jdk tests JDK_ALL_TEST_LIST = $(JDK_DEFAULT_TEST_LIST) $(JDK_NONDEFAULT_TEST_LIST)