From afeeaddee5f18de34b77d20e5805213214378300 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Tue, 10 Oct 2017 17:43:46 +0300 Subject: [PATCH] debugger agent: catch all exceptions --- .../rt/debugger/agent/CaptureAgent.java | 92 +++++++++++-------- 1 file changed, 56 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 9e64241e6809..e8dfab095c86 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 @@ -25,45 +25,15 @@ public class CaptureAgent { private static Map> myCapturePoints = new HashMap>(); private static Map> myInsertPoints = new HashMap>(); - public static void premain(String args, Instrumentation instrumentation) throws IOException { + public static void premain(String args, Instrumentation instrumentation) { ourInstrumentation = instrumentation; - - boolean deleteSettings = true; - - FileReader reader = null; try { - reader = new FileReader(args); - Properties properties = new Properties(); - properties.load(reader); + String asmPath = readSettings(args); - DEBUG = Boolean.parseBoolean(properties.getProperty("debug", "false")); - if (DEBUG) { - CaptureStorage.setDebug(true); - } - - if (Boolean.parseBoolean(properties.getProperty("disabled", "false"))) { - CaptureStorage.setEnabled(false); - } - - deleteSettings = Boolean.parseBoolean(properties.getProperty("deleteSettings", "true")); - - String asmPath = properties.getProperty("asm-lib"); if (asmPath == null) { - System.out.println("Capture agent: asm path is not specified, exiting"); return; } - 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)); - } - } - try { instrumentation.appendToSystemClassLoaderSearch(new JarFile(asmPath)); } @@ -98,18 +68,68 @@ public class CaptureAgent { System.out.println("Capture agent: ready"); } } + catch (Throwable e) { + System.out.println("Capture agent: unknown exception"); + e.printStackTrace(); + } + } + + private static String readSettings(String path) { + FileReader reader = null; + try { + reader = new FileReader(path); + Properties properties = new Properties(); + 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")); + + String asmPath = properties.getProperty("asm-lib"); + if (asmPath == null) { + System.out.println("Capture agent: asm path is not specified, exiting"); + return null; + } + + 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(); + } + return asmPath; + } catch (IOException e) { System.out.println("Capture agent: unable to read settings"); e.printStackTrace(); } finally { if (reader != null) { - reader.close(); - } - if (deleteSettings) { - new File(args).delete(); + try { + reader.close(); + } + catch (IOException e) { + e.printStackTrace(); + } } } + return null; } private static List getNotNull(List list) {