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

ValidationSupport does not account for inheritance #1084

Closed
alniks opened this issue Mar 18, 2021 · 1 comment
Closed

ValidationSupport does not account for inheritance #1084

alniks opened this issue Mar 18, 2021 · 1 comment
Assignees

Comments

@alniks
Copy link

alniks commented Mar 18, 2021

Test case:

public abstract class Template extends ValidationSupport {
    private String name;

    public Template() {
        validatePresenceOf("name");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

public class WaTemplate extends Template { }

@Test
public void shouldBeValid() {
        WaTemplate t = new WaTemplate();
        t.setName("test");
        the(t).shouldBe("valid");
}

We get a

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at org.javalite.test.jspec.Expectation.invokeBoolean(Expectation.java:336)
	at org.javalite.test.jspec.Expectation.shouldBe(Expectation.java:128)
	at org.javalite.validation.ValidationSpec.shouldBeValid(ValidationSpec.java:70)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:364)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:272)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:237)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:158)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:428)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
	at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:562)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:548)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.javalite.test.jspec.Expectation.invokeBoolean(Expectation.java:334)
	... 30 more
Caused by: org.javalite.validation.ValidationException: { }
	at org.javalite.validation.ValidationSupport.get(ValidationSupport.java:162)
	at org.javalite.validation.AttributePresenceValidator.validate(AttributePresenceValidator.java:36)
	at org.javalite.validation.ValidationSupport.validate(ValidationSupport.java:186)
	at org.javalite.validation.ValidationSupport.validate(ValidationSupport.java:177)
	at org.javalite.validation.ValidationSupport.isValid(ValidationSupport.java:171)
	... 35 more

the reflection in ValidationSupport#get should recursively search for fields in class hierarchy

@ipolevoy
Copy link
Member

ipolevoy commented Mar 20, 2021

@alniks this is fixed on branches java8, java11 and master

ipolevoy added a commit that referenced this issue Mar 20, 2021
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