Skip to content

Commit

Permalink
Add SafeLoggable SafeUnsupportedOperationException (#860)
Browse files Browse the repository at this point in the history
Add SafeLoggable SafeUnsupportedOperationException
  • Loading branch information
carterkozak authored Apr 21, 2023
1 parent fa78839 commit 24875e4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-860.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Add SafeLoggable SafeUnsupportedOperationException
links:
- https://github.com/palantir/safe-logging/pull/860
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.logsafe.exceptions;

import com.google.errorprone.annotations.CompileTimeConstant;
import com.palantir.logsafe.Arg;
import com.palantir.logsafe.SafeLoggable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public final class SafeUnsupportedOperationException extends UnsupportedOperationException implements SafeLoggable {
private final String logMessage;
private final List<Arg<?>> arguments;

public SafeUnsupportedOperationException() {
super("");
this.logMessage = "";
this.arguments = Collections.emptyList();
}

public SafeUnsupportedOperationException(@CompileTimeConstant String message, Arg<?>... arguments) {
super(SafeExceptions.renderMessage(message, arguments));
this.logMessage = message;
this.arguments = Collections.unmodifiableList(Arrays.asList(arguments));
}

public SafeUnsupportedOperationException(
@CompileTimeConstant String message, Throwable cause, Arg<?>... arguments) {
super(SafeExceptions.renderMessage(message, arguments), cause);
this.logMessage = message;
this.arguments = Collections.unmodifiableList(Arrays.asList(arguments));
}

public SafeUnsupportedOperationException(Throwable cause) {
super("", cause);
this.logMessage = "";
this.arguments = Collections.emptyList();
}

@Override
public String getLogMessage() {
return logMessage;
}

@Override
public List<Arg<?>> getArgs() {
return arguments;
}
}

0 comments on commit 24875e4

Please sign in to comment.