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

WW-5415 Fixes accessing public constructors via expression #933

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public boolean isAccessible(Map context, Object target, Member member, String pr
if (target != null) {
// Special case: Target is a Class object but not Class.class
if (Class.class.equals(target.getClass()) && !Class.class.equals(target)) {
if (!isStatic(member)) {
if (!isStatic(member) && Arrays.stream(((Class<?>) target).getConstructors()).noneMatch(p -> p.getClass().equals(member.getClass()))) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a temporary solution to express where the problem is, @kusalk I count on your comment :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lukaszlenart for writing the test case - I did indeed overlook the constructor case, I've pushed a commit to this PR with the appropriate fix :)

throw new IllegalArgumentException("Member expected to be static!");
}
if (!member.getDeclaringClass().equals(target)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.opensymphony.xwork2.conversion.impl.ConversionData;
import org.easymock.EasyMock;

import java.sql.Date;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
Expand Down Expand Up @@ -142,6 +144,15 @@ public void testCollectionValidation() throws Exception {
assertEquals(1, errors.size());
}

public void testDateValidation() throws Exception {
action.setBirthday(Date.valueOf(LocalDate.now().minusYears(20)));
action.setContext("birthday");

validate("birthday");

assertFalse(action.hasFieldErrors());
}

public void testContextIsOverriddenByContextParamInValidationXML() throws Exception {
validate("visitorValidationAlias");
assertTrue(action.hasFieldErrors());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.opensymphony.xwork2.TestBean;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


Expand All @@ -37,7 +38,7 @@ public class VisitorValidatorTestAction extends ActionSupport {
private String context;
private TestBean bean = new TestBean();
private TestBean[] testBeanArray;

private Date birthday;

public VisitorValidatorTestAction() {
testBeanArray = new TestBean[5];
Expand Down Expand Up @@ -80,4 +81,12 @@ public void setTestBeanList(List<TestBean> testBeanList) {
public List<TestBean> getTestBeanList() {
return testBeanList;
}

public Date getBirthday() {
return birthday;
}

public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@
<message>You must enter a context.</message>
</field-validator>
</field>
<field name="birthday">
<field-validator type="fieldexpression">
<param name="expression"><![CDATA[
(birthday == null || birthday.before(new java.util.Date()))
]]></param>
<message key="errors_birthday" />
</field-validator>
</field>
</validators>