Class Errors

java.lang.Object
com.google.inject.internal.Errors
All Implemented Interfaces:
Serializable

public final class Errors extends Object implements Serializable
A collection of error messages. If this type is passed as a method parameter, the method is considered to have executed successfully only if new errors were not added to this collection.

Errors can be chained to provide additional context. To add context, call withSource(java.lang.Object) to create a new Errors instance that contains additional context. All messages added to the returned instance will contain full context.

To avoid messages with redundant context, withSource(java.lang.Object) should be added sparingly. A good rule of thumb is to assume a method's caller has already specified enough context to identify that method. When calling a method that's defined in a different context, call that method with an errors object that includes its context.

See Also:
  • Field Details

    • root

      private final Errors root
      The root errors object. Used to access the list of error messages.
    • parent

      private final Errors parent
      The parent errors object. Used to obtain the chain of source objects.
    • source

      private final Object source
      The leaf source for errors added here.
    • errors

      private List<Message> errors
      null unless (root == this) and error messages exist. Never an empty list.
    • CONSTRUCTOR_RULES

      private static final String CONSTRUCTOR_RULES
      See Also:
  • Constructor Details

    • Errors

      public Errors()
    • Errors

      public Errors(Object source)
    • Errors

      private Errors(Errors parent, Object source)
  • Method Details

    • checkNotNull

      static <T> T checkNotNull(T reference, String name)
      Throws a ConfigurationException with an NullPointerExceptions as the cause if the given reference is null.
    • checkConfiguration

      static void checkConfiguration(boolean condition, String format, Object... args)
      Throws a ConfigurationException with a formatted Message if this condition is false.
    • withSource

      public Errors withSource(Object source)
      Returns an instance that uses source as a reference point for newly added errors.
    • aopDisabled

      public Errors aopDisabled(InterceptorBinding binding)
    • missingImplementation

      public Errors missingImplementation(Key<?> key)
      We use a fairly generic error message here. The motivation is to share the same message for both bind time errors:
      Guice.createInjector(new AbstractModule() {
         public void configure() {
           bind(Runnable.class);
         }
       }
      ...and at provide-time errors:
      Guice.createInjector().getInstance(Runnable.class);
      Otherwise we need to know who's calling when resolving a just-in-time binding, which makes things unnecessarily complex.
    • missingImplementationWithHint

      <T> Errors missingImplementationWithHint(Key<T> key, Injector injector)
      Within guice's core, allow for better missing binding messages
    • jitDisabled

      public Errors jitDisabled(Key<?> key)
    • jitDisabledInParent

      public Errors jitDisabledInParent(Key<?> key)
    • atInjectRequired

      public Errors atInjectRequired(TypeLiteral<?> type)
    • converterReturnedNull

      public Errors converterReturnedNull(String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding)
    • conversionTypeError

      public Errors conversionTypeError(String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, Object converted)
    • conversionError

      public Errors conversionError(String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, RuntimeException cause)
    • ambiguousTypeConversion

      public Errors ambiguousTypeConversion(String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding a, TypeConverterBinding b)
    • bindingToProvider

      public Errors bindingToProvider()
    • notASubtype

      public Errors notASubtype(Class<?> implementationType, Class<?> type)
    • recursiveImplementationType

      public Errors recursiveImplementationType()
    • recursiveProviderType

      public Errors recursiveProviderType()
    • missingRuntimeRetention

      public Errors missingRuntimeRetention(Class<? extends Annotation> annotation)
    • missingScopeAnnotation

      public Errors missingScopeAnnotation(Class<? extends Annotation> annotation)
    • optionalConstructor

      public Errors optionalConstructor(Constructor<?> constructor)
    • cannotBindToGuiceType

      public Errors cannotBindToGuiceType(String simpleName)
    • scopeNotFound

      public Errors scopeNotFound(Class<? extends Annotation> scopeAnnotation)
    • scopeAnnotationOnAbstractType

      public Errors scopeAnnotationOnAbstractType(Class<? extends Annotation> scopeAnnotation, Class<?> type, Object source)
    • misplacedBindingAnnotation

      public Errors misplacedBindingAnnotation(Member member, Annotation bindingAnnotation)
    • missingConstructor

      public Errors missingConstructor(TypeLiteral<?> type)
    • tooManyConstructors

      public Errors tooManyConstructors(Class<?> implementation)
    • constructorNotDefinedByType

      public Errors constructorNotDefinedByType(Constructor<?> constructor, TypeLiteral<?> type)
    • duplicateMapKey

      public <K, V> Errors duplicateMapKey(Key<Map<K,V>> mapKey, com.google.common.collect.Multimap<K,Binding<V>> duplicates)
    • duplicateScopes

      public Errors duplicateScopes(ScopeBinding existing, Class<? extends Annotation> annotationType, Scope scope)
    • voidProviderMethod

      public Errors voidProviderMethod()
    • missingConstantValues

      public Errors missingConstantValues()
    • cannotInjectInnerClass

      public Errors cannotInjectInnerClass(Class<?> type)
    • cannotInjectLocalClass

      public Errors cannotInjectLocalClass(Class<?> type)
    • duplicateBindingAnnotations

      public Errors duplicateBindingAnnotations(Member member, Class<? extends Annotation> a, Class<? extends Annotation> b)
    • staticInjectionOnInterface

      public Errors staticInjectionOnInterface(Class<?> clazz)
    • cannotInjectFinalField

      public Errors cannotInjectFinalField(Field field)
    • atTargetIsMissingParameter

      public Errors atTargetIsMissingParameter(Annotation bindingAnnotation, String parameterName, Class<?> clazz)
    • cannotInjectAbstractMethod

      public Errors cannotInjectAbstractMethod(Method method)
    • cannotInjectMethodWithTypeParameters

      public Errors cannotInjectMethodWithTypeParameters(Method method)
    • duplicateScopeAnnotations

      public Errors duplicateScopeAnnotations(Class<? extends Annotation> a, Class<? extends Annotation> b)
    • recursiveBinding

      public Errors recursiveBinding(Key<?> key, Key<?> linkedKey)
    • bindingAlreadySet

      Errors bindingAlreadySet(Binding<?> binding, Binding<?> original)
    • bindingAlreadySet

      public Errors bindingAlreadySet(Key<?> key, Object source)
    • jitBindingAlreadySet

      public Errors jitBindingAlreadySet(Key<?> key)
    • childBindingAlreadySet

      public Errors childBindingAlreadySet(Key<?> key, Set<Object> sources)
    • errorCheckingDuplicateBinding

      public Errors errorCheckingDuplicateBinding(Key<?> key, Object source, Throwable t)
    • errorNotifyingTypeListener

      public Errors errorNotifyingTypeListener(TypeListenerBinding listener, TypeLiteral<?> type, Throwable cause)
    • exposedButNotBound

      public Errors exposedButNotBound(Key<?> key)
    • keyNotFullySpecified

      public Errors keyNotFullySpecified(TypeLiteral<?> typeLiteral)
    • errorEnhancingClass

      public Errors errorEnhancingClass(Class<?> clazz, Throwable cause)
    • getMessagesFromThrowable

      public static Collection<Message> getMessagesFromThrowable(Throwable throwable)
    • errorInUserCode

      public Errors errorInUserCode(Throwable cause, String messageFormat, Object... arguments)
    • cannotInjectRawProvider

      public Errors cannotInjectRawProvider()
    • cannotInjectRawMembersInjector

      public Errors cannotInjectRawMembersInjector()
    • cannotInjectTypeLiteralOf

      public Errors cannotInjectTypeLiteralOf(Type unsupportedType)
    • cannotInjectRawTypeLiteral

      public Errors cannotInjectRawTypeLiteral()
    • throwCreationExceptionIfErrorsExist

      public void throwCreationExceptionIfErrorsExist()
    • throwConfigurationExceptionIfErrorsExist

      public void throwConfigurationExceptionIfErrorsExist()
    • throwProvisionExceptionIfErrorsExist

      public void throwProvisionExceptionIfErrorsExist()
    • merge

      public Errors merge(Collection<Message> messages)
    • merge

      public Errors merge(Errors moreErrors)
    • merge

      public Errors merge(InternalProvisionException ipe)
    • getSources

      private List<Object> getSources()
    • throwIfNewErrors

      public void throwIfNewErrors(int expectedSize) throws ErrorsException
      Throws:
      ErrorsException
    • toException

      public ErrorsException toException()
    • hasErrors

      public boolean hasErrors()
    • addMessage

      public Errors addMessage(String messageFormat, Object... arguments)
    • addMessage

      public Errors addMessage(ErrorId errorId, String messageFormat, Object... arguments)
    • addMessage

      private Errors addMessage(ErrorId errorId, Throwable cause, String messageFormat, Object... arguments)
    • addMessage

      public Errors addMessage(Message message)
    • format

      public static String format(String messageFormat, Object... arguments)
    • getMessages

      public List<Message> getMessages()
    • size

      public int size()
    • convert

      public static Object convert(Object o)
    • convert

      public static Object convert(Object o, ElementSource source)
    • formatSource

      public static void formatSource(Formatter formatter, Object source)