@@ -120,7 +120,11 @@ public TrustyUriResource(URL url, String artifactCode) throws IOException {
120120 logger .debug ("Creating TrustyUriResource from URL '{}' with explicit artifact code '{}'" , url , artifactCode );
121121 URLConnection conn = url .openConnection ();
122122 String contentType = conn .getContentType ();
123- logger .debug ("Content-Type reported by server for '{}': '{}'" , url , contentType );
123+ if (contentType == null ) {
124+ logger .warn ("Server did not report a Content-Type for URL '{}'; mimetype will be unknown" , url );
125+ } else {
126+ logger .debug ("Content-Type reported by server for '{}': '{}'" , url , contentType );
127+ }
124128 init (url .toString (), contentType , conn .getInputStream (), artifactCode );
125129 }
126130
@@ -136,7 +140,11 @@ public TrustyUriResource(URL url) throws IOException {
136140 logger .debug ("Creating TrustyUriResource from URL '{}'; derived artifact code: '{}'" , n , ac );
137141 URLConnection conn = url .openConnection ();
138142 String contentType = conn .getContentType ();
139- logger .debug ("Content-Type reported by server for '{}': '{}'" , n , contentType );
143+ if (contentType == null ) {
144+ logger .warn ("Server did not report a Content-Type for URL '{}'; mimetype will be unknown" , n );
145+ } else {
146+ logger .debug ("Content-Type reported by server for '{}': '{}'" , n , contentType );
147+ }
140148 init (n , contentType , conn .getInputStream (), ac );
141149 }
142150
@@ -145,11 +153,17 @@ private void init(String filename, String mimetype, InputStream in, String artif
145153 this .mimetype = mimetype ;
146154 this .artifactCode = artifactCode ;
147155 if (filename .matches (".*\\ .(gz|gzip)" )) {
148- logger .debug ("Detected compressed resource '{}', wrapping stream in GZIPInputStream" , filename );
149- this .in = new GZIPInputStream (in );
156+ logger .debug ("Detected compressed resource '{}' (.gz/.gzip extension), wrapping stream in GZIPInputStream" , filename );
157+ try {
158+ this .in = new GZIPInputStream (in );
159+ } catch (IOException ex ) {
160+ logger .error ("Failed to read '{}' as a GZIP stream despite .gz/.gzip extension: {}" , filename , ex .getMessage ());
161+ throw ex ;
162+ }
150163 } else {
151164 this .in = in ;
152165 }
166+ logger .debug ("Initialized TrustyUriResource: filename='{}', mimetype='{}', artifactCode='{}', compressed={}" , filename , mimetype , artifactCode , compressed );
153167 }
154168
155169 /**
@@ -212,7 +226,9 @@ public boolean isCompressed() {
212226 * @return the module identifier of the resource, which is derived from the artifact code
213227 */
214228 public String getModuleId () {
215- return TrustyUriUtils .getModuleId (artifactCode );
229+ String moduleId = TrustyUriUtils .getModuleId (artifactCode );
230+ logger .debug ("Resolved module ID for artifact code '{}': '{}'" , artifactCode , moduleId );
231+ return moduleId ;
216232 }
217233
218234 /**
0 commit comments