2222
2323/** Represents the JDK cache for this tool. */
2424public final class JDKCache {
25- private boolean attemptedLocate = false ;
26- private final List <Throwable > attemptedLocateErrors = new ArrayList <>();
25+ private Map <JavaLocator , List <String >> attemptedLocate = null ;
2726 private final File root ;
2827 private final Map <Integer , File > jdks = new HashMap <>();
2928 private final JavaProvisioner disco ;
@@ -50,7 +49,7 @@ public File root() {
5049 * @return The JDK, or {@code null} if it could not be found or downloaded
5150 */
5251 public File get (int version ) throws Exception {
53- if (! attemptedLocate )
52+ if (attemptedLocate == null )
5453 attemptLocate ();
5554
5655 // check cache. stop immediately if we get a hit.
@@ -61,7 +60,18 @@ public File get(int version) throws Exception {
6160 ret = disco .provision (version ).home (); // Implementation detail, we only download jdks, so no need to check here
6261 } catch (Exception e ) {
6362 LOGGER .error ("Failed to provision JDK " + version );
63+ disco .logOutput ().forEach (LOGGER ::error );
6464 e .printStackTrace (LOGGER .getLog (Logger .Level .ERROR ));
65+
66+ if (!attemptedLocate .isEmpty ()) {
67+ LOGGER .error ("The following errors were found trying to find existing JDKs:" );
68+ for (var entry : attemptedLocate .entrySet ()) {
69+ var locator = entry .getKey ();
70+ var output = entry .getValue ();
71+ LOGGER .error ("Errors with locator: " + locator .getClass ().getName () + " " + locator );
72+ output .forEach (LOGGER ::error );
73+ }
74+ }
6575 throw e ;
6676 }
6777
@@ -77,8 +87,8 @@ public File get(int version) throws Exception {
7787 }
7888
7989 private void attemptLocate () {
80- if (attemptedLocate ) return ;
81- attemptedLocate = true ;
90+ if (attemptedLocate != null ) return ;
91+ attemptedLocate = Map . of () ;
8292
8393 List <JavaLocator > locators = new ArrayList <>();
8494 locators .add (JavaLocator .home ());
@@ -87,13 +97,16 @@ private void attemptLocate() {
8797
8898 List <JavaInstall > installs = new ArrayList <>();
8999
100+ var errors = new HashMap <JavaLocator , List <String >>(locators .size ());
90101 for (JavaLocator locator : locators ) {
91- try {
92- installs .addAll (locator .findAll ());
93- } catch (Exception e ) {
94- attemptedLocateErrors .add (e );
102+ var located = locator .findAll ();
103+ if (located .isEmpty ()) {
104+ errors .put (locator , locator .logOutput ());
105+ } else {
106+ installs .addAll (located );
95107 }
96108 }
109+ attemptedLocate = errors ;
97110
98111 // Remove duplicates
99112 var seen = new HashSet <File >();
0 commit comments