Skip to content

Commit

Permalink
Merge pull request #6347 from pkriens/build/resource-leaks-in-test-we…
Browse files Browse the repository at this point in the history
…re-visible-in-eclipse

Fixes resource leaks warnings in tests
  • Loading branch information
pkriens authored Nov 1, 2024
2 parents 544d5b3 + dae6deb commit 560a0b4
Show file tree
Hide file tree
Showing 18 changed files with 306 additions and 272 deletions.
423 changes: 219 additions & 204 deletions aQute.libg/test/aQute/lib/io/LineSeparatorBufferedReaderTest.java

Large diffs are not rendered by default.

40 changes: 21 additions & 19 deletions biz.aQute.bnd.util/test/aQute/bnd/unmodifiable/ListsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,17 +513,18 @@ public void serialization() throws Exception {
try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(list);
}
ObjectInputStream ois = new ObjectInputStream(new ByteBufferInputStream(bos.toByteBuffer()));
@SuppressWarnings("unchecked")
List<String> deser = (List<String>) ois.readObject();

assertThat(deser).isEqualTo(list)
.isNotSameAs(list)
.containsExactlyElementsOf(list);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.add("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("e1"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.clear());
try (ObjectInputStream ois = new ObjectInputStream(new ByteBufferInputStream(bos.toByteBuffer()))) {
@SuppressWarnings("unchecked")
List<String> deser = (List<String>) ois.readObject();

assertThat(deser).isEqualTo(list)
.isNotSameAs(list)
.containsExactlyElementsOf(list);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.add("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("e1"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.clear());
}
}

@Test
Expand All @@ -533,14 +534,15 @@ public void serialization_zero() throws Exception {
try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(list);
}
ObjectInputStream ois = new ObjectInputStream(new ByteBufferInputStream(bos.toByteBuffer()));
@SuppressWarnings("unchecked")
List<String> deser = (List<String>) ois.readObject();

assertThat(deser).isSameAs(list);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.add("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.clear());
try (ObjectInputStream ois = new ObjectInputStream(new ByteBufferInputStream(bos.toByteBuffer()))) {
@SuppressWarnings("unchecked")
List<String> deser = (List<String>) ois.readObject();

assertThat(deser).isSameAs(list);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.add("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.clear());
}
}

@Test
Expand Down
40 changes: 21 additions & 19 deletions biz.aQute.bnd.util/test/aQute/bnd/unmodifiable/MapsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -823,17 +823,18 @@ public void serialization() throws Exception {
try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(map);
}
ObjectInputStream ois = new ObjectInputStream(new ByteBufferInputStream(bos.toByteBuffer()));
@SuppressWarnings("unchecked")
Map<String, String> deser = (Map<String, String>) ois.readObject();

assertThat(deser).isEqualTo(map)
.isNotSameAs(map)
.containsExactlyEntriesOf(map);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.put("a", "b"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("k1"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.clear());
try (ObjectInputStream ois = new ObjectInputStream(new ByteBufferInputStream(bos.toByteBuffer()))) {
@SuppressWarnings("unchecked")
Map<String, String> deser = (Map<String, String>) ois.readObject();

assertThat(deser).isEqualTo(map)
.isNotSameAs(map)
.containsExactlyEntriesOf(map);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.put("a", "b"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("k1"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.clear());
}
}

@Test
Expand All @@ -843,14 +844,15 @@ public void serialization_zero() throws Exception {
try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(map);
}
ObjectInputStream ois = new ObjectInputStream(new ByteBufferInputStream(bos.toByteBuffer()));
@SuppressWarnings("unchecked")
Map<String, String> deser = (Map<String, String>) ois.readObject();

assertThat(deser).isSameAs(map);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.put("a", "b"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.clear());
try (ObjectInputStream ois = new ObjectInputStream(new ByteBufferInputStream(bos.toByteBuffer()))) {
@SuppressWarnings("unchecked")
Map<String, String> deser = (Map<String, String>) ois.readObject();

assertThat(deser).isSameAs(map);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.put("a", "b"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.clear());
}
}

}
40 changes: 21 additions & 19 deletions biz.aQute.bnd.util/test/aQute/bnd/unmodifiable/SetsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,18 @@ public void serialization() throws Exception {
try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(set);
}
ObjectInputStream ois = new ObjectInputStream(new ByteBufferInputStream(bos.toByteBuffer()));
@SuppressWarnings("unchecked")
Set<String> deser = (Set<String>) ois.readObject();

assertThat(deser).isEqualTo(set)
.isNotSameAs(set)
.containsExactlyElementsOf(set);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.add("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("e1"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.clear());
try (ObjectInputStream ois = new ObjectInputStream(new ByteBufferInputStream(bos.toByteBuffer()))) {
@SuppressWarnings("unchecked")
Set<String> deser = (Set<String>) ois.readObject();

assertThat(deser).isEqualTo(set)
.isNotSameAs(set)
.containsExactlyElementsOf(set);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.add("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("e1"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.clear());
}
}

@Test
Expand All @@ -350,14 +351,15 @@ public void serialization_zero() throws Exception {
try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(set);
}
ObjectInputStream ois = new ObjectInputStream(new ByteBufferInputStream(bos.toByteBuffer()));
@SuppressWarnings("unchecked")
Set<String> deser = (Set<String>) ois.readObject();

assertThat(deser).isSameAs(set);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.add("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.clear());
try (ObjectInputStream ois = new ObjectInputStream(new ByteBufferInputStream(bos.toByteBuffer()))) {
@SuppressWarnings("unchecked")
Set<String> deser = (Set<String>) ois.readObject();

assertThat(deser).isSameAs(set);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.add("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.remove("a"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> deser.clear());
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class LaunchpadWorkspace {
@SuppressWarnings("unused")
private static Workspace ws;

@SuppressWarnings("resource")
static LaunchpadBuilder builder = new LaunchpadBuilder().runfw("org.apache.felix.framework;version=@5");

static {
Expand Down
17 changes: 9 additions & 8 deletions biz.aQute.bndlib.tests/test/test/BndEditModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,17 @@ public void testGetPropertiesWithFileReplace() throws Exception {

@Test
public void testGetPropertiesWithWorkspaceMacros() throws Exception {
Workspace ws = new Workspace(new File("testresources/ws"));
Project project = ws.getProject("p1");
BndEditModel model = new BndEditModel(project);
model.setGenericString("ws", "${workspace}");
model.setGenericString("pro", "${project}");
Processor p = model.getProperties();
try (Workspace ws = new Workspace(new File("testresources/ws"))) {
Project project = ws.getProject("p1");
BndEditModel model = new BndEditModel(project);
model.setGenericString("ws", "${workspace}");
model.setGenericString("pro", "${project}");
Processor p = model.getProperties();

assertThat(p.getProperty("ws")).isEqualTo(getPortablePath(ws.getBase()));
assertThat(p.getProperty("ws")).isEqualTo(getPortablePath(ws.getBase()));

assertThat(p.getProperty("pro")).isEqualTo(getPortablePath(project.getBase()));
assertThat(p.getProperty("pro")).isEqualTo(getPortablePath(project.getBase()));
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public class SettingsParser extends XPathParser {
final SettingsDTO settings = new SettingsDTO();
@SuppressWarnings("resource")
private final Macro replacer = new Processor().getReplacer();

/*
Expand Down
4 changes: 3 additions & 1 deletion biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,9 @@ private boolean addAll(Jar to, Jar sub, Instruction filter, String destination,
return dupl;
}

@SuppressWarnings("deprecation")
@SuppressWarnings({
"deprecation", "resource"
})
private void copy(Jar jar, String path, File from, Instructions preprocess, Map<String, String> extra)
throws Exception {
if (doNotCopy(from))
Expand Down
3 changes: 1 addition & 2 deletions biz.aQute.bndlib/src/aQute/bnd/osgi/Jar.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public Jar(String string, File file) throws IOException {
}


private Jar buildFromDirectory(final Path baseDir, final Pattern doNotCopy) throws IOException {
private void buildFromDirectory(final Path baseDir, final Pattern doNotCopy) throws IOException {
Files.walkFileTree(baseDir, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
new SimpleFileVisitor<Path>() {
@Override
Expand Down Expand Up @@ -292,7 +292,6 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
return FileVisitResult.CONTINUE;
}
});
return this;
}

private Jar buildFromZip(File file) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class BeforeAfterTest {
static final String org_apache_felix_framework = "org.apache.felix.framework;version='[6.0.5,7)'";
static final String org_apache_felix_scr = "org.apache.felix.scr;version='[2.1.12,2.1.13)'";

@SuppressWarnings("resource")
static LaunchpadBuilder builder = new LaunchpadBuilder().runfw(org_apache_felix_framework)
.bundles("assertj-core")
.bundles("net.bytebuddy.byte-buddy")
Expand Down
1 change: 1 addition & 0 deletions biz.aQute.launchpad.tests/test/aQute/xlaunchpad/FO.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class FO {
static File tmp = new File("generated/snapshot");

@SuppressWarnings("resource")
static LaunchpadBuilder builder = new LaunchpadBuilder().snapshot()
.set("snapshot.dir", tmp.getAbsolutePath())
.runfw("org.apache.felix.framework;version='[7.0.5,7.0.5]'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public class LaunchpadConfigurationTest {
static File tmp = new File("generated/snapshot");

@SuppressWarnings("resource")
static LaunchpadBuilder builder = new LaunchpadBuilder().snapshot()
.set("snapshot.dir", tmp.getAbsolutePath())
.bndrun("runsystempackages.bndrun")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public class LaunchpadRunnerBasicTest {
static File tmp = new File("generated/snapshot");

@SuppressWarnings("resource")
static LaunchpadBuilder builder = new LaunchpadBuilder().snapshot()
.set("snapshot.dir", tmp.getAbsolutePath())
.bndrun("runsystempackages.bndrun")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Manual {
static final String org_apache_felix_scr = "org.apache.felix.scr;version='[2.1.12,2.1.13)'";
static final String org_apache_felix_log = "org.apache.felix.log;version='[1.2.0,1.2.1)'";
static final String org_apache_felix_configadmin = "org.apache.felix.configadmin;version='[1.9.10,1.9.11)'";
@SuppressWarnings("resource")
LaunchpadBuilder builder = new LaunchpadBuilder().runfw(org_apache_felix_framework);

@Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* consider for the plugins.
*/
public class WorkspaceTest {
@SuppressWarnings("resource")
static LaunchpadBuilder builder = new LaunchpadBuilder().bndrun("workspace.bndrun");

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

public class JunitRuleTest {

@SuppressWarnings("resource")
static LaunchpadBuilder builder = new LaunchpadBuilder().runfw("org.apache.felix.framework");

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@

@SuppressWarnings("restriction")
public class BundleEngineTest {
@SuppressWarnings("resource")
private LaunchpadBuilder builder = new LaunchpadBuilder().bndrun("bundleenginetest.bndrun")
.excludeExport("aQute.tester.bundle.engine")
.excludeExport("aQute.tester.bundle.engine.discovery")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public boolean performFinish() {
}
}

@SuppressWarnings("resource")
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
this.workbench = workbench;
Expand Down

0 comments on commit 560a0b4

Please sign in to comment.