diff options
author | Paul Pazderski | 2020-01-07 20:18:37 +0000 |
---|---|---|
committer | Paul Pazderski | 2020-01-11 21:58:14 +0000 |
commit | 492af0407faf9dc981b28d99abff4642d126534c (patch) | |
tree | f68db19076a7663b20c096a10e11ff67f1298e33 | |
parent | e0f10fa9497237de090d33902fea61c5f05336c2 (diff) | |
download | eclipse.platform.debug-492af0407faf9dc981b28d99abff4642d126534c.tar.gz eclipse.platform.debug-492af0407faf9dc981b28d99abff4642d126534c.tar.xz eclipse.platform.debug-492af0407faf9dc981b28d99abff4642d126534c.zip |
Bug 559070 - Fix resource related compiler warnings in platform.debug
Change-Id: If9102e5fcd24e7888596fd33a14ed5529419acc2
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
9 files changed, 66 insertions, 27 deletions
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/containers/ZipEntryStorage.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/containers/ZipEntryStorage.java index 2bf9eeef3..5ffe0fcb4 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/containers/ZipEntryStorage.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/sourcelookup/containers/ZipEntryStorage.java @@ -38,6 +38,7 @@ import org.eclipse.debug.internal.core.sourcelookup.SourceLookupMessages; * @since 3.0 * @noextend This class is not intended to be subclassed by clients. */ +@SuppressWarnings("resource") public class ZipEntryStorage extends PlatformObject implements IStorage { /** diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/NullStreamsProxy.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/NullStreamsProxy.java index 9a399e27d..4ac805433 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/NullStreamsProxy.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/NullStreamsProxy.java @@ -24,6 +24,7 @@ public class NullStreamsProxy implements IStreamsProxy2 { private NullStreamMonitor outputStreamMonitor; private NullStreamMonitor errorStreamMonitor; + @SuppressWarnings("resource") public NullStreamsProxy(Process process) { outputStreamMonitor = new NullStreamMonitor(process.getInputStream()); errorStreamMonitor = new NullStreamMonitor(process.getErrorStream()); diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java index 823757fb8..54fc4c9f6 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/StreamsProxy.java @@ -52,6 +52,7 @@ public class StreamsProxy implements IStreamsProxy, IStreamsProxy2 { * @param process system process to create a streams proxy on * @param charset the process's charset or <code>null</code> if default */ + @SuppressWarnings("resource") public StreamsProxy(Process process, Charset charset) { if (process == null) { return; diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTestUtil.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTestUtil.java index ce67942cc..526d26374 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTestUtil.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTestUtil.java @@ -122,6 +122,7 @@ public final class IOConsoleTestUtil { * @return this {@link IOConsoleTestUtil} to chain methods * @see #write(String) */ + @SuppressWarnings("resource") public IOConsoleTestUtil writeFast(final String s) throws IOException { return writeFast(s, getDefaultOutputStream()); } @@ -134,6 +135,7 @@ public final class IOConsoleTestUtil { * @return this {@link IOConsoleTestUtil} to chain methods * @see #writeFast(String) */ + @SuppressWarnings("resource") public IOConsoleTestUtil write(final String s) throws Exception { return write(s, getDefaultOutputStream()); } @@ -149,6 +151,7 @@ public final class IOConsoleTestUtil { * @param s content to write in output stream * @return this {@link IOConsoleTestUtil} to chain methods */ + @SuppressWarnings("resource") public IOConsoleTestUtil writeAndVerify(final String s) throws Exception { return writeAndVerify(s, getDefaultOutputStream()); } diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java index 88fa40207..1277b8196 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/IOConsoleTests.java @@ -274,14 +274,15 @@ public class IOConsoleTests extends AbstractDebugTest { final IOConsoleTestUtil c = getTestUtil("Test input file"); // open default output stream to match usual behavior where two output // streams are open and to prevent premature console closing - c.getDefaultOutputStream(); - try (InputStream in = new ByteArrayInputStream(new byte[0])) { - try (InputStream defaultIn = c.getConsole().getInputStream()) { - // just close input stream + try (IOConsoleOutputStream defaultOutputStream = c.getDefaultOutputStream()) { + try (InputStream in = new ByteArrayInputStream(new byte[0])) { + try (InputStream defaultIn = c.getConsole().getInputStream()) { + // just close input stream + } + c.getConsole().setInputStream(in); } - c.getConsole().setInputStream(in); + closeConsole(c); } - closeConsole(c); assertEquals("Test triggered errors in IOConsole.", 0, loggedErrors.get()); } @@ -582,21 +583,23 @@ public class IOConsoleTests extends AbstractDebugTest { */ public void testTrim() throws Exception { final IOConsoleTestUtil c = getTestUtil("Test trim"); - try (IOConsoleOutputStream otherOut = c.getConsole().newOutputStream()) { - c.writeFast("first\n"); - for (int i = 0; i < 20; i++) { - c.writeFast("0123456789\n", (i & 1) == 0 ? c.getDefaultOutputStream() : otherOut); + try (IOConsoleOutputStream defaultOut = c.getDefaultOutputStream()) { + try (IOConsoleOutputStream otherOut = c.getConsole().newOutputStream()) { + c.writeFast("first\n"); + for (int i = 0; i < 20; i++) { + c.writeFast("0123456789\n", (i & 1) == 0 ? defaultOut : otherOut); + } + c.write("last\n"); + c.verifyContentByLine("first", 0).verifyContentByLine("last", -2); + assertTrue("Document not filled.", c.getDocument().getNumberOfLines() > 15); + + c.getConsole().setWaterMarks(50, 100); + c.waitForScheduledJobs(); + c.verifyContentByOffset("0123456789", 0); + assertTrue("Document not trimmed.", c.getDocument().getNumberOfLines() < 15); } - c.write("last\n"); - c.verifyContentByLine("first", 0).verifyContentByLine("last", -2); - assertTrue("Document not filled.", c.getDocument().getNumberOfLines() > 15); - - c.getConsole().setWaterMarks(50, 100); - c.waitForScheduledJobs(); - c.verifyContentByOffset("0123456789", 0); - assertTrue("Document not trimmed.", c.getDocument().getNumberOfLines() < 15); + closeConsole(c); } - closeConsole(c); } /** diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ProcessConsoleTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ProcessConsoleTests.java index 10ff24470..3f7eb9f5c 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ProcessConsoleTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ProcessConsoleTests.java @@ -44,6 +44,7 @@ import org.eclipse.ui.console.ConsolePlugin; import org.eclipse.ui.console.IConsole; import org.eclipse.ui.console.IConsoleConstants; import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.IOConsoleInputStream; /** * Tests the ProcessConsole. @@ -139,7 +140,9 @@ public class ProcessConsoleTests extends AbstractDebugTest { final org.eclipse.debug.internal.ui.views.console.ProcessConsole console = new org.eclipse.debug.internal.ui.views.console.ProcessConsole(process, new ConsoleColorProvider(), StandardCharsets.UTF_8.toString()); try { console.initialize(); - console.getInputStream().appendData(input); + @SuppressWarnings("resource") + IOConsoleInputStream consoleIn = console.getInputStream(); + consoleIn.appendData(input); mockProcess.waitFor(testTimeout, TimeUnit.MILLISECONDS); } finally { console.destroy(); diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchConfigurationTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchConfigurationTests.java index e35e9e74a..c5797cfe3 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchConfigurationTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchConfigurationTests.java @@ -1267,8 +1267,11 @@ public class LaunchConfigurationTests extends AbstractLaunchTest implements ILau c2.doSave(); // file contents should be the same - char[] chars1 = getInputStreamAsCharArray(c1.getFile().getContents()); - char[] chars2 = getInputStreamAsCharArray(c2.getFile().getContents()); + char[] chars1, chars2; + try (InputStream in1 = c1.getFile().getContents(); InputStream in2 = c2.getFile().getContents()) { + chars1 = getInputStreamAsCharArray(in1); + chars2 = getInputStreamAsCharArray(in2); + } assertEquals("Should be the same characters", chars1.length, chars2.length); //$NON-NLS-1$ for (int i = 0; i < chars2.length; i++) { assertEquals("Should be the same character", chars1[i], chars2[i]); //$NON-NLS-1$ @@ -1345,8 +1348,11 @@ public class LaunchConfigurationTests extends AbstractLaunchTest implements ILau c2.doSave(); // file contents should be the same - char[] chars1 = getInputStreamAsCharArray(c1.getFile().getContents()); - char[] chars2 = getInputStreamAsCharArray(c2.getFile().getContents()); + char[] chars1, chars2; + try (InputStream in1 = c1.getFile().getContents(); InputStream in2 = c2.getFile().getContents()) { + chars1 = getInputStreamAsCharArray(in1); + chars2 = getInputStreamAsCharArray(in2); + } assertEquals("Should be the same characters", chars1.length, chars2.length); //$NON-NLS-1$ for (int i = 0; i < chars2.length; i++) { assertEquals("Should be the same character", chars1[i], chars2[i]); //$NON-NLS-1$ diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartition.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartition.java index 34ffa88c3..48af576ff 100644 --- a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartition.java +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartition.java @@ -236,6 +236,26 @@ public class IOConsolePartition implements ITypedRegion { return inputStream; } + /** + * Test if this partition belongs to the given input stream. + * + * @param in the input stream to test or <code>null</code> + * @return <code>true</code> if this partition belongs to input stream + */ + boolean belongsTo(IOConsoleInputStream in) { + return inputStream == in; + } + + /** + * Test if this partition belongs to the given output stream. + * + * @param out the output stream to test or <code>null</code> + * @return <code>true</code> if this partition belongs to output stream + */ + boolean belongsTo(IOConsoleOutputStream out) { + return outputStream == out; + } + @Override public String toString() { final StringBuilder sb = new StringBuilder(40); diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java index 3102a3ab0..f6df185ee 100644 --- a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java @@ -643,6 +643,7 @@ public class IOConsolePartitioner * and a new partition will start * @return the newly created partition (i.e. the right side of the split) */ + @SuppressWarnings("resource") // suppress wrong 'not closed' warnings private IOConsolePartition splitPartition(int offset) { final int partitionIndex = findPartitionCandidate(offset); final IOConsolePartition existingPartition = partitions.get(partitionIndex); @@ -861,7 +862,7 @@ public class IOConsolePartitioner Assert.isTrue(atOutputPartitionIndex == findPartitionCandidate(outputOffset - 1)); } } - if (atOutputPartition == null || atOutputPartition.getOutputStream() != pending.stream) { + if (atOutputPartition == null || !atOutputPartition.belongsTo(pending.stream)) { // no partitions yet or last partition is incompatible to reuse -> add new one atOutputPartition = new IOConsolePartition(outputOffset, pending.stream); partitions.add(atOutputPartition); @@ -904,7 +905,7 @@ public class IOConsolePartitioner atOutputPartition.getLength() - (outputOffset - atOutputPartition.getOffset())); Assert.isTrue(chunkLength > 0); // do not remove since it can prevent an infinity loop - if (atOutputPartition.getOutputStream() != pending.stream) { + if (!atOutputPartition.belongsTo(pending.stream)) { // new output is from other stream then overwritten output // Note: this implementation ignores the possibility to reuse the partition @@ -925,7 +926,7 @@ public class IOConsolePartitioner atOutputPartition = splitPartition(outputOffset); atOutputPartitionIndex++; } - if (outputPartition == null || outputPartition.getOutputStream() != pending.stream) { + if (outputPartition == null || !outputPartition.belongsTo(pending.stream)) { outputPartition = new IOConsolePartition(outputOffset, pending.stream); partitions.add(atOutputPartitionIndex, outputPartition); atOutputPartitionIndex++; |