Skip to content
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

extending Java class with field name collision throws java.lang.IllegalAccessError #5114

Open
scabug opened this issue Oct 26, 2011 · 3 comments

Comments

@scabug
Copy link

scabug commented Oct 26, 2011

// M.java
public class M {
        public M(){}
        public String name;
}
class X(name: String) extends M {
     val config: String = try {name} catch { case _ => ""}
}
new X("").name
java.lang.IllegalAccessError: tried to access field X.name from class 

Note that the class X constructor parameter name matches java class M field name; the name is referenced in the constructor code of class X. Try block referencing "name" is needed to reproduce. This has been narrowed down from real code. If class M is implemented in Scala, no problem occurs. I am using 2.9.1 final, problem occurs both in Eclipse and REPL

@scabug
Copy link
Author

scabug commented Oct 26, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5114?orig=1
Reporter: Julian Rozentur (julianrz)
Affected Versions: 2.9.1

@scabug
Copy link
Author

scabug commented Oct 31, 2011

@paulp said:
Same as #4762: unwanted synthetic private[this] field shadows inherited public field. This shows another dimension of it: shadowing a public field with a private[this] field means that the selection is allowed, only to fail at runtime.

@scabug
Copy link
Author

scabug commented Nov 24, 2012

@paulp said:
I hit this one again.

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

2 participants