Skip to content

Commit 8648ed5

Browse files
committed
Manifest: add some defensive programming
This guards against the wrapped manifest being null, as well as the wrapped manifest's main attributes being null for some reason. Intended to address (the symptom, at least) of Fiji bug 889: http://fiji.sc/bugzilla/show_bug.cgi?id=889
1 parent 6410909 commit 8648ed5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/java/org/scijava/util/Manifest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.net.URL;
3737
import java.util.Collections;
3838
import java.util.Map;
39+
import java.util.jar.Attributes;
3940

4041
/**
4142
* Helper class for working with JAR manifests.
@@ -115,11 +116,17 @@ public String getSpecificationVersion() {
115116
}
116117

117118
public String get(final String key) {
118-
return manifest.getMainAttributes().getValue(key);
119+
if (manifest == null) return null;
120+
final Attributes mainAttrs = manifest.getMainAttributes();
121+
if (mainAttrs == null) return null;
122+
return mainAttrs.getValue(key);
119123
}
120124

121125
public Map<Object, Object> getAll() {
122-
return Collections.unmodifiableMap(manifest.getMainAttributes());
126+
if (manifest == null) return null;
127+
final Attributes mainAttrs = manifest.getMainAttributes();
128+
if (mainAttrs == null) return null;
129+
return Collections.unmodifiableMap(mainAttrs);
123130
}
124131

125132
// -- Utility methods --

0 commit comments

Comments
 (0)