Skip to content

Private Classes can be instantiated by reflection from outside their scope #3276

Closed
@scabug

Description

@scabug

Test case:

package testing {

package privatetesting {
  private class PrivateClass
  private[privatetesting] class PrivateToPackageClass
}

object TestingObject {
  def main(args: Array[String]) {
    println(Class.forName("testing.privatetesting.PrivateClass").getConstructor().newInstance())
    println(Class.forName("testing.privatetesting.PrivateToPackageClass").getConstructor().newInstance())
  }
}

}

Expected output: IllegalAccessException, or some such error

Actual output:

testing.privatetesting.PrivateClass@47808199
testing.privatetesting.PrivateToPackageClass@5ca46701

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions