@@ -31,7 +31,7 @@ public final class ServiceException extends RuntimeException implements SafeLogg
3131    private  final  List <Arg <?>> args ;  // unmodifiable 
3232
3333    private  final  String  errorInstanceId  = UUID .randomUUID ().toString ();
34-     private  final  String  safeMessage ;
34+     private  final  String  unsafeMessage ;
3535    private  final  String  noArgsMessage ;
3636
3737    /** 
@@ -45,12 +45,12 @@ public ServiceException(ErrorType errorType, Arg<?>... parameters) {
4545    /** As above, but additionally records the cause of this exception. */ 
4646    public  ServiceException (ErrorType  errorType , @ Nullable  Throwable  cause , Arg <?>... args ) {
4747        // TODO(rfink): Memoize formatting? 
48-         super (renderSafeMessage ( errorType ,  args ),  cause );
48+         super (cause );
4949
5050        this .errorType  = errorType ;
5151        // Note that instantiators cannot mutate List<> args since it comes through copyToList in all code paths. 
5252        this .args  = copyToUnmodifiableList (args );
53-         this .safeMessage  = renderSafeMessage (errorType , args );
53+         this .unsafeMessage  = renderUnsafeMessage (errorType , args );
5454        this .noArgsMessage  = renderNoArgsMessage (errorType );
5555    }
5656
@@ -66,8 +66,8 @@ public String getErrorInstanceId() {
6666
6767    @ Override 
6868    public  String  getMessage () {
69-         // Including safe  args here since any logger not configured with safe-logging will log this message. 
70-         return  safeMessage ;
69+         // Including all  args here since any logger not configured with safe-logging will log this message. 
70+         return  unsafeMessage ;
7171    }
7272
7373    @ Override 
@@ -97,7 +97,7 @@ private static <T> List<T> copyToUnmodifiableList(T[] elements) {
9797        return  Collections .unmodifiableList (list );
9898    }
9999
100-     private  static  String  renderSafeMessage (ErrorType  errorType , Arg <?>... args ) {
100+     private  static  String  renderUnsafeMessage (ErrorType  errorType , Arg <?>... args ) {
101101        String  message  = renderNoArgsMessage (errorType );
102102
103103        if  (args .length  == 0 ) {
@@ -106,15 +106,13 @@ private static String renderSafeMessage(ErrorType errorType, Arg<?>... args) {
106106
107107        StringBuilder  builder  = new  StringBuilder ();
108108        builder .append (message ).append (": {" );
109-         int  consumedArgs  = 0 ;
110-         for  (Arg <?> arg  : args ) {
111-             if  (arg .isSafeForLogging ()) {
112-                 if  (consumedArgs ++ > 0 ) {
113-                     builder .append (", " );
114-                 }
115- 
116-                 builder .append (arg .getName ()).append ("=" ).append (arg .getValue ());
109+         for  (int  i  = 0 ; i  < args .length ; i ++) {
110+             Arg <?> arg  = args [i ];
111+             if  (i  > 0 ) {
112+                 builder .append (", " );
117113            }
114+ 
115+             builder .append (arg .getName ()).append ("=" ).append (arg .getValue ());
118116        }
119117        builder .append ("}" );
120118
0 commit comments