Runtime retention of @Nullable for dependency-injection

Guice is a dependency injection framework that uses
annotations to mark injection points. For example:
public class Foo {
@Inject
public Foo(Bar bar, Baz baz) { ... }
}

Currently Guice doesn't allow null to be injected.
We like this. It helps to prevent bugs.

But there are cases where injecting null is convenient.
We'd like to reuse the Jetbrains' @Nullable annotation to
indicate that null is okay:
public class Foo {
@Inject
public Foo(Bar bar, @Nullable Baz baz) { ... }
}

For this to work, we need runtime retention for @Nullable.
Otherwise we'd have to scrape the annotation from the
classfile, or introduce another annotation that like
'@InjectNullOk'. It would be unfortunate to have to annotate
one variable with both "@Nullable" and "@InjectNullOk".

Although this example is Guice-specific it applies to other
dependency-injection frameworks and containers.

Is there any chance that future releases of Jetbrains' annotations
could include runtime retention?

Thanks,
Jesse

See also:
http://code.google.com/p/google-guice/issues/detail?id=112
http://groups.google.com/group/jsr-305/browse_thread/thread/99cb455eedf21801

Guice:
http://code.google.com/p/google-guice/

7 comments
Comment actions Permalink

Hello Jesse,

No, we don't have such plans at the moment. The easiest solution for you
is to recompile our annotations.jar (the source code is in redist\src\src_annotations.zip)
and add the runtime retention by yourself.

Guice is a dependency injection framework that uses
annotations to mark injection points. For example:
public class Foo {
@Inject
public Foo(Bar bar, Baz baz) { ... }
}
Currently Guice doesn't allow null to be injected. We like this. It
helps to prevent bugs.

But there are cases where injecting null is convenient.
We'd like to reuse the Jetbrains' @Nullable annotation to
indicate that null is okay:
public class Foo {
@Inject
public Foo(Bar bar, @Nullable Baz baz) { ... }
}
For this to work, we need runtime retention for @Nullable. Otherwise
we'd have to scrape the annotation from the classfile, or introduce
another annotation that like '@InjectNullOk'. It would be unfortunate
to have to annotate one variable with both "@Nullable" and
"@InjectNullOk".

Although this example is Guice-specific it applies to other
dependency-injection frameworks and containers.

Is there any chance that future releases of Jetbrains' annotations
could include runtime retention?

Thanks, Jesse

See also: http://code.google.com/p/google-guice/issues/detail?id=112
http://groups.google.com/group/jsr-305/browse_thread/thread/99cb455eed
f21801

Guice: http://code.google.com/p/google-guice/

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Out of curiosity, why not?

0
Comment actions Permalink

It's worth noting that, if it ever gets back on schedule, the JSR-305 standardization of @Nullable will almost certainly have runtime retention.

--Dave Griffith

0
Comment actions Permalink

Now that both Dave and Jesse are in this thread, here's an off-topic question:

I've been using Guice recently, and having some support in IDEA would be very nice.
- I know that some googlers were planning to develop a IDEA plugin
- Jetbrains is planning to include some S&RR plugins in Diana. While I haven't used GuiceyIDEA in the past, looking at the features is seems to have the right focus.

So, is there anything moving on this front?

0
Comment actions Permalink

Hello Taras,

GuiceyIDEA was in the list of plugins that we've acquired from S&RR, and
if there's interest in it, it won't take us long to open-source it and bundle
in a future Diana EAP build.

Now that both Dave and Jesse are in this thread, here's an off-topic
question:

I've been using Guice recently, and having some support in IDEA would
be very nice.

- I know that some googlers were planning to develop a IDEA plugin

- Jetbrains is planning to include some S&RR plugins in Diana. While I
haven't used GuiceyIDEA in the past, looking at the features is seems
to have the right focus.

So, is there anything moving on this front?

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hello Taras,

http://svn.jetbrains.org/idea/Trunk/bundled/GuiceyIDEA/

Now that both Dave and Jesse are in this thread, here's an off-topic
question:

I've been using Guice recently, and having some support in IDEA would
be very nice.

- I know that some googlers were planning to develop a IDEA plugin

- Jetbrains is planning to include some S&RR plugins in Diana. While I
haven't used GuiceyIDEA in the past, looking at the features is seems
to have the right focus.

So, is there anything moving on this front?

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

> No, we don't have such plans at the moment. The easiest solution for you
> is to recompile our annotations.jar (the source code is in redist\src\src_annotations.zip)
> and add the runtime retention by yourself.

FYI, I've just now released a library to Maven Central doing exactly this:

0

Please sign in to leave a comment.