Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply the error-prone CompileTimeConstant annotation to safe messages #104

Merged
merged 3 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions preconditions/src/main/java/com/palantir/logsafe/Preconditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.palantir.logsafe;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.CompileTimeConstant;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import com.palantir.logsafe.exceptions.SafeIllegalStateException;
import com.palantir.logsafe.exceptions.SafeNullPointerException;
Expand Down Expand Up @@ -46,7 +47,7 @@ public static void checkArgument(boolean expression) {
* @param message the loggable exception message
* @throws SafeIllegalArgumentException if {@code expression} is false
*/
public static void checkArgument(boolean expression, String message) {
public static void checkArgument(boolean expression, @CompileTimeConstant String message) {
if (!expression) {
throw new SafeIllegalArgumentException(message);
}
Expand All @@ -57,7 +58,7 @@ public static void checkArgument(boolean expression, String message) {
*
* <p>See {@link #checkArgument(boolean, String, Arg...)} for details.
*/
public static void checkArgument(boolean expression, String message, Arg<?> arg) {
public static void checkArgument(boolean expression, @CompileTimeConstant String message, Arg<?> arg) {
if (!expression) {
throw new SafeIllegalArgumentException(message, arg);
}
Expand All @@ -68,7 +69,8 @@ public static void checkArgument(boolean expression, String message, Arg<?> arg)
*
* <p>See {@link #checkArgument(boolean, String, Arg...)} for details.
*/
public static void checkArgument(boolean expression, String message, Arg<?> arg1, Arg<?> arg2) {
public static void checkArgument(
boolean expression, @CompileTimeConstant String message, Arg<?> arg1, Arg<?> arg2) {
if (!expression) {
throw new SafeIllegalArgumentException(message, arg1, arg2);
}
Expand All @@ -79,7 +81,8 @@ public static void checkArgument(boolean expression, String message, Arg<?> arg1
*
* <p>See {@link #checkArgument(boolean, String, Arg...)} for details.
*/
public static void checkArgument(boolean expression, String message, Arg<?> arg1, Arg<?> arg2, Arg<?> arg3) {
public static void checkArgument(
boolean expression, @CompileTimeConstant String message, Arg<?> arg1, Arg<?> arg2, Arg<?> arg3) {
if (!expression) {
throw new SafeIllegalArgumentException(message, arg1, arg2, arg3);
}
Expand All @@ -93,7 +96,7 @@ public static void checkArgument(boolean expression, String message, Arg<?> arg1
* @param args the arguments to include in the {@link SafeIllegalArgumentException}
* @throws SafeIllegalArgumentException if {@code expression} is false
*/
public static void checkArgument(boolean expression, String message, Arg<?>... args) {
public static void checkArgument(boolean expression, @CompileTimeConstant String message, Arg<?>... args) {
if (!expression) {
throw new SafeIllegalArgumentException(message, args);
}
Expand All @@ -120,7 +123,7 @@ public static void checkState(boolean expression) {
* @param message the loggable exception message
* @throws SafeIllegalStateException if {@code expression} is false
*/
public static void checkState(boolean expression, String message) {
public static void checkState(boolean expression, @CompileTimeConstant String message) {
if (!expression) {
throw new SafeIllegalStateException(message);
}
Expand All @@ -131,7 +134,7 @@ public static void checkState(boolean expression, String message) {
*
* <p>See {@link #checkState(boolean, String, Arg...)} for details.
*/
public static void checkState(boolean expression, String message, Arg<?> arg) {
public static void checkState(boolean expression, @CompileTimeConstant String message, Arg<?> arg) {
if (!expression) {
throw new SafeIllegalStateException(message, arg);
}
Expand All @@ -142,7 +145,7 @@ public static void checkState(boolean expression, String message, Arg<?> arg) {
*
* <p>See {@link #checkState(boolean, String, Arg...)} for details.
*/
public static void checkState(boolean expression, String message, Arg<?> arg1, Arg<?> arg2) {
public static void checkState(boolean expression, @CompileTimeConstant String message, Arg<?> arg1, Arg<?> arg2) {
if (!expression) {
throw new SafeIllegalStateException(message, arg1, arg2);
}
Expand All @@ -153,7 +156,8 @@ public static void checkState(boolean expression, String message, Arg<?> arg1, A
*
* <p>See {@link #checkState(boolean, String, Arg...)} for details.
*/
public static void checkState(boolean expression, String message, Arg<?> arg1, Arg<?> arg2, Arg<?> arg3) {
public static void checkState(
boolean expression, @CompileTimeConstant String message, Arg<?> arg1, Arg<?> arg2, Arg<?> arg3) {
if (!expression) {
throw new SafeIllegalStateException(message, arg1, arg2, arg3);
}
Expand All @@ -168,7 +172,7 @@ public static void checkState(boolean expression, String message, Arg<?> arg1, A
* @param args the arguments to include in the {@link SafeIllegalStateException}
* @throws SafeIllegalStateException if {@code expression} is false
*/
public static void checkState(boolean expression, String message, Arg<?>... args) {
public static void checkState(boolean expression, @CompileTimeConstant String message, Arg<?>... args) {
if (!expression) {
throw new SafeIllegalStateException(message, args);
}
Expand Down Expand Up @@ -198,7 +202,7 @@ public static <T> T checkNotNull(@Nullable T reference) {
* @throws SafeNullPointerException if {@code reference} is null
*/
@CanIgnoreReturnValue
public static <T> T checkNotNull(@Nullable T reference, String message) {
public static <T> T checkNotNull(@Nullable T reference, @CompileTimeConstant String message) {
if (reference == null) {
throw new SafeNullPointerException(message);
}
Expand All @@ -211,7 +215,7 @@ public static <T> T checkNotNull(@Nullable T reference, String message) {
* <p>See {@link #checkNotNull(Object, String, Arg...)} for details.
*/
@CanIgnoreReturnValue
public static <T> T checkNotNull(@Nullable T reference, String message, Arg<?> arg) {
public static <T> T checkNotNull(@Nullable T reference, @CompileTimeConstant String message, Arg<?> arg) {
if (reference == null) {
throw new SafeNullPointerException(message, arg);
}
Expand All @@ -224,7 +228,8 @@ public static <T> T checkNotNull(@Nullable T reference, String message, Arg<?> a
* <p>See {@link #checkNotNull(Object, String, Arg...)} for details.
*/
@CanIgnoreReturnValue
public static <T> T checkNotNull(@Nullable T reference, String message, Arg<?> arg1, Arg<?> arg2) {
public static <T> T checkNotNull(
@Nullable T reference, @CompileTimeConstant String message, Arg<?> arg1, Arg<?> arg2) {
if (reference == null) {
throw new SafeNullPointerException(message, arg1, arg2);
}
Expand All @@ -237,7 +242,8 @@ public static <T> T checkNotNull(@Nullable T reference, String message, Arg<?> a
* <p>See {@link #checkNotNull(Object, String, Arg...)} for details.
*/
@CanIgnoreReturnValue
public static <T> T checkNotNull(@Nullable T reference, String message, Arg<?> arg1, Arg<?> arg2, Arg<?> arg3) {
public static <T> T checkNotNull(
@Nullable T reference, @CompileTimeConstant String message, Arg<?> arg1, Arg<?> arg2, Arg<?> arg3) {
if (reference == null) {
throw new SafeNullPointerException(message, arg1, arg2, arg3);
}
Expand All @@ -254,7 +260,7 @@ public static <T> T checkNotNull(@Nullable T reference, String message, Arg<?> a
* @throws SafeNullPointerException if {@code reference} is null
*/
@CanIgnoreReturnValue
public static <T> T checkNotNull(@Nullable T reference, String message, Arg<?>... args) {
public static <T> T checkNotNull(@Nullable T reference, @CompileTimeConstant String message, Arg<?>... args) {
if (reference == null) {
throw new SafeNullPointerException(message, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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;
Expand All @@ -32,13 +33,13 @@ public SafeIllegalArgumentException() {
this.arguments = Collections.emptyList();
}

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

public SafeIllegalArgumentException(String message, Throwable cause, Arg<?>... arguments) {
public SafeIllegalArgumentException(@CompileTimeConstant String message, Throwable cause, Arg<?>... arguments) {
super(SafeExceptions.renderMessage(message, arguments), cause);
this.logMessage = message;
this.arguments = Collections.unmodifiableList(Arrays.asList(arguments));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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;
Expand All @@ -32,13 +33,13 @@ public SafeIllegalStateException() {
this.arguments = Collections.emptyList();
}

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

public SafeIllegalStateException(String message, Throwable cause, Arg<?>... arguments) {
public SafeIllegalStateException(@CompileTimeConstant String message, Throwable cause, Arg<?>... arguments) {
super(SafeExceptions.renderMessage(message, arguments), cause);
this.logMessage = message;
this.arguments = Collections.unmodifiableList(Arrays.asList(arguments));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.palantir.logsafe.exceptions;

import com.google.errorprone.annotations.CompileTimeConstant;
import com.palantir.logsafe.Arg;
import com.palantir.logsafe.SafeLoggable;
import java.io.IOException;
Expand All @@ -27,13 +28,13 @@ public final class SafeIoException extends IOException implements SafeLoggable {
private final String logMessage;
private final List<Arg<?>> arguments;

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

public SafeIoException(String message, Throwable cause, Arg<?>... arguments) {
public SafeIoException(@CompileTimeConstant String message, Throwable cause, Arg<?>... arguments) {
super(SafeExceptions.renderMessage(message, arguments), cause);
this.logMessage = message;
this.arguments = Collections.unmodifiableList(Arrays.asList(arguments));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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;
Expand All @@ -32,7 +33,7 @@ public SafeNullPointerException() {
this.arguments = Collections.emptyList();
}

public SafeNullPointerException(String message, Arg<?>... arguments) {
public SafeNullPointerException(@CompileTimeConstant String message, Arg<?>... arguments) {
super(SafeExceptions.renderMessage(message, arguments));
this.logMessage = message;
this.arguments = Collections.unmodifiableList(Arrays.asList(arguments));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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;
Expand All @@ -32,13 +33,13 @@ public SafeRuntimeException() {
this.arguments = Collections.emptyList();
}

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

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