From 0ec60e9bfb24f08e5f42580f38bb8561fba77fe8 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Wed, 7 Mar 2018 16:20:35 +0300 Subject: [PATCH] IDEA-184352 java.io.FileNotFoundException - correctly remove the settings file (IDEA-CR-30232) --- .../rt/debugger/agent/CaptureAgent.java | 69 +++++++++---------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/java/debugger/debugger-agent/src/com/intellij/rt/debugger/agent/CaptureAgent.java b/java/debugger/debugger-agent/src/com/intellij/rt/debugger/agent/CaptureAgent.java index d58b0167bbf4..05def4fb65be 100644 --- a/java/debugger/debugger-agent/src/com/intellij/rt/debugger/agent/CaptureAgent.java +++ b/java/debugger/debugger-agent/src/com/intellij/rt/debugger/agent/CaptureAgent.java @@ -11,7 +11,6 @@ import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.Instrumentation; import java.lang.instrument.UnmodifiableClassException; import java.net.URI; -import java.net.URISyntaxException; import java.security.ProtectionDomain; import java.util.*; @@ -69,47 +68,19 @@ public class CaptureAgent { System.setProperty(modulesKey, property); } - private static void readSettings(String path) { + private static void readSettings(String uri) { + Properties properties = new Properties(); + File file; FileReader reader = null; try { - reader = new FileReader(new URI(path).getPath()); - Properties properties = new Properties(); + file = new File(new URI(uri)); + reader = new FileReader(file); properties.load(reader); - - DEBUG = Boolean.parseBoolean(properties.getProperty("debug", "false")); - if (DEBUG) { - CaptureStorage.setDebug(true); - } - - if (Boolean.parseBoolean(properties.getProperty("disabled", "false"))) { - CaptureStorage.setEnabled(false); - } - - boolean deleteSettings = Boolean.parseBoolean(properties.getProperty("deleteSettings", "true")); - - Enumeration propNames = properties.propertyNames(); - while (propNames.hasMoreElements()) { - String propName = (String)propNames.nextElement(); - if (propName.startsWith("capture")) { - addPoint(true, properties.getProperty(propName)); - } - else if (propName.startsWith("insert")) { - addPoint(false, properties.getProperty(propName)); - } - } - - // delete settings file only if it was read correctly - if (deleteSettings) { - new File(path).delete(); - } } - catch (IOException e) { - System.out.println("Capture agent: unable to read settings"); - e.printStackTrace(); - } - catch (URISyntaxException e) { + catch (Exception e) { System.out.println("Capture agent: unable to read settings"); e.printStackTrace(); + return; } finally { if (reader != null) { @@ -121,6 +92,32 @@ public class CaptureAgent { } } } + + DEBUG = Boolean.parseBoolean(properties.getProperty("debug", "false")); + if (DEBUG) { + CaptureStorage.setDebug(true); + } + + if (Boolean.parseBoolean(properties.getProperty("disabled", "false"))) { + CaptureStorage.setEnabled(false); + } + + Enumeration propNames = properties.propertyNames(); + while (propNames.hasMoreElements()) { + String propName = (String)propNames.nextElement(); + if (propName.startsWith("capture")) { + addPoint(true, properties.getProperty(propName)); + } + else if (propName.startsWith("insert")) { + addPoint(false, properties.getProperty(propName)); + } + } + + // delete settings file only if it was read correctly + if (Boolean.parseBoolean(properties.getProperty("deleteSettings", "true"))) { + //noinspection ResultOfMethodCallIgnored + file.delete(); + } } private static List getNotNull(List list) {