8209987: Minor cleanup in Level.java
authordfuchs
Mon, 27 Aug 2018 12:33:03 +0100
changeset 51532 5f40be158613
parent 51531 948c62200f8c
child 51533 839667fe21ef
8209987: Minor cleanup in Level.java Reviewed-by: dfuchs Contributed-by: Bernd Eckenfels <ecki@zusammenkunft.net>
src/java.logging/share/classes/java/util/logging/Level.java
--- a/src/java.logging/share/classes/java/util/logging/Level.java	Mon Aug 27 10:25:13 2018 +0530
+++ b/src/java.logging/share/classes/java/util/logging/Level.java	Mon Aug 27 12:33:03 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, 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
@@ -610,10 +610,7 @@
         }
 
         private static void registerWithClassLoader(Level customLevel) {
-            PrivilegedAction<ClassLoader> pa =
-                  () -> customLevel.getClass().getClassLoader();
-            PrivilegedAction<String> pn =  customLevel.getClass()::getName;
-            final String name = AccessController.doPrivileged(pn);
+            PrivilegedAction<ClassLoader> pa = customLevel.getClass()::getClassLoader;
             final ClassLoader cl = AccessController.doPrivileged(pa);
             CUSTOM_LEVEL_CLV.computeIfAbsent(cl, (c, v) -> new ArrayList<>())
                 .add(customLevel);
@@ -624,19 +621,10 @@
             // the mirroredLevel object is always added to the list
             // before the custom Level instance
             KnownLevel o = new KnownLevel(l);
-            List<KnownLevel> list = nameToLevels.get(l.name);
-            if (list == null) {
-                list = new ArrayList<>();
-                nameToLevels.put(l.name, list);
-            }
-            list.add(o);
-
-            list = intToLevels.get(l.value);
-            if (list == null) {
-                list = new ArrayList<>();
-                intToLevels.put(l.value, list);
-            }
-            list.add(o);
+            nameToLevels.computeIfAbsent(l.name, (k) -> new ArrayList<>())
+                .add(o);
+            intToLevels.computeIfAbsent(l.value, (k) -> new ArrayList<>())
+                .add(o);
 
             // keep the custom level reachable from its class loader
             // This will ensure that custom level values are not GC'ed