< prev index next >

src/java.base/share/classes/java/lang/StackWalker.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -294,10 +294,11 @@
         new StackWalker(DEFAULT_EMPTY_OPTION);
 
     private final Set<Option> options;
     private final ExtendedOption extendedOption;
     private final int estimateDepth;
+    final boolean retainClassRef; // cached for performance
 
     /**
      * Returns a {@code StackWalker} instance.
      *
      * <p> This {@code StackWalker} is configured to skip all

@@ -410,10 +411,11 @@
     }
     private StackWalker(EnumSet<Option> options, int estimateDepth, ExtendedOption extendedOption) {
         this.options = options;
         this.estimateDepth = estimateDepth;
         this.extendedOption = extendedOption;
+        this.retainClassRef = hasOption(Option.RETAIN_CLASS_REFERENCE);
     }
 
     private static void checkPermission(Set<Option> options) {
         Objects.requireNonNull(options);
         SecurityManager sm = System.getSecurityManager();

@@ -588,11 +590,11 @@
      *         when this {@code getCallerClass} method is called from a method
      *         which is the last frame on the stack.
      */
     @CallerSensitive
     public Class<?> getCallerClass() {
-        if (!options.contains(Option.RETAIN_CLASS_REFERENCE)) {
+        if (!retainClassRef) {
             throw new UnsupportedOperationException("This stack walker " +
                     "does not have RETAIN_CLASS_REFERENCE access");
         }
 
         return StackStreamFactory.makeCallerFinder(this).findCaller();

@@ -615,13 +617,6 @@
     }
 
     boolean hasLocalsOperandsOption() {
         return extendedOption == ExtendedOption.LOCALS_AND_OPERANDS;
     }
-
-    void ensureAccessEnabled(Option access) {
-        if (!hasOption(access)) {
-            throw new UnsupportedOperationException("No access to " + access +
-                    ": " + options.toString());
-        }
-    }
 }
< prev index next >