Fix bug 431674 Java field private access doesn't work well with Java Bean

access


git-svn-id: svn://10.0.0.236/trunk@251028 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
nboyd%atg.com
2008-05-01 14:08:48 +00:00
parent 3f91c36bd5
commit 200daab556
3 changed files with 35 additions and 6 deletions

View File

@@ -598,9 +598,16 @@ class JavaMembers
// If we already have a member by this name, don't do this
// property.
if (ht.containsKey(beanPropertyName)
|| toAdd.containsKey(beanPropertyName)) {
if (toAdd.containsKey(beanPropertyName))
continue;
Object v = ht.get(beanPropertyName);
if (v != null) {
// A private field shouldn't mask a public getter/setter
if (!includePrivate ||
!Modifier.isPrivate(((Member)v).getModifiers()))
{
continue;
}
}
// Find the getter method, or if there is none, the is-

View File

@@ -88,7 +88,17 @@ public class JavaAcessibilityTest extends TestCase {
runScript(importClass + "new PrivateAccessClass(5)");
runScript(importClass + "new PrivateAccessClass(5, \"foo\")");
}
public void testAccessingJavaBeanProperty() {
Object result = runScript(importClass +
"var x = new PrivateAccessClass(); x.javaBeanProperty + ' ' + x.getterCalled;");
assertEquals("6 true", result);
result = runScript(importClass +
"var x = new PrivateAccessClass(); x.javaBeanProperty = 4; x.javaBeanProperty + ' ' + x.setterCalled;");
assertEquals("4 true", result);
}
private Object runScript(final String scriptSourceText) {
return this.contextFactory.call(new ContextAction() {
public Object run(Context context) {

View File

@@ -74,8 +74,20 @@ public class PrivateAccessClass
int packagePrivateMethod() { return 3; }
private int privateMethod() { return 4; }
protected int protectedMethod() { return 5; }
/*
private int javaBeanProperty = 6;
public boolean getterCalled = false;
public boolean setterCalled = false;
public int getJavaBeanProperty() {
getterCalled = true;
return javaBeanProperty;
}
public void setJavaBeanProperty(int i) {
setterCalled = true;
javaBeanProperty = i;
}
/*
* Suppress warnings about unused private members.
*/
public int referenceToPrivateMembers() {
@@ -85,6 +97,6 @@ public class PrivateAccessClass
System.out.println(privateString);
pac2.privateMethod(); // to silence warning
return pnc.privateInt + staticPrivateInt + staticPrivateMethod() +
pac.privateMethod();
pac.privateMethod() + javaBeanProperty;
}
}