Skip to content

Commit 6690167

Browse files
committed
Fixed some IDE warnings
1 parent ba7ee80 commit 6690167

File tree

5 files changed

+60
-24
lines changed

5 files changed

+60
-24
lines changed

src/test/java/com/github/robtimus/io/stream/BinaryPipeTest.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ void testClosed() {
6868
@DisplayName("interrupt")
6969
void testInterrupt() throws InterruptedException {
7070
BinaryPipe pipe = new BinaryPipe();
71+
@SuppressWarnings("resource")
72+
InputStream input = pipe.input();
7173
AtomicReference<InterruptedIOException> exception = new AtomicReference<>();
7274
Thread thread = new Thread(() -> {
73-
exception.set(assertThrows(InterruptedIOException.class, () -> pipe.input().read()));
75+
exception.set(assertThrows(InterruptedIOException.class, () -> input.read()));
7476
});
7577
thread.start();
7678
thread.interrupt();
@@ -288,7 +290,9 @@ void testWriteInt() throws IOException, InterruptedException {
288290
readLatch.await();
289291
assertArrayEquals(expected, result.get());
290292

291-
assertClosed(() -> pipe.output().write(0));
293+
@SuppressWarnings("resource")
294+
OutputStream output = pipe.output();
295+
assertClosed(() -> output.write(0));
292296
}
293297

294298
@Test
@@ -315,7 +319,9 @@ void testWriteByteArrayRange() throws IOException, InterruptedException {
315319
readLatch.await();
316320
assertArrayEquals(expected, result.get());
317321

318-
assertClosed(() -> pipe.output().write(expected));
322+
@SuppressWarnings("resource")
323+
OutputStream output = pipe.output();
324+
assertClosed(() -> output.write(expected));
319325
}
320326

321327
@Test
@@ -334,20 +340,23 @@ void testOperationsWithReadError() throws IOException {
334340

335341
BinaryPipe pipe = new BinaryPipe();
336342
try (OutputStream output = pipe.output()) {
343+
@SuppressWarnings("resource")
344+
PipeInputStream input = pipe.input();
345+
337346
IOException error = new IOException();
338-
pipe.input().close(error);
347+
input.close(error);
339348

340349
assertSame(error, assertThrows(IOException.class, () -> output.write(bytes[0])));
341350
assertSame(error, assertThrows(IOException.class, () -> output.write(bytes, 0, 5)));
342351
assertSame(error, assertThrows(IOException.class, () -> output.flush()));
343352

344-
pipe.input().close();
353+
input.close();
345354

346355
assertSame(error, assertThrows(IOException.class, () -> output.write(bytes[0])));
347356
assertSame(error, assertThrows(IOException.class, () -> output.write(bytes, 0, 5)));
348357
assertSame(error, assertThrows(IOException.class, () -> output.flush()));
349358

350-
pipe.input().close(null);
359+
input.close(null);
351360

352361
assertClosed(() -> output.write(bytes[0]));
353362
assertClosed(() -> output.write(bytes, 0, 5));
@@ -388,7 +397,9 @@ void testWriteInt() throws InterruptedException {
388397
Arrays.sort(actual);
389398
assertArrayEquals(expected, actual);
390399

391-
assertClosed(() -> pipe.output().write(0));
400+
@SuppressWarnings("resource")
401+
OutputStream output = pipe.output();
402+
assertClosed(() -> output.write(0));
392403
}
393404

394405
@Test
@@ -420,7 +431,9 @@ void testWriteByteArrayRange() throws InterruptedException {
420431
Arrays.sort(actual);
421432
assertArrayEquals(expected, actual);
422433

423-
assertClosed(() -> pipe.output().write(bytes));
434+
@SuppressWarnings("resource")
435+
OutputStream output = pipe.output();
436+
assertClosed(() -> output.write(bytes));
424437
}
425438
}
426439

src/test/java/com/github/robtimus/io/stream/LimitOutputStreamTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class LimitOutputStreamTest extends TestBase {
3838
@Test
3939
@DisplayName("negative limit")
4040
void testNegativeLimit() {
41-
OutputStream outputStream = NullOutputStream.NULL_OUTPUT_STREAM;
41+
OutputStream outputStream = NullOutputStream.INSTANCE;
4242
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new LimitOutputStream(outputStream, -1));
4343
assertEquals("-1 < 0", exception.getMessage());
4444
}

src/test/java/com/github/robtimus/io/stream/LimitWriterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class LimitWriterTest extends TestBase {
3737
@Test
3838
@DisplayName("negative limit")
3939
void testNegativeLimit() {
40-
Writer writer = NullWriter.NULL_WRITER;
40+
Writer writer = NullWriter.INSTANCE;
4141
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new LimitWriter(writer, -1));
4242
assertEquals("-1 < 0", exception.getMessage());
4343
}

src/test/java/com/github/robtimus/io/stream/TextPipeTest.java

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ void testClosed() {
7171
@DisplayName("interrupt")
7272
void testInterrupt() throws InterruptedException {
7373
TextPipe pipe = new TextPipe();
74+
@SuppressWarnings("resource")
75+
Reader input = pipe.input();
7476
AtomicReference<InterruptedIOException> exception = new AtomicReference<>();
7577
Thread thread = new Thread(() -> {
76-
exception.set(assertThrows(InterruptedIOException.class, () -> pipe.input().read()));
78+
exception.set(assertThrows(InterruptedIOException.class, () -> input.read()));
7779
});
7880
thread.start();
7981
thread.interrupt();
@@ -301,7 +303,9 @@ void testWriteInt() throws IOException, InterruptedException {
301303
readLatch.await();
302304
assertEquals(SOURCE, result.get());
303305

304-
assertClosed(() -> pipe.output().write('*'));
306+
@SuppressWarnings("resource")
307+
Writer output = pipe.output();
308+
assertClosed(() -> output.write('*'));
305309
}
306310

307311
@Test
@@ -328,7 +332,9 @@ void testWriteCharArrayRange() throws IOException, InterruptedException {
328332
readLatch.await();
329333
assertEquals(SOURCE, result.get());
330334

331-
assertClosed(() -> pipe.output().write(chars));
335+
@SuppressWarnings("resource")
336+
Writer output = pipe.output();
337+
assertClosed(() -> output.write(chars));
332338
}
333339

334340
@Test
@@ -353,7 +359,9 @@ void testWriteStringRange() throws IOException, InterruptedException {
353359
readLatch.await();
354360
assertEquals(SOURCE, result.get());
355361

356-
assertClosed(() -> pipe.output().write(SOURCE));
362+
@SuppressWarnings("resource")
363+
Writer output = pipe.output();
364+
assertClosed(() -> output.write(SOURCE));
357365
}
358366

359367
@Test
@@ -382,7 +390,8 @@ private void testAppendCharSequence(Function<String, CharSequence> mapper) throw
382390
readLatch.await();
383391
assertEquals(SOURCE + "null", result.get());
384392

385-
assertClosed(() -> pipe.output().append(SOURCE));
393+
Writer output = pipe.output();
394+
assertClosed(() -> output.append(SOURCE));
386395
}
387396

388397
@Test
@@ -416,7 +425,9 @@ private void testAppendSubSequence(Function<String, CharSequence> mapper) throws
416425
readLatch.await();
417426
assertEquals(SOURCE + "ul", result.get());
418427

419-
assertClosed(() -> pipe.output().write(SOURCE, 0, 10));
428+
@SuppressWarnings("resource")
429+
Writer output = pipe.output();
430+
assertClosed(() -> output.write(SOURCE, 0, 10));
420431
}
421432

422433
@Test
@@ -434,7 +445,9 @@ void testAppendChar() throws IOException, InterruptedException {
434445
readLatch.await();
435446
assertEquals(SOURCE, result.get());
436447

437-
assertClosed(() -> pipe.output().write('*'));
448+
@SuppressWarnings("resource")
449+
Writer output = pipe.output();
450+
assertClosed(() -> output.write('*'));
438451
}
439452

440453
@Test
@@ -453,8 +466,11 @@ void testOperationsWithReadError() throws IOException {
453466

454467
TextPipe pipe = new TextPipe();
455468
try (Writer output = pipe.output()) {
469+
@SuppressWarnings("resource")
470+
PipeReader input = pipe.input();
471+
456472
IOException error = new IOException();
457-
pipe.input().close(error);
473+
input.close(error);
458474

459475
assertSame(error, assertThrows(IOException.class, () -> output.write(chars[0])));
460476
assertSame(error, assertThrows(IOException.class, () -> output.write(chars, 0, 5)));
@@ -464,7 +480,7 @@ void testOperationsWithReadError() throws IOException {
464480
assertSame(error, assertThrows(IOException.class, () -> output.append(chars[0])));
465481
assertSame(error, assertThrows(IOException.class, () -> output.flush()));
466482

467-
pipe.input().close();
483+
input.close();
468484

469485
assertSame(error, assertThrows(IOException.class, () -> output.write(chars[0])));
470486
assertSame(error, assertThrows(IOException.class, () -> output.write(chars, 0, 5)));
@@ -474,7 +490,7 @@ void testOperationsWithReadError() throws IOException {
474490
assertSame(error, assertThrows(IOException.class, () -> output.append(chars[0])));
475491
assertSame(error, assertThrows(IOException.class, () -> output.flush()));
476492

477-
pipe.input().close(null);
493+
input.close(null);
478494

479495
assertClosed(() -> output.write(chars[0]));
480496
assertClosed(() -> output.write(chars, 0, 5));
@@ -517,7 +533,9 @@ void testWriteInt() throws InterruptedException {
517533
Arrays.sort(actual);
518534
assertArrayEquals(expected, actual);
519535

520-
assertClosed(() -> pipe.output().write(0));
536+
@SuppressWarnings("resource")
537+
Writer output = pipe.output();
538+
assertClosed(() -> output.write(0));
521539
}
522540

523541
@Test
@@ -547,7 +565,9 @@ void testWriteCharArrayRange() throws InterruptedException {
547565
Arrays.sort(actual);
548566
assertArrayEquals(expected, actual);
549567

550-
assertClosed(() -> pipe.output().write(SOURCE));
568+
@SuppressWarnings("resource")
569+
Writer output = pipe.output();
570+
assertClosed(() -> output.write(SOURCE));
551571
}
552572

553573
@Test
@@ -577,7 +597,9 @@ void testAppendSubSequence() throws InterruptedException {
577597
Arrays.sort(actual);
578598
assertArrayEquals(expected, actual);
579599

580-
assertClosed(() -> pipe.output().write(SOURCE));
600+
@SuppressWarnings("resource")
601+
Writer output = pipe.output();
602+
assertClosed(() -> output.write(SOURCE));
581603
}
582604
}
583605

@@ -665,7 +687,7 @@ void testAppendChar() throws IOException {
665687
try (Writer output = pipe.output()) {
666688
output.write(0);
667689
IOException thrown = assertThrows(IOException.class, () -> {
668-
output.write(0);
690+
output.append('\0');
669691
});
670692
assertEquals(Messages.pipe.readerDied(), thrown.getMessage());
671693
}

src/test/java/com/github/robtimus/io/stream/web/TestFilter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ private CapturingHttpServletRequest(HttpServletRequest request) {
8787
}
8888

8989
@Override
90+
@SuppressWarnings("resource")
9091
public ServletInputStream getInputStream() throws IOException {
9192
if (inputStream == null) {
9293
CapturingInputStream capturing = new CapturingInputStream(super.getInputStream(), CapturingInputStream.config()

0 commit comments

Comments
 (0)