From 04f30185e914c10c918d0eff1fb63fd96e1139fb Mon Sep 17 00:00:00 2001 From: Kevin Walls Date: Thu, 9 Feb 2023 09:30:44 +0000 Subject: [PATCH] 8299739: HashedPasswordFileTest.java and ExceptionTest.java can fail with java.lang.NullPointerException Reviewed-by: sspitsyn, amenkov, cjplummer --- .../management/MBeanServer/ExceptionTest.java | 11 +++++++---- .../security/HashedPasswordFileTest.java | 16 +++++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/test/jdk/javax/management/MBeanServer/ExceptionTest.java b/test/jdk/javax/management/MBeanServer/ExceptionTest.java index 3ea04f7d7ca..bb58e941242 100644 --- a/test/jdk/javax/management/MBeanServer/ExceptionTest.java +++ b/test/jdk/javax/management/MBeanServer/ExceptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 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 @@ -123,10 +123,13 @@ public class ExceptionTest { } finally { try { // Close JMX Connector Client - cc.close(); + if (cc != null) { + cc.close(); + } // Stop connertor server - cs.stop(); - + if (cs != null) { + cs.stop(); + } } catch (Exception e) { Utils.printThrowable(e, true); throw new RuntimeException( diff --git a/test/jdk/javax/management/security/HashedPasswordFileTest.java b/test/jdk/javax/management/security/HashedPasswordFileTest.java index e7b0af4cab7..e2d5bd7deb6 100644 --- a/test/jdk/javax/management/security/HashedPasswordFileTest.java +++ b/test/jdk/javax/management/security/HashedPasswordFileTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -200,6 +200,12 @@ public class HashedPasswordFileTest { return cs.getAddress(); } + private void stopServerSide() throws IOException { + if (cs != null) { + cs.stop(); + } + } + @Test public void testClearTextPasswordFile() throws IOException { Boolean[] bvals = new Boolean[]{true, false}; @@ -217,7 +223,7 @@ public class HashedPasswordFileTest { } Assert.assertEquals(isPasswordFileHashed(), bval); } finally { - cs.stop(); + stopServerSide(); } } } @@ -241,7 +247,7 @@ public class HashedPasswordFileTest { } Assert.assertEquals(isPasswordFileHashed(), false); } finally { - cs.stop(); + stopServerSide(); } } } @@ -263,7 +269,7 @@ public class HashedPasswordFileTest { } } } finally { - cs.stop(); + stopServerSide(); } } } @@ -400,7 +406,7 @@ public class HashedPasswordFileTest { } } } finally { - cs.stop(); + stopServerSide(); } }