GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Error Prone
  • Bug Patterns
  • Docs
  • GitHub

This view

  • Original page
  • New address

GeezerVison is showing errorprone.info — MissingRuntimeRetention

MissingRuntimeRetention
Scoping and qualifier annotations must have runtime retention.

Severity
ERROR

Alternate names: InjectScopeOrQualifierAnnotationRetention

The problem

Qualifier and Scope annotations are used by dependency injection frameworks to adjust their behavior. Not having runtime retention on scoping or qualifier annotations will cause unexpected behavior in frameworks that use reflection:

class CreditCardProcessor { @Inject CreditCardProcessor(...) }

@Qualifier
@interface ForTests

@Provides
@ForTests
CreditCardProcessor providesTestProcessor() { return new TestCreditCardProcessor(...) }
...

@Inject
MyApp(CreditCardProcessor processor) {
  processor.issueCharge(...); // Issues a charge against a fake!
}

Since the Qualifier doesn’t have runtime retention, the Guice provider method doesn’t see the annotation, and will use the TestCreditCardProcessor for the normal CreditCardProcessor injection point.

NOTE: Even for dependency injection frameworks traditionally considered to be compile-time dependent, the JSR-330 specification still requires runtime retention for both Qualifier and Scope.

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("MissingRuntimeRetention") to the enclosing element.

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.