You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by st...@apache.org on 2025/04/12 10:33:18 UTC
(felix-dev) 09/19: [fw] use try with resource
This is an automated email from the ASF dual-hosted git repository.
stbischof pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
commit a835f947ec5e684e68f497892d6cfab3c206dd08
Author: Stefan Bischof <st...@bipolis.org>
AuthorDate: Sat Apr 5 09:38:03 2025 +0200
[fw] use try with resource
Signed-off-by: Stefan Bischof <st...@bipolis.org>
---
.../java/org/apache/felix/framework/cache/BundleArchive.java | 11 ++---------
.../java/org/apache/felix/framework/util/ClassParser.java | 7 +------
.../org/apache/felix/framework/cache/BundleCacheTest.java | 7 +------
3 files changed, 4 insertions(+), 21 deletions(-)
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java b/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
index 13d04ad910..3125ba4f35 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/BundleArchive.java
@@ -708,10 +708,8 @@ public class BundleArchive
**/
private void initialize() throws Exception
{
- OutputStream os = null;
- BufferedWriter bw = null;
-
- try
+ try (OutputStream os = null;
+ BufferedWriter bw = null)
{
// If the archive directory exists, then we don't
// need to initialize since it has already been done.
@@ -731,11 +729,6 @@ public class BundleArchive
writeBundleInfo();
}
- finally
- {
- if (bw != null) bw.close();
- if (os != null) os.close();
- }
}
/**
diff --git a/framework/src/main/java/org/apache/felix/framework/util/ClassParser.java b/framework/src/main/java/org/apache/felix/framework/util/ClassParser.java
index 6fefd915ff..6558a224c4 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/ClassParser.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/ClassParser.java
@@ -616,15 +616,10 @@ public class ClassParser
public Set<String> parseClassFileUses(String path, InputStream in) throws Exception
{
- DataInputStream din = new DataInputStream(in);
- try
+ try (DataInputStream din = new DataInputStream(in))
{
return new Clazz(this, path).parseClassFileData(din);
}
- finally
- {
- din.close();
- }
}
private static class Clazz
diff --git a/framework/src/test/java/org/apache/felix/framework/cache/BundleCacheTest.java b/framework/src/test/java/org/apache/felix/framework/cache/BundleCacheTest.java
index 2c92c2877b..8160daa5e9 100644
--- a/framework/src/test/java/org/apache/felix/framework/cache/BundleCacheTest.java
+++ b/framework/src/test/java/org/apache/felix/framework/cache/BundleCacheTest.java
@@ -322,15 +322,10 @@ class BundleCacheTest
assertThat(target.getParentFile()).isDirectory();
- FileOutputStream output = new FileOutputStream(target);
- try
+ try (FileOutputStream output = new FileOutputStream(target))
{
output.write(content);
}
- finally
- {
- output.close();
- }
}
private void createJar(File source, File target) throws Exception