Skip to content

Commit 83411d5

Browse files
committed
Handle error case, when file does not contain a valid manifest (e.g. if it isn't a JAR file at all).
1 parent 4a1e657 commit 83411d5

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

  • de.tototec.osgi.setupbuilder/src/main/scala/de/tototec/osgi/setupbuilder

de.tototec.osgi.setupbuilder/src/main/scala/de/tototec/osgi/setupbuilder/OsgiSetup.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package de.tototec.osgi.setupbuilder
22

3+
import java.io.BufferedInputStream
34
import java.io.File
4-
import java.util.jar.Manifest
5-
import java.util.jar.JarFile
6-
import java.util.jar.Attributes
75
import java.io.FileInputStream
8-
import java.io.BufferedInputStream
6+
import java.util.jar.Attributes
7+
import java.util.jar.JarException
98
import java.util.jar.JarInputStream
9+
import java.util.jar.Manifest
1010

1111
/**
1212
* Configuration for an OSGi setup.
@@ -45,10 +45,11 @@ class Bundle(val file: File) {
4545
val manifest: Manifest = {
4646
val stream = new JarInputStream(new BufferedInputStream(new FileInputStream(file)))
4747
try {
48-
stream.getManifest()
49-
} finally {
50-
stream.close()
51-
}
48+
stream.getManifest() match {
49+
case null => throw new JarException(s"""The supposed bundle file "${file}" does not contain a manifest (META-INF/MANIFEST.MF).""")
50+
case m => m
51+
}
52+
} finally stream.close()
5253
}
5354

5455
implicit class RichAttributes(attributes: Attributes) {

0 commit comments

Comments
 (0)