Skip to content

Commit ee39dc4

Browse files
author
TLS-Attacker Developer
committed
Fix OBL_UNSATISFIED_OBLIGATION issue in Scanner class
Added missing close() method implementation to Scanner class which implements AutoCloseable. This fixes the static analysis warning about potentially unclosed resources. Also added ScannerTest to verify the close() method works correctly.
1 parent d4a3032 commit ee39dc4

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

src/main/java/de/rub/nds/scanner/core/execution/Scanner.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,10 @@ protected void registerProbeForExecution(ProbeT probe, boolean executeByDefault)
259259
protected void registerProbeForExecution(AfterProbeT afterProbe) {
260260
afterList.add(afterProbe);
261261
}
262+
263+
@Override
264+
public void close() throws Exception {
265+
// No resources to close in base Scanner class
266+
// Subclasses can override this method if they have resources to clean up
267+
}
262268
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Scanner Core - A Modular Framework for Probe Definition, Execution, and Result Analysis.
3+
*
4+
* Copyright 2017-2023 Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
5+
*
6+
* Licensed under Apache License, Version 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0.txt
8+
*/
9+
package de.rub.nds.scanner.core.execution;
10+
11+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
12+
13+
import de.rub.nds.scanner.core.afterprobe.AfterProbe;
14+
import de.rub.nds.scanner.core.config.ExecutorConfig;
15+
import de.rub.nds.scanner.core.passive.StatsWriter;
16+
import de.rub.nds.scanner.core.probe.ProbeType;
17+
import de.rub.nds.scanner.core.probe.ScannerProbe;
18+
import de.rub.nds.scanner.core.probe.requirements.FulfilledRequirement;
19+
import de.rub.nds.scanner.core.probe.requirements.Requirement;
20+
import de.rub.nds.scanner.core.report.ScanReport;
21+
import org.junit.jupiter.api.Test;
22+
23+
class ScannerTest {
24+
25+
@Test
26+
void testCloseMethod() {
27+
// Test that the Scanner's close() method can be called without throwing exceptions
28+
ExecutorConfig config = new ExecutorConfig();
29+
TestScanner scanner = new TestScanner(config);
30+
31+
assertDoesNotThrow(
32+
() -> {
33+
try (TestScanner s = scanner) {
34+
// Using try-with-resources to ensure close() is called
35+
}
36+
});
37+
}
38+
39+
// Test implementation of Scanner for testing purposes
40+
private static class TestScanner
41+
extends Scanner<TestReport, TestProbe, TestAfterProbe, TestState> {
42+
43+
public TestScanner(ExecutorConfig executorConfig) {
44+
super(executorConfig);
45+
}
46+
47+
@Override
48+
protected void fillProbeLists() {
49+
// Empty implementation for testing
50+
}
51+
52+
@Override
53+
protected StatsWriter<TestState> getDefaultProbeWriter() {
54+
return null;
55+
}
56+
57+
@Override
58+
protected TestReport getEmptyReport() {
59+
return new TestReport();
60+
}
61+
62+
@Override
63+
protected boolean checkScanPrerequisites(TestReport report) {
64+
return true;
65+
}
66+
}
67+
68+
// Test implementations of required types
69+
private static class TestReport extends ScanReport {
70+
@Override
71+
public String getRemoteName() {
72+
return "test";
73+
}
74+
75+
@Override
76+
public void serializeToJson(java.io.OutputStream outputStream) {
77+
// Empty implementation for testing
78+
}
79+
}
80+
81+
private static class TestProbe extends ScannerProbe<TestReport, TestState> {
82+
public TestProbe() {
83+
super(new TestProbeType());
84+
}
85+
86+
@Override
87+
public void executeTest() {
88+
// Empty implementation
89+
}
90+
91+
@Override
92+
public void adjustConfig(TestReport report) {
93+
// Empty implementation
94+
}
95+
96+
@Override
97+
public void mergeData(TestReport report) {
98+
// Empty implementation for testing
99+
}
100+
101+
@Override
102+
public Requirement<TestReport> getRequirements() {
103+
return new FulfilledRequirement<>();
104+
}
105+
}
106+
107+
private static class TestProbeType implements ProbeType {
108+
@Override
109+
public String getName() {
110+
return "TEST_PROBE";
111+
}
112+
}
113+
114+
private static class TestAfterProbe extends AfterProbe<TestReport> {
115+
@Override
116+
public void analyze(TestReport report) {
117+
// Empty implementation
118+
}
119+
}
120+
121+
private static class TestState {
122+
// Empty state class for testing
123+
}
124+
}

0 commit comments

Comments
 (0)