Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scabug opened this issue Apr 10, 2010 · 3 comments
Closed

Comments

@scabug
Copy link

scabug commented Apr 10, 2010

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
@scabug
Copy link
Author

scabug commented Apr 10, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3276?orig=1
Reporter: Graham Lea (grlea)

@scabug
Copy link
Author

scabug commented Apr 11, 2010

@dubochet said:
There is probably not much we can do: Scala access annotation are not reflection-safe. I'll check with the team during the next meeting.

@scabug
Copy link
Author

scabug commented Apr 13, 2010

@dubochet said:
As I thought, this is not something we can change.

The fact that Java reflection allows invalid access on Scala programs is an inherent problem with the compilation of non-Java languages to the JVM. There is nothing we can do.

The longer-term answer to such issues is that we are developing a Scala reflection library that will not suffer from those problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant