-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Avoid generate @Delegate method body NPE #3811
base: master
Are you sure you want to change the base?
Conversation
…ll on javac's HandleDelegate
There is also e ecj's implement version. But i've not ever test event compile it. But I think it's ok. I'll add in PR if you think is ok. |
Not sure if this is a good idea. Let's see this case: public interface Foo {
/**
* Do a foo thing. Never, ever returns {@code null}.
* It is very important that in no circunstances {@code null} is ever returned.
* @return Anything, everything or something, except {@code null}.
*/
public String foo();
} public class FooDecorator implements Foo {
@Delegate(types = Foo.class)
private Foo myFooField = null;
} |
Well in this case, the code runs and stops immediately throwing a NPE. It May useful for some scenario want expose bug earlier in test time. In the samethime in some use case like DTO case, need expose additioal field but don't want add it to core model class RestControllerShopItemReturnDTO{
private String someAdditionalShitFieldFromShitService;
@Delegate
private ShopItemDTO item = null;
@Delegate
private PriceDTO price = null;
}
class ShopItemDTO{
} according to query condition it may contains price or not. May be add a method in annoation boolean skipWhenFieldNull() default false; finally it looks like this class RestControllerShopItemReturnDTO{
private String someAdditionalShitFieldFromShitService;
@Delegate(skipWhenFieldNull=true)
private ShopItemDTO item = null;
@Delegate(skipWhenFieldNull=true)
private PriceDTO price = null;
}
class ShopItemDTO{
} |
I converted this to a draft because:
While the actual modification is straightforward and could be adjusted to avoid being a breaking change, making it work with primitives might be a bit more complex. I recommend waiting for Reinier or Roel to approve the idea before investing time in implementing it. |
Avoid generate @DeleGate method body NPE when deletegate target is null on javac's HandleDelegate
Add a null check before delegate call,now is only for javac
before:
after