InvalidateStateException needs to show the error messages in the message when it's thrown


I dunno if you fixed this in 4.0 releases. To make testing easier, I think the error messages should be viewable when the exception is thrown. I know it's possible to inspect the exception for these errors, but within a unit test, this is just too much work and it's annoying.

In practice, we create all these objects and do tests. Sometimes these objects get sent to the database and are saved.

Now, let's say 3 validation constraints aren't met. On the outset, the developer is 100% blind and must code in a try/catch and print out the list of errors. When this happens over and over and over... it's just tedious. When a test fails because an unexpected validation exception is thrown, I don't want to have to do this - I want to instantly see what went wrong so I can make the changes to my test case and run it quickly.

I think this change would facilitate much faster test/code cycles, and it shouldn't be hard to add in.





Hardy Ferentschik
September 22, 2009, 12:23 PM

I am not sure I follow. First of Validator 4.x implements the Bean Validation standadd (JSR 303) so we have to stick to what's defined in there.

That said, the actual validation does not throw exceptions. The various validation methods of javax.validation.Validator all return Set<ConstraintViolation<T>>. The set is empty if the validation is successful otherwise one ConstraintViolation instance per failing constraint is added.

When it comes to integration of Bean Validation into other frameworks, for example JPA , the framework might decide to wrap the constraint violations into an exception. In this case the ConstraintViolationException is recommended which gives access to the violations via getConstraintViolations()

To have the various error messages of the set as part of toString of the ConstraintViolationException, either the integrating framework has to build this error string and pass it to the constructor of the ConstraintViolationException or toString on ConstraintViolationException needs to be overriden. Not sure whether the latter is a good idea, but you could suggest it on the Bean Validation forum -

Ken Egervari
September 22, 2009, 12:33 PM

You guys don't have to stick to what's defined there... you can actually expand on it, just like your sister projects have. Hibernate provides more than JPA specifies. I don't see a problem here

If you ask me, standards are lame and bloated. What really matters is that people get a tool that works for them in practice. I think it's dumb to wait a for a standard that eventually adds these things in 4 years too late. EJB 3.0 anyone?

I dunno how the architecture works on your end... but from my end, this is just an exception thrown by your validator project. It really isn't possible to just add more into the toString() method? You already have an array of invalidValues[] - we can just iterate through that and print them. It's really very simple, and man... just think of the people that would LOVE you for doing this.

I think in the grand scheme of things, will make your framework 10x easier to test with, and will save people probably hours of time over the course of a long project, not to mention reducing frustration levels. This is a very, very good idea. Please find a way to implement it. Please )))))




Ken Egervari



Feedback Requested


Feedback Requested By




Suitable for new contributors


Pull Request






Time tracking