diff options
author | Tor Norbye <tnorbye@google.com> | 2013-08-21 11:17:55 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2013-08-21 11:17:55 -0700 |
commit | d34b4c8d74407f5b2be1a344e41f2ecdeb25f4fe (patch) | |
tree | 1263896cdf5d3e25697287c40cf3a1d35de8e95d /plugins/InspectionGadgets/test | |
parent | 4db7dfd37df60de478b5d99be0554bc0e06dfdba (diff) | |
download | idea-d34b4c8d74407f5b2be1a344e41f2ecdeb25f4fe.tar.gz |
Snapshot 32d31e4915ef17b3ec6ec4e87923f017e8e41bce from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: Idb2188c1f4e63d654aa3e3b832b9121d0be2dbe9
Diffstat (limited to 'plugins/InspectionGadgets/test')
5 files changed, 21 insertions, 347 deletions
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/ChannelResourceInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/ChannelResourceInspection.java deleted file mode 100644 index c11d447b1210..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/ChannelResourceInspection.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.siyeh.igtest.resources; - -import org.jetbrains.annotations.NotNull; - -import java.io.*; -import java.net.Socket; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.net.ServerSocket; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.FileChannel; - -public class ChannelResourceInspection { - - public void foo2() throws IOException { - ServerSocket serverSocket = new ServerSocket(1, 1); - serverSocket.getChannel(); - try { - - } finally { - serverSocket.close(); - } - } - - public void foo3() throws IOException { - ServerSocket serverSocket = null; - serverSocket = new ServerSocket(1, 1); - ServerSocketChannel channel = serverSocket.getChannel(); - try { - } finally { - serverSocket.close(); - } - } - - public void foo4() throws IOException { - ServerSocket serverSocket = null; - serverSocket = new ServerSocket(1, 1); - ServerSocketChannel channel = serverSocket.getChannel(); - try { - channel.close(); - } finally { - serverSocket.close(); - } - } - - public void foo5() throws IOException { - ServerSocket serverSocket = null; - ServerSocketChannel channel = null; - serverSocket = new ServerSocket(1, 1); - channel = serverSocket.getChannel(); - try { - // do stuff - } finally { - channel.close(); - serverSocket.close(); - } - } - - public static void copyFile(@NotNull File from, @NotNull File to) - throws IOException { - if (from.getCanonicalPath().equals(to.getCanonicalPath())) - return; - final FileInputStream inStream = new FileInputStream(from); - try { - boolean success = false; - try { - final FileOutputStream outStream = new FileOutputStream(to); - try { - final FileChannel inChannel = inStream.getChannel(); - try { - final FileChannel outChannel = outStream.getChannel(); - try { - inChannel.transferTo(0, inChannel.size(), outChannel); - } - finally { - outChannel.close(); - } - } - finally { - inChannel.close(); - } - } - finally { - outStream.close(); - } - //copyLastModifiedDate( from, to ); - success = true; - } - finally { - if (!success) - to.delete(); - } - } - finally { - inStream.close(); - } - } - - public static void copy(FileInputStream source, - FileOutputStream target) - throws IOException { - FileChannel sourceChannel = source.getChannel(); // line 4 - FileChannel targetChannel = target.getChannel(); // line 5 - try { - sourceChannel.transferTo(0, sourceChannel.size(), - targetChannel); - } - finally { - try { - targetChannel.close(); - } - finally { - sourceChannel.close(); - } - } - } - - public static void copyFile2(File source, File target) - throws IOException { - final FileInputStream sourceStream = new FileInputStream(source); - try { - final FileOutputStream targetStream = - new FileOutputStream(target); - try { - copy(sourceStream, targetStream); - } - finally { - targetStream.close(); - } - } - finally { - sourceStream.close(); - } - } -} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/JDBCResourceInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/JDBCResourceInspection.java deleted file mode 100644 index c00cf709e3d8..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/JDBCResourceInspection.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.siyeh.igtest.resources; - -import java.sql.*; - -public class JDBCResourceInspection { - private Driver driver; - - public void foo() throws SQLException { - Connection connection = null; - try { - connection = driver.connect("foo", null); - } finally { - connection.close(); - } - - } - - public void foo2() throws SQLException { - Connection connection = null; - try { - connection = driver.connect("foo", null); - } finally { - } - } - - - public void foo3() throws SQLException { - Connection connection = null; - try { - connection = driver.connect("foo", null); - connection.createStatement(); - } finally { - connection.close(); - } - - } - - public void foo4() throws SQLException { - Connection connection = null; - Statement statement = null; - try { - connection = driver.connect("foo", null); - statement = connection.createStatement(); - } finally { - connection.close(); - } - - } - - public void foo5() throws SQLException { - Connection connection = null; - Statement statement = null; - try { - connection = driver.connect("foo", null); - statement = connection.createStatement(); - } finally { - statement.close(); - connection.close(); - } - - } - - public void foo6() throws SQLException { - Connection connection = null; - Statement statement = null; - try { - connection = driver.connect("foo", null); - statement = connection.prepareStatement("foo"); - } finally { - connection.close(); - } - - } - - public void foo7() throws SQLException { - Connection connection = null; - Statement statement = null; - try { - connection = driver.connect("foo", null); - statement = connection.prepareStatement("foo"); - } finally { - statement.close(); - connection.close(); - } - - } - - public void foo8() throws SQLException { - Connection connection = null; - Statement statement = null; - try { - connection = driver.connect("foo", null); - statement = connection.prepareCall("foo"); - } finally { - connection.close(); - } - - } - - public void foo9() throws SQLException { - Connection connection = null; - Statement statement = null; - try { - connection = driver.connect("foo", null); - statement = connection.prepareCall("foo"); - } finally { - statement.close(); - connection.close(); - } - - } - - public void foo10() throws SQLException { - Connection connection = null; - Statement statement = null; - ResultSet resultSet = null; - try { - connection = driver.connect("foo", null); - statement = connection.prepareCall("foo"); - resultSet = statement.executeQuery("foo"); - } finally { - statement.close(); - connection.close(); - } - - } - - public void foo11() throws SQLException { - Connection connection = null; - Statement statement = null; - ResultSet resultSet = null; - try { - connection = driver.connect("foo", null); - statement = connection.prepareCall("foo"); - resultSet = statement.executeQuery("foo"); - } finally { - resultSet.close(); - statement.close(); - connection.close(); - } - - } - -} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/SocketResourceInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/SocketResourceInspection.java deleted file mode 100644 index a1097c155a11..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/SocketResourceInspection.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.siyeh.igtest.resources; - -import java.io.*; -import java.net.Socket; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.net.ServerSocket; - -public class SocketResourceInspection { - public void foo() throws IOException, UnknownHostException { - new Socket( InetAddress.getLocalHost(), 1); - } - - public void foo2() throws IOException, UnknownHostException { - final Socket socket = new Socket(InetAddress.getLocalHost(), 1); - } - - public void foo25() throws IOException, UnknownHostException { - try { - final Socket socket = new Socket(InetAddress.getLocalHost(), 1); - } finally { - } - - } - - - public void foo3() throws IOException { - final Socket socket = new Socket(InetAddress.getLocalHost(), 1); - socket.close(); - } - - public void foo4() throws IOException { - Socket socket = null; - try { - socket = new Socket(InetAddress.getLocalHost(), 1); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - socket.close(); - } - - public void foo5() throws IOException { - Socket socket = null; - try { - socket = new Socket(InetAddress.getLocalHost(), 1); - } finally { - socket.close(); - } - } - public void foo6() throws IOException { - ServerSocket socket = null; - try{ - socket = new ServerSocket(1, 1); - } finally{ - } - } - public void foo7() throws IOException { - ServerSocket serverSocket = null; - try{ - serverSocket = new ServerSocket(1, 1); - Socket socket = serverSocket.accept(); - } finally{ - serverSocket.close(); - } - } - -} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/io/plain/IOResourceInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/io/plain/IOResourceInspection.java index 74481e3a9016..dacea8301f49 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/io/plain/IOResourceInspection.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/resources/io/plain/IOResourceInspection.java @@ -158,4 +158,24 @@ public class IOResourceInspection { writer.close(); } } + + void escaper(InputStream in) {} + + void escaped3() throws FileNotFoundException { + escaper(new FileInputStream("")); + } + + void escaped4() throws FileNotFoundException { + class X { + X(InputStream s) {} + } + new X(new FileInputStream("")) {}; + InputStream s = new FileInputStream(""); + new X(s) {}; + } + + void escaped5() throws FileNotFoundException { + InputStream in = new FileInputStream(""); + escaper(in); + } } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_semicolon/UnnecessarySemicolonInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_semicolon/UnnecessarySemicolonInspection.java index 13d978b455d1..67524e40023f 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_semicolon/UnnecessarySemicolonInspection.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_semicolon/UnnecessarySemicolonInspection.java @@ -1,6 +1,6 @@ package com.siyeh.igtest.style.unnecessary_semicolon;; -; +import java.util.List;; public class UnnecessarySemicolonInspection { int i; |