Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sisu-users] @Nullable working example

PS. Maven also does not (yet) expose the com.google.inject package to plugins, so it could be that using @com.google.inject.Inject(optional = true) is not having the expected affect, in that the field will likely never be injected (since the JVM silently removes runtime annotations that are not visible from the defining classloader, making the field appear to have no @Inject).

On 17 Jun 2014, at 20:52, Stuart McCulloch <mcculls@xxxxxxxxx> wrote:

> On 17 Jun 2014, at 20:12, Igor Fedorenko <igor@xxxxxxxxxxxxxx> wrote:
> 
>> I am using Sisu 0.0.0.M5 (part of Maven 3.2.1) and I am having
>> difficulty getting @org.eclipse.sisu.Nullable to do anything. It didn't
>> work neither for injected constructor parameter nor for injected field.
> 
> For plugin or extension? AFAIK maven doesn’t expose any org.eclipse.sisu packages from maven-core, in which case @org.eclipse.sisu.Nullable won't be visible at runtime from the plugin realm. However note that any @Nullable annotation can be used, as long as it’s visible when loading the annotated class - the actual @Nullable check is in Guice where it compares the name of the annotation to “Nullable”, regardless of the package. So you could always create your own @Nullable in a package that’s known to be visible to your plugin.
> 
>> @com.google.inject.Inject(optional = true) worked for injected field as
>> suggested in [1], which I hope means the rest of my code is setup
>> correctly and the problem is with how I use @Nullable.
> 
> Note optional=true is not quite the same as @Nullable - the former allows you to proceed without any binding for the injected member (which for a field means it’s not injected at all) whereas the latter allows null to be injected.
> 
> When using Sisu, @Nullable becomes a reasonable approximation to optional=true (because its generated bindings will return null when a component is not available) but is still slightly different because the injection goes ahead even if the value being injected is null, whereas with optional=true you can set a default value for the field and it won’t be disturbed if the relevant binding is missing.
> 
>> Are there known problems with @Nullable in Sisu 0.0.0.M5?
> 
> Not according to the test reports (the expected behaviour of @Nullable is tested for all kinds of injection points in BeanImportTest)
> 
>> Can somebody
>> point me at a working example that shows how to use it properly, ideally
>> when used from plexus shim?
>> 
>> [1] https://code.google.com/p/google-guice/wiki/FrequentlyAskedQuestions
>> 
>> --
>> Regards,
>> Igor
>> _______________________________________________
>> sisu-users mailing list
>> sisu-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/sisu-users
> 



Back to the top