Class NestedAccessUtil

java.lang.Object
edu.umd.cs.findbugs.util.NestedAccessUtil

public class NestedAccessUtil extends Object
Provides checks to support JEP 181, improved nested member access.

In short, JEP 181 defines "nest mates", "nest host" and "nest members" attributes in compiled files. Access rules are relaxed to allow private member access between nest mates. This removes the need for the compiler to generate synthetic accessors. Extra attributes are added to the separate .class files to let the compiler know which classes are nested in which class.

Summary of terminology for JEP 181 and the added attributes:
  1. The "nest host" is the top level class that contains nested classes, i.e. the class that corresponds to the source file
  2. The "nest members" are the nested classes in the nest host.
  3. The "nest" consists of the nest host and the nest members.
  4. A "nest mate" is a class within the nest, "nest mates" can access each others private members.
  5. The nest host class has an attribute NestMembers which lists the qualified names of nested classes.
  6. A nested class has an attribute NestHost which lists the qualified name of the nest host.
See Also:
  • "https://openjdk.java.net/jeps/181"
  • Constructor Details

    • NestedAccessUtil

      public NestedAccessUtil()
  • Method Details

    • hasNest

      public static boolean hasNest(org.apache.bcel.classfile.JavaClass javaClass)
      Checks if the specified class is a nested class or defines nested classes.
      Parameters:
      javaClass - The class for which to check.
      Returns:
      true if the specified class is a nested class or defines nested class, false otherwise.
    • supportsNestedAccess

      public static boolean supportsNestedAccess(org.apache.bcel.classfile.JavaClass javaClass)
      Checks whether the specified class supports nested access as per JEP 181.
      Parameters:
      javaClass - The class for which to check.
      Returns:
      true if the specified class supports nested access as per JEP 181.
      See Also:
    • getNestMateClassNames

      public static List<String> getNestMateClassNames(org.apache.bcel.classfile.JavaClass javaClass, AnalysisContext analysisContext) throws ClassNotFoundException
      Retrieves the qualified class names of all nest mates of the specified class.
      Parameters:
      javaClass - The class for which qualified class names of nest mates are retrieved.
      analysisContext - The analysis context, used to look-up a nest host class if required.
      Returns:
      The qualified class name of all nest mates. If the specified class is not a nested class or does not have nested classes, an empty list is returned.
      Throws:
      ClassNotFoundException - If a nest host class was looked-up but could not be found.
      See Also: