Can Guice be configured to hide the class path in stack traces?

佐手、 提交于 2019-12-24 03:18:12

问题


Guice's stack traces can get so verbose that they are very painful to read. Here's an example:

1) No implementation for java.util.Set<com.mydomain.myapp.android.activities.catbrowser.generalizedbrowser.listview.helpers.databaseitem.itemmanipulators.ItemManipulator<com.mydomain.myapp.flash.Cat>> annotated with @com.google.inject.assistedinject.Assisted(value=) was bound.
  while locating java.util.Set<com.mydomain.myapp.android.activities.catbrowser.generalizedbrowser.listview.helpers.databaseitem.itemmanipulators.ItemManipulator<com.mydomain.myapp.flash.Cat>> annotated with @com.google.inject.assistedinject.Assisted(value=)

...

If I could hide the classpath, it would look like:

1) No implementation for Set<ItemManipulator<Cat>> annotated with @Assisted(value=) was bound.
  while locating Set<ItemManipulator<Cat>> annotated with @Assisted(value=)

Is there any way to configure Guice to do this?


回答1:


So the answer is no.

If you take look at guice source code you will find com.google.inject.internal.Errors class that is responsible for building error messages. In this class it is coded that the Key is converting the following way:

  new Converter<Key>(Key.class) {
    public String toString(Key key) {
      if (key.getAnnotationType() != null) {
        return key.getTypeLiteral() + " annotated with "
            + (key.getAnnotation() != null ? key.getAnnotation() : key.getAnnotationType());
      } else {
        return key.getTypeLiteral().toString();
      }
    }
  }

Next step is to take a look at TypeLiteral#toString method:

  @Override public final String toString() {
    return MoreTypes.typeToString(type);
  }

Where MoreTypes#typeToString is a static method that cannot be configured

  public static String typeToString(Type type) {
    return type instanceof Class ? ((Class) type).getName() : type.toString();
  }


来源:https://stackoverflow.com/questions/8766843/can-guice-be-configured-to-hide-the-class-path-in-stack-traces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!