From 388dcff72518c96a15e38ff0b18be8a89836c2d5 Mon Sep 17 00:00:00 2001 From: Chris Plummer Date: Thu, 17 Aug 2023 15:09:09 +0000 Subject: [PATCH] 8282712: VMConnection.open() does not detect if VM failed to be created, resulting in NPE Reviewed-by: sspitsyn, amenkov --- .../sun/tools/example/debug/tty/VMConnection.java | 12 ++++++++---- test/jdk/com/sun/jdi/VMConnection.java | 10 +++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/VMConnection.java b/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/VMConnection.java index 7f4ae6939cb..555e8272e81 100644 --- a/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/VMConnection.java +++ b/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/VMConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -544,16 +544,18 @@ class VMConnection { } catch (IOException ioe) { ioe.printStackTrace(); MessageOutput.fatalError("Unable to launch target VM."); + throw new RuntimeException(ioe); } catch (IllegalConnectorArgumentsException icae) { icae.printStackTrace(); MessageOutput.fatalError("Internal debugger error."); + throw new RuntimeException(icae); } catch (VMStartException vmse) { MessageOutput.println("vmstartexception", vmse.getMessage()); MessageOutput.println(); dumpFailedLaunchInfo(vmse.process()); MessageOutput.fatalError("Target VM failed to initialize."); + throw new RuntimeException(vmse); } - return null; // Shuts up the compiler } /* attach to running target vm */ @@ -564,11 +566,12 @@ class VMConnection { } catch (IOException ioe) { ioe.printStackTrace(); MessageOutput.fatalError("Unable to attach to target VM."); + throw new RuntimeException(ioe); } catch (IllegalConnectorArgumentsException icae) { icae.printStackTrace(); MessageOutput.fatalError("Internal debugger error."); + throw new RuntimeException(icae); } - return null; // Shuts up the compiler } /* listen for connection from target vm */ @@ -583,10 +586,11 @@ class VMConnection { } catch (IOException ioe) { ioe.printStackTrace(); MessageOutput.fatalError("Unable to attach to target VM."); + throw new RuntimeException(ioe); } catch (IllegalConnectorArgumentsException icae) { icae.printStackTrace(); MessageOutput.fatalError("Internal debugger error."); + throw new RuntimeException(icae); } - return null; // Shuts up the compiler } } diff --git a/test/jdk/com/sun/jdi/VMConnection.java b/test/jdk/com/sun/jdi/VMConnection.java index 18bd3d8956a..1444393e46b 100644 --- a/test/jdk/com/sun/jdi/VMConnection.java +++ b/test/jdk/com/sun/jdi/VMConnection.java @@ -322,15 +322,17 @@ class VMConnection { } catch (IOException ioe) { ioe.printStackTrace(); System.err.println("\n Unable to launch target VM."); + throw new RuntimeException(ioe); } catch (IllegalConnectorArgumentsException icae) { icae.printStackTrace(); System.err.println("\n Internal debugger error."); + throw new RuntimeException(icae); } catch (VMStartException vmse) { System.err.println(vmse.getMessage() + "\n"); dumpFailedLaunchInfo(vmse.process()); System.err.println("\n Target VM failed to initialize."); + throw new RuntimeException(vmse); } - return null; // Shuts up the compiler } /* attach to running target vm */ @@ -341,11 +343,12 @@ class VMConnection { } catch (IOException ioe) { ioe.printStackTrace(); System.err.println("\n Unable to attach to target VM."); + throw new RuntimeException(ioe); } catch (IllegalConnectorArgumentsException icae) { icae.printStackTrace(); System.err.println("\n Internal debugger error."); + throw new RuntimeException(icae); } - return null; // Shuts up the compiler } /* listen for connection from target vm */ @@ -360,10 +363,11 @@ class VMConnection { } catch (IOException ioe) { ioe.printStackTrace(); System.err.println("\n Unable to attach to target VM."); + throw new RuntimeException(ioe); } catch (IllegalConnectorArgumentsException icae) { icae.printStackTrace(); System.err.println("\n Internal debugger error."); + throw new RuntimeException(icae); } - return null; // Shuts up the compiler } }