-
Notifications
You must be signed in to change notification settings - Fork 332
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
Vraptor instantiate even has no request parameters for object #532
Comments
I agree that it should not instantiate... Can anyone see a downside changing it? |
I agree. There is the same issue opened in vraptor3. |
This change can affect developers who already use it. It now can generate a NullPointerException. |
just linking caelum/vraptor#525 |
I did some tests, and this behavior (I consider behavior, not a bug) occurs only with mutable objects. Take a look in my code: @Path("/test")
public void test(PlanDTO plan, UserDTO user) {
System.out.println(plan);
System.out.println(user);
result.use(Results.status()).forbidden("true");
} public class PlanDTO {
private final Long id;
public PlanDTO(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
} And this is the logs for some requests
But if I change my class PlanDTO to have mutability (removing final, constructors and add a setter for id property), the class will be always instantiated in all requests like described above. I don't know what you think but, IMHO, we can leave this behavior as is, and add a note in the docs describing that only immutable objects won't be instantiated. I have this idea because but it's too dangerous to change this behavior by now. Final release already released, so many apps expects non-null instance as parameters. And as @matheusmessora told, we can create a |
Others point of view about this issue : 1 . Ognl was introduced before iogi and keep going on in vraptor since was removed as a dependencie in vraptor 4 . So i think (my opinion) the priority is for him behavior (ognl) for a great reason too (migration to version 4 with compatibility) unless that is not default behaviour anymore in version 4 and who use ognl has to rewrite all the application to be compatible with iogi (in general the same reason you defend not change for iogi (who used iogi has to review your application)) . We will never know who is using what for migration (iogi or ognl have diferents behavior for this scenario) . So that argument is kind of invalid for me since one of the worlds will be affected . 2 . For me again there is no sense vraptor instantiate an object as an "empty instance" if there`s no parameter to populate (independent if a class is mutable or not) null is more sensate in this case (no parameter in request , no object) . 3 . An another ideia is a way to dev choose what kind of behaviour he wants (to not break compatibility with anyone (iogi world and ognl world)) overwriting some class for example . |
VRaptor 4 is not meant to be fully compatible with VRaptor 3, and as we dropped OGNL from it, there is no need to support it. So point 1 doesn't hold, in my opinion. I agree with point 2, but it's a compatibility break. We could argue that it's a bug, but I'd only release it on version 4.1, and make a big note on the release explaining this break change. 3 - I think it doesn't worth the complexity. But maybe a class with a protected method that could be overridden by a |
I'd prefer the 3rd option... like Otávio said, it's a behavior and not necessarily a bug. Some |
I like 3rd option too. |
Can I implement it? Using an environment property to choose |
Environment isn't good because this case is not related to environment. I |
Ops, it's true. A protected method looks better |
=) |
In this snippet vraptor instantiate carro , but has no carro.xxx in the request parameters . In my point of view carro must be null not a empty instance . Another point is that break compatibility with ognl that was removed in favor of iogi in version 4 (that instantiate correctly in vraptor 3 with ognl putting null if has no request parameters) .
The text was updated successfully, but these errors were encountered: