Skip to content

Commit ce5a9de

Browse files
authored
fix: improve use of InputStream in PackageURLTest (#171)
* Fix memory leak with `InputStream` * `JSONTokener` is able to load the `InputStream` directly, removing the test dependency on Commons IO
1 parent f926adf commit ce5a9de

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,6 @@
123123
<version>20240303</version>
124124
<scope>test</scope>
125125
</dependency>
126-
<dependency>
127-
<groupId>commons-io</groupId>
128-
<artifactId>commons-io</artifactId>
129-
<version>2.15.1</version>
130-
<scope>test</scope>
131-
</dependency>
132126
</dependencies>
133127

134128
<build>

src/test/java/com/github/packageurl/PackageURLTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@
2323

2424
import java.io.IOException;
2525
import java.io.InputStream;
26-
import java.nio.charset.StandardCharsets;
2726
import java.util.HashMap;
2827
import java.util.Map;
2928
import java.util.Locale;
3029
import java.util.TreeMap;
3130

32-
import org.apache.commons.io.IOUtils;
3331
import org.json.JSONArray;
3432
import org.json.JSONObject;
3533
import org.junit.AfterClass;
34+
import org.json.JSONTokener;
3635
import org.junit.Assert;
3736
import org.junit.BeforeClass;
3837
import org.junit.Rule;
@@ -57,10 +56,11 @@ public class PackageURLTest {
5756

5857
@BeforeClass
5958
public static void setup() throws IOException {
60-
InputStream is = PackageURLTest.class.getResourceAsStream("/test-suite-data.json");
61-
Assert.assertNotNull(is);
62-
String jsonTxt = IOUtils.toString(is, StandardCharsets.UTF_8);
63-
json = new JSONArray(jsonTxt);
59+
try (InputStream is = PackageURLTest.class.getResourceAsStream("/test-suite-data.json")) {
60+
Assert.assertNotNull(is);
61+
json = new JSONArray(new JSONTokener(is));
62+
}
63+
6464
defaultLocale = Locale.getDefault();
6565
Locale.setDefault(new Locale("tr"));
6666
}

0 commit comments

Comments
 (0)