X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=liblttng-ust-java-agent%2Fjava%2Flttng-ust-agent-common%2Forg%2Flttng%2Fust%2Fagent%2Fclient%2FLttngTcpSessiondClient.java;h=a0adceae6d32b0e9c1f9031b20dc422b07953678;hb=8d8c99c9eed441026e2dad93b685f2004034a321;hp=f78fdbd0f7c515d6bbecb589ae3454f2d2c83636;hpb=ffaea23347a6aa8f2d7c311e5d4feb7a891be182;p=lttng-ust.git diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java index f78fdbd0..a0adceae 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java @@ -204,27 +204,34 @@ public class LttngTcpSessiondClient implements Runnable { * @return port value if found else 0. */ private static int getPortFromFile(String path) throws IOException { - int port; BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(new FileInputStream(path), PORT_FILE_ENCODING)); String line = br.readLine(); - port = Integer.parseInt(line, 10); + if (line == null) { + /* File exists but is empty. */ + return 0; + } + + int port = Integer.parseInt(line, 10); if (port < 0 || port > 65535) { /* Invalid value. Ignore. */ port = 0; } + return port; + + } catch (NumberFormatException e) { + /* File contained something that was not a number. */ + return 0; } catch (FileNotFoundException e) { /* No port available. */ - port = 0; + return 0; } finally { if (br != null) { br.close(); } } - - return port; } private void registerToSessiond() throws IOException {