Skip to content

Commit dd1adcb

Browse files
authored
Merge pull request #29 from Electrostat-Lab/epsilon-patch
Epsilon-patch: introduced a sanity-check of the stream provider handler for other File locator routines
2 parents 91fbefc + 8ac5a23 commit dd1adcb

File tree

12 files changed

+32
-20
lines changed

12 files changed

+32
-20
lines changed

snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestBasicFeatures.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public final class TestBasicFeatures {
6666
DefaultDynamicLibraries.MAC_X86_64,
6767
};
6868

69-
public static void main(String[] args) throws IOException {
69+
public static void main(String[] args) throws Exception {
7070
if (loader == null) {
7171
loader = new NativeBinaryLoader(libraryInfo);
7272
}

snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestBasicFeatures2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
*/
5454
public final class TestBasicFeatures2 {
5555

56-
public static void main(String[] args) throws IOException {
56+
public static void main(String[] args) throws Exception {
5757

5858
final Path compressionPath = Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs", TestBasicFeatures.getJarFile());
5959
final Path extractionPath = Files.createDirectories(Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs",

snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestFilesystemException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.nio.file.Paths;
1616

1717
public final class TestFilesystemException {
18-
public static void main(String[] args) throws IOException {
18+
public static void main(String[] args) throws Exception {
1919
final Path compressionPath = Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs", TestBasicFeatures.getJarFile());
2020
final Path extractionPath = Files.createDirectories(Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs",
2121
NativeVariant.OS_NAME.getProperty(), NativeVariant.OS_ARCH.getProperty()));

snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestFilesystemMemoryLeak.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* @author pavl_g
5050
*/
5151
public class TestFilesystemMemoryLeak {
52-
public static void main(String[] args) throws IOException {
52+
public static void main(String[] args) throws Exception {
5353
/* Locates the image inside the Zip Compression */
5454
SnapLoaderLogger.setLoggingEnabled(true);
5555
final FileLocator fileLocator = new FileLocator(getZipAbsolutePath(), getFilePath(), ZipCompressionType.ZIP);

snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestMultiThreading.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void run() {
5555
try {
5656
Thread.sleep(200);
5757
TestBasicFeatures.loader.loadLibrary(LoadingCriterion.CLEAN_EXTRACTION);
58-
} catch (UnSupportedSystemError | IOException | InterruptedException e) {
58+
} catch (Exception e) {
5959
e.printStackTrace();
6060
}
6161
}
@@ -69,7 +69,7 @@ public void run() {
6969
try {
7070
Thread.sleep(200);
7171
TestBasicFeatures.loader.loadLibrary(LoadingCriterion.CLEAN_EXTRACTION);
72-
} catch (UnSupportedSystemError | IOException | InterruptedException e) {
72+
} catch (Exception e) {
7373
e.printStackTrace();
7474
}
7575
}
@@ -83,7 +83,7 @@ public void run() {
8383
try {
8484
Thread.sleep(200);
8585
TestBasicFeatures.loader.loadLibrary(LoadingCriterion.CLEAN_EXTRACTION);
86-
} catch (UnSupportedSystemError | IOException | InterruptedException e) {
86+
} catch (Exception e) {
8787
e.printStackTrace();
8888
}
8989
}

snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestMultipleLoads.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*/
4343
public final class TestMultipleLoads {
4444

45-
public static void main(String[] args) throws InterruptedException, IOException {
45+
public static void main(String[] args) throws Exception {
4646
TestBasicFeatures.main(args);
4747
new File(TestBasicFeatures.getNativeDynamicLibraryPath()).delete();
4848
Thread.sleep(5000);

snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestZipExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
*/
4949
public class TestZipExtractor {
5050

51-
public static void main(String[] args) throws IOException {
51+
public static void main(String[] args) throws Exception {
5252
/* Locates the image inside the Zip Compression */
5353
final FileLocator fileLocator = new FileLocator(getZipAbsolutePath(), getFilePath(), ZipCompressionType.ZIP);
5454
/* Extracts the image filesystem from the Zip Compression */

snaploader/src/main/java/electrostatic4j/snaploader/ConcurrentNativeBinaryLoader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
package electrostatic4j.snaploader;
3434

35-
import java.io.IOException;
3635
import java.util.List;
3736
import java.util.concurrent.locks.ReentrantLock;
3837
import electrostatic4j.snaploader.platform.NativeDynamicLibrary;
@@ -59,7 +58,7 @@ public ConcurrentNativeBinaryLoader(final List<NativeDynamicLibrary> registeredL
5958
}
6059

6160
@Override
62-
protected void cleanExtractBinary(NativeDynamicLibrary library) throws IOException {
61+
protected void cleanExtractBinary(NativeDynamicLibrary library) throws Exception {
6362
try {
6463
/* CRITICAL SECTION STARTS */
6564
lock.lock();

snaploader/src/main/java/electrostatic4j/snaploader/NativeBinaryLoader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public NativeBinaryLoader initPlatformLibrary() throws UnSupportedSystemError {
152152
* @return this instance for chained invocations
153153
* @throws IOException if the library to extract is not present in the jar filesystem
154154
*/
155-
public NativeBinaryLoader loadLibrary(LoadingCriterion criterion) throws IOException {
155+
public NativeBinaryLoader loadLibrary(LoadingCriterion criterion) throws Exception {
156156
if (criterion == LoadingCriterion.INCREMENTAL_LOADING && nativeDynamicLibrary.isExtracted()) {
157157
loadBinary(nativeDynamicLibrary);
158158
return this;
@@ -240,7 +240,7 @@ public FileLocalizingListener getLibraryLocalizingListener() {
240240
* @param library the platform-specific library to load
241241
* @throws IOException in case the binary to be extracted is not found on the specified jar
242242
*/
243-
protected void loadBinary(NativeDynamicLibrary library) throws IOException {
243+
protected void loadBinary(NativeDynamicLibrary library) throws Exception {
244244
try {
245245
/* sanity-check for android java vm (the dalvik) */
246246
if (NativeVariant.Os.isAndroid()) {
@@ -278,7 +278,7 @@ protected void loadBinary(NativeDynamicLibrary library) throws IOException {
278278
* @throws IOException in case the binary to be extracted is not found on the specified jar, or an
279279
* interrupted I/O operation has occurred
280280
*/
281-
protected void cleanExtractBinary(NativeDynamicLibrary library) throws IOException {
281+
protected void cleanExtractBinary(NativeDynamicLibrary library) throws Exception {
282282
libraryExtractor = initializeLibraryExtractor(library);
283283
SnapLoaderLogger.log(Level.INFO, getClass().getName(), "cleanExtractBinary",
284284
"File extractor handler initialized!");
@@ -346,7 +346,7 @@ public void onExtractionFinalization(FileExtractor fileExtractor, FileLocator fi
346346
* @return a new FileExtractor object that represents an output stream provider
347347
* @throws IOException if the jar filesystem to be located is not found, or if the extraction destination is not found
348348
*/
349-
protected FileExtractor initializeLibraryExtractor(NativeDynamicLibrary library) throws IOException {
349+
protected FileExtractor initializeLibraryExtractor(NativeDynamicLibrary library) throws Exception {
350350
FileExtractor extractor;
351351
if (library.getJarPath() != null) {
352352
extractor = new LibraryExtractor(library.getJarPath(), library.getCompressedLibrary(), library.getExtractedLibrary());

snaploader/src/main/java/electrostatic4j/snaploader/filesystem/FileExtractor.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ protected FileExtractor() {
8686
}
8787

8888
@Override
89-
public void initialize(int size) {
89+
public void initialize(int size) throws Exception {
90+
// 1) sanity-check for double initializing
91+
// 2) sanity-check for pre-initialization using other routines
92+
if (this.fileOutputStream != null) {
93+
return;
94+
}
9095
try {
9196
if (size > 0) {
9297
this.fileOutputStream = new BufferedOutputStream(
@@ -98,7 +103,8 @@ public void initialize(int size) {
98103
this.fileOutputStream = new FileOutputStream(destination);
99104
SnapLoaderLogger.log(Level.INFO, getClass().getName(), "initialize(int)",
100105
"File extractor initialized with hash key #" + getHashKey());
101-
} catch (FileNotFoundException e) {
106+
} catch (Exception e) {
107+
close();
102108
throw new FilesystemResourceInitializationException(
103109
"Failed to initialize the file extractor handler #" + getHashKey(), e);
104110
}

0 commit comments

Comments
 (0)