@@ -43,7 +43,10 @@ final class ImmutableDefinitionIdentifier implements DefinitionIdentifier {
4343 private final String namespace ;
4444 private final String name ;
4545 private final String version ;
46- @ Nullable private final URL url ;
46+ // The URL is kept in its String form (not as java.net.URL) on purpose: URL.equals()/URL.hashCode() perform
47+ // blocking DNS resolution and are non-deterministic, so they must not be used for equality. getUrl() reconstructs
48+ // the java.net.URL on demand from this (always valid) string.
49+ @ Nullable private final String urlString ;
4750 private final String stringRepresentation ;
4851
4952 private ImmutableDefinitionIdentifier (final CharSequence theNamespace , final CharSequence theName ,
@@ -53,13 +56,13 @@ private ImmutableDefinitionIdentifier(final CharSequence theNamespace, final Cha
5356 namespace = "" ;
5457 name = "" ;
5558 version = "" ;
56- url = theUrl ;
57- stringRepresentation = url . toString () ;
59+ urlString = theUrl . toString () ;
60+ stringRepresentation = urlString ;
5861 } else {
5962 namespace = argumentNotEmpty (theNamespace , "namespace" ).toString ();
6063 name = argumentNotEmpty (theName , "name" ).toString ();
6164 version = argumentNotEmpty (theVersion , "version" ).toString ();
62- url = null ;
65+ urlString = null ;
6366 stringRepresentation = namespace + COLON + name + COLON + version ;
6467 }
6568 }
@@ -160,7 +163,15 @@ public String getVersion() {
160163
161164 @ Override
162165 public Optional <URL > getUrl () {
163- return Optional .ofNullable (url );
166+ if (null == urlString ) {
167+ return Optional .empty ();
168+ }
169+ try {
170+ return Optional .of (new URL (urlString ));
171+ } catch (final MalformedURLException e ) {
172+ // cannot happen: urlString always originates from a previously valid java.net.URL
173+ return Optional .empty ();
174+ }
164175 }
165176
166177 @ Override
@@ -175,12 +186,12 @@ public boolean equals(final Object o) {
175186 return Objects .equals (namespace , that .namespace ) &&
176187 Objects .equals (name , that .name ) &&
177188 Objects .equals (version , that .version ) &&
178- Objects .equals (url , that .url );
189+ Objects .equals (urlString , that .urlString );
179190 }
180191
181192 @ Override
182193 public int hashCode () {
183- return Objects .hash (namespace , name , version , url );
194+ return Objects .hash (namespace , name , version , urlString );
184195 }
185196
186197 @ Override
0 commit comments