Skip to content

Commit

Permalink
Fix IDE warnings for unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Dec 15, 2024
1 parent e4c9e00 commit 37fbd31
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion java/org/apache/catalina/startup/ExpandWar.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public static String expand(Host host, URL war, String pathname) throws IOExcept
File warTracker = new File(host.getAppBaseFile(), pathname + Constants.WarTracker);
long warLastModified = -1;

try (InputStream is = jfuc.getInputStream()) {
try (@SuppressWarnings("unused")
InputStream is = jfuc.getInputStream()) {
// Get the last modified time for the WAR
warLastModified = jfuc.getLastModified();
}
Expand Down
3 changes: 2 additions & 1 deletion java/org/apache/jasper/servlet/JspCServletContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ public URL getResource(String path) throws MalformedURLException {
try {
URI uri = new URI(myResourceBaseURL.toExternalForm() + path);
url = uri.toURL();
try (InputStream is = url.openStream()) {
try (@SuppressWarnings("unused")
InputStream is = url.openStream()) {
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public void run() {
@Override
public void run() {
// Expected to fail
try (Connection c = ds.getConnection()) {
try (@SuppressWarnings("unused")
Connection c = ds.getConnection()) {
} catch (Exception e) {
System.err.println("Step 2:"+e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public void testDefaultAbandon() throws Exception {
this.datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(100);
this.datasource.getPoolProperties().setRemoveAbandoned(true);
this.datasource.getPoolProperties().setRemoveAbandonedTimeout(1);
try (Connection con = datasource.getConnection()) {
try (@SuppressWarnings("unused")
Connection con = datasource.getConnection()) {
Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive());
Thread.sleep(2000);
Assert.assertEquals("Number of connections active/busy should be 0",0,datasource.getPool().getActive());
Expand All @@ -51,7 +52,8 @@ public void testMaxedOutAbandon() throws Exception {
this.datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(100);
this.datasource.getPoolProperties().setRemoveAbandoned(true);
this.datasource.getPoolProperties().setRemoveAbandonedTimeout(1);
try (Connection con = datasource.getConnection()) {
try (@SuppressWarnings("unused")
Connection con = datasource.getConnection()) {
Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive());
Thread.sleep(2000);
Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public class TestException extends DefaultTestCase {
public void testException() throws Exception {
datasource.getPoolProperties().setJdbcInterceptors(TestInterceptor.class.getName());
Connection con = datasource.getConnection();
try (Statement s = con.createStatement()){
try (@SuppressWarnings("unused")
Statement s = con.createStatement()){
} catch (Exception x) {
Assert.fail();
}
Expand Down
6 changes: 4 additions & 2 deletions test/org/apache/tomcat/util/net/TestXxxEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public void testStartStopBindOnInit() throws Exception {

tomcat.getConnector().stop();
Exception e = null;
try (ServerSocket s = new ServerSocket(port, 100, InetAddress.getByName("localhost"))){
try (@SuppressWarnings("unused")
ServerSocket s = new ServerSocket(port, 100, InetAddress.getByName("localhost"))){
} catch (Exception e1) {
e = e1;
}
Expand All @@ -76,7 +77,8 @@ public void testStartStopBindOnStart() throws Exception {

tomcat.getConnector().stop();
Exception e = null;
try (ServerSocket s = new ServerSocket(port, 100, InetAddress.getByName("localhost"))) {
try (@SuppressWarnings("unused")
ServerSocket s = new ServerSocket(port, 100, InetAddress.getByName("localhost"))) {
// This should not throw an Exception
} catch (Exception e1) {
e = e1;
Expand Down

0 comments on commit 37fbd31

Please sign in to comment.