Class RuntimePackageCheck

java.lang.Object
org.codehaus.groovy.classgen.asm.sc.RuntimePackageCheck

public final class RuntimePackageCheck extends Object
Reports what statically compiled code accesses in another run-time package, which is the package name and the class loader, when CompilerConfiguration.RUNTIME_PACKAGE_CHECK applies. The language allows such access, as the package name is the same, but the JVM refuses it at run time with IllegalAccessError.
Since:
6.0.1
See Also:
  • Method Details

    • checkConstructor

      public static void checkConstructor(WriterController controller, ConstructorNode ctor, boolean superCall, ASTNode call)
      Checks a call of a constructor. There is no subclass rule for new: only super(...) can call a protected constructor from a subclass.

      A super(...) call without a source position in a generated constructor, as @InheritConstructors adds for each constructor of the superclass, is not reported: it fails only if that constructor is called. Dynamic code calls a super constructor without the meta-class too, so the report of such a call does not advise @CompileDynamic.

      Parameters:
      controller - the writer of the current class
      ctor - the constructor that is called
      superCall - whether the call is super(...)
      call - where to report it
    • checkAnonymousClass

      public static void checkAnonymousClass(WriterController controller, ConstructorCallExpression call)
      Checks the constructor of the superclass that the generated constructor of an anonymous class calls. That call is selected at run time, so the arguments of the anonymous class creation tell which constructor it is, if they tell.
      Parameters:
      controller - the writer of the current class
      call - the creation of the anonymous class
    • checkMethod

      public static void checkMethod(WriterController controller, MethodNode method, ClassNode receiverType, ASTNode call)
      Checks a call of a method.
      Parameters:
      controller - the writer of the current class
      method - the method that is called
      receiverType - the type of the receiver, or null for this or super
      call - where to report it
    • checkField

      public static void checkField(WriterController controller, FieldNode field, ClassNode receiverType, ASTNode expression)
      Checks a read or write of a field.
      Parameters:
      controller - the writer of the current class
      field - the field that is accessed
      receiverType - the type of the receiver, or null for this or super
      expression - where to report it
    • checkSuperTypes

      public static void checkSuperTypes(WriterController controller)
      Checks the superclass and interfaces of a statically compiled class. The JVM refuses to load a class whose superclass or interface it cannot access, in dynamic code too, so the report does not advise @CompileDynamic.
      Parameters:
      controller - the writer of the class
    • checkNamedClasses

      public static org.objectweb.asm.MethodVisitor checkNamedClasses(WriterController controller, org.objectweb.asm.MethodVisitor delegate)
      Returns a visitor that reports the instructions of a statically compiled method that name a class the JVM refuses: a class that is not public, with the same package name as the current class, of another run-time package. The JVM checks that wherever an instruction names the class, so a value of such a class can still be stored and passed on as long as none of them does.
      Parameters:
      controller - the writer of the current class
      delegate - the visitor of the method
      Returns:
      the visitor to use for the instructions of the method