|
27 | 27 |
|
28 | 28 | import org.jboss.logging.Logger;
|
29 | 29 |
|
| 30 | +import com.google.common.annotations.VisibleForTesting; |
| 31 | + |
30 | 32 | import io.quarkus.bootstrap.app.CuratedApplication;
|
31 | 33 | import io.quarkus.bootstrap.app.StartupAction;
|
32 | 34 | import io.quarkus.commons.classloading.ClassLoaderHelper;
|
33 |
| -import io.quarkus.paths.ManifestAttributes; |
34 | 35 | import io.quarkus.paths.PathVisit;
|
35 | 36 |
|
36 | 37 | /**
|
@@ -141,7 +142,6 @@ public static boolean isResourcePresentAtRuntime(String resourcePath) {
|
141 | 142 | private final List<ClassPathElement> bannedElements;
|
142 | 143 | private final List<ClassPathElement> parentFirstElements;
|
143 | 144 | private final ConcurrentMap<ClassPathElement, ProtectionDomain> protectionDomains = new ConcurrentHashMap<>();
|
144 |
| - private final ConcurrentMap<String, Package> definedPackages = new ConcurrentHashMap<>(); |
145 | 145 | private final ClassLoader parent;
|
146 | 146 | /**
|
147 | 147 | * If this is true it will attempt to load from the parent first
|
@@ -587,28 +587,33 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
|
587 | 587 | }
|
588 | 588 | }
|
589 | 589 |
|
590 |
| - private void definePackage(String name, ClassPathElement classPathElement) { |
591 |
| - final String pkgName = getPackageNameFromClassName(name); |
592 |
| - //we can't use getPackage here |
593 |
| - //if can return a package from the parent |
594 |
| - if ((pkgName != null) && definedPackages.get(pkgName) == null) { |
595 |
| - synchronized (getClassLoadingLock(pkgName)) { |
596 |
| - if (definedPackages.get(pkgName) == null) { |
597 |
| - ManifestAttributes manifest = classPathElement.getManifestAttributes(); |
598 |
| - if (manifest != null) { |
599 |
| - definedPackages.put(pkgName, definePackage(pkgName, manifest.getSpecificationTitle(), |
600 |
| - manifest.getSpecificationVersion(), |
601 |
| - manifest.getSpecificationVendor(), |
602 |
| - manifest.getImplementationTitle(), |
603 |
| - manifest.getImplementationVersion(), |
604 |
| - manifest.getImplementationVendor(), null)); |
605 |
| - return; |
606 |
| - } |
607 |
| - |
608 |
| - // this could certainly be improved to use the actual manifest |
609 |
| - definedPackages.put(pkgName, definePackage(pkgName, null, null, null, null, null, null, null)); |
610 |
| - } |
| 590 | + @VisibleForTesting |
| 591 | + void definePackage(String name, ClassPathElement classPathElement) { |
| 592 | + var pkgName = getPackageNameFromClassName(name); |
| 593 | + if (pkgName == null) { |
| 594 | + return; |
| 595 | + } |
| 596 | + if (getDefinedPackage(pkgName) != null) { |
| 597 | + return; |
| 598 | + } |
| 599 | + try { |
| 600 | + var manifest = classPathElement.getManifestAttributes(); |
| 601 | + if (manifest != null) { |
| 602 | + definePackage(pkgName, manifest.getSpecificationTitle(), |
| 603 | + manifest.getSpecificationVersion(), |
| 604 | + manifest.getSpecificationVendor(), |
| 605 | + manifest.getImplementationTitle(), |
| 606 | + manifest.getImplementationVersion(), |
| 607 | + manifest.getImplementationVendor(), null); |
| 608 | + } else { |
| 609 | + definePackage(pkgName, null, null, null, null, null, null, null); |
| 610 | + } |
| 611 | + } catch (IllegalArgumentException e) { |
| 612 | + // retry, thrown by definePackage(), if a package for the same name is already defines by this class loader. |
| 613 | + if (getDefinedPackage(pkgName) != null) { |
| 614 | + return; |
611 | 615 | }
|
| 616 | + throw e; |
612 | 617 | }
|
613 | 618 | }
|
614 | 619 |
|
|
0 commit comments