src/share/classes/java/lang/ClassLoader.java

Print this page
7001933: Deadlock in java.lang.classloader.getPackage()

*** 1,7 **** /* ! * Copyright (c) 1994, 2010, 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 --- 1,7 ---- /* ! * Copyright (c) 1994, 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
*** 1626,1650 **** * <tt>null</tt> if not found * * @since 1.2 */ protected Package getPackage(String name) { synchronized (packages) { ! Package pkg = packages.get(name); if (pkg == null) { if (parent != null) { pkg = parent.getPackage(name); } else { pkg = Package.getSystemPackage(name); } if (pkg != null) { packages.put(name, pkg); } } - return pkg; } } /** * Returns all of the <tt>Packages</tt> defined by this class loader and * its ancestors. </p> * --- 1626,1655 ---- * <tt>null</tt> if not found * * @since 1.2 */ protected Package getPackage(String name) { + Package pkg; synchronized (packages) { ! pkg = packages.get(name); ! } if (pkg == null) { if (parent != null) { pkg = parent.getPackage(name); } else { pkg = Package.getSystemPackage(name); } if (pkg != null) { + synchronized (packages) { + if (packages.get(name) != null) { packages.put(name, pkg); } } } } + return pkg; + } /** * Returns all of the <tt>Packages</tt> defined by this class loader and * its ancestors. </p> *