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

Replace NoStackTraceThrowable with NoStackTraceException #4854 #4855

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/main/java/io/vertx/core/Promise.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import io.vertx.codegen.annotations.CacheReturn;
import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.impl.NoStackTraceThrowable;
import io.vertx.core.impl.NoStackTraceException;
import io.vertx.core.impl.future.PromiseImpl;

/**
Expand Down Expand Up @@ -137,7 +137,7 @@ default boolean tryComplete() {
* @return false when the future is already completed
*/
default boolean tryFail(String message) {
return tryFail(new NoStackTraceThrowable(message));
return tryFail(new NoStackTraceException(message));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/vertx/core/dns/DnsException.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

package io.vertx.core.dns;

import io.vertx.core.impl.NoStackTraceThrowable;
import io.vertx.core.impl.NoStackTraceException;
import java.util.Objects;

/**
Expand All @@ -20,10 +20,10 @@
*
* @author <a href="mailto:[email protected]">Norman Maurer</a>
*/
public final class DnsException extends NoStackTraceThrowable {
public final class DnsException extends NoStackTraceException {

private static final String ERROR_MESSAGE_PREFIX = "DNS query error occurred: ";
private DnsResponseCode code;
private final DnsResponseCode code;

public DnsException(DnsResponseCode code) {
super(ERROR_MESSAGE_PREFIX + code);
Expand Down
36 changes: 31 additions & 5 deletions src/main/java/io/vertx/core/impl/NoStackTraceException.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,40 @@

/**
* @author <a href="mailto:[email protected]">Julien Viet</a>
* @see VertxException
*/
public class NoStackTraceException extends VertxException {
@SuppressWarnings("deprecation")
public class NoStackTraceException extends NoStackTraceThrowable {

public NoStackTraceException(String message) {
super(message, null, true);
public NoStackTraceException (String message, Throwable cause){
super(message, cause);
}

public NoStackTraceException(Throwable cause) {
super(cause, true);
public NoStackTraceException (String message){
super(message);
}

public NoStackTraceException (Throwable cause){
super(cause);
}

public NoStackTraceException (){
}

// after removing NoStackTraceThrowable
// public NoStackTraceException (String message, Throwable cause) {
// super(message, cause, true);
// }
//
// public NoStackTraceException(String message) {
// super(message, null, true);// disable cause too
// }
//
// public NoStackTraceException(Throwable cause) {
// super(cause, true);
// }
//
// public NoStackTraceException() {
// super((Throwable) null, true);// disable cause too
// }
}
23 changes: 21 additions & 2 deletions src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,31 @@

package io.vertx.core.impl;

import io.vertx.core.VertxException;

/**
* @deprecated Please use {@link NoStackTraceException} instead. NoStackTraceThrowable extends Throwable, which is generally considered a bad practice.
* @author <a href="http://tfox.org">Tim Fox</a>
*/
public class NoStackTraceThrowable extends Throwable {
public class NoStackTraceThrowable extends VertxException {

@Deprecated
public NoStackTraceThrowable (String message, Throwable cause) {
super(message, cause, true);
}

@Deprecated
public NoStackTraceThrowable(String message) {
super(message, null, false, false);
super(message, null, true);// disable cause too
}

@Deprecated
public NoStackTraceThrowable(Throwable cause) {
super(cause, true);
}

@Deprecated
public NoStackTraceThrowable() {
super((Throwable) null, true);// disable cause too
}
}
6 changes: 3 additions & 3 deletions src/main/java/io/vertx/core/impl/future/FailedFuture.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.impl.ContextInternal;
import io.vertx.core.impl.NoStackTraceThrowable;
import io.vertx.core.impl.NoStackTraceException;

import java.util.function.Function;

Expand All @@ -42,7 +42,7 @@ public FailedFuture(Throwable t) {
*/
public FailedFuture(ContextInternal context, Throwable t) {
super(context);
this.cause = t != null ? t : new NoStackTraceThrowable(null);
this.cause = t != null ? t : new NoStackTraceException();
}

/**
Expand All @@ -58,7 +58,7 @@ public FailedFuture(String failureMessage) {
* @param failureMessage the failure message
*/
public FailedFuture(ContextInternal context, String failureMessage) {
this(context, new NoStackTraceThrowable(failureMessage));
this(context, new NoStackTraceException(failureMessage));
}

@Override
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/io/vertx/core/impl/future/FutureImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.impl.ContextInternal;
import io.vertx.core.impl.NoStackTraceThrowable;
import io.vertx.core.impl.NoStackTraceException;

import java.util.ArrayList;
import java.util.Objects;
Expand All @@ -36,7 +36,6 @@ class FutureImpl<T> extends FutureBase<T> {
* Create a future that hasn't completed yet
*/
FutureImpl() {
super();
}

/**
Expand Down Expand Up @@ -250,7 +249,7 @@ public boolean tryComplete(T result) {

public boolean tryFail(Throwable cause) {
if (cause == null) {
cause = new NoStackTraceThrowable(null);
cause = new NoStackTraceException();
}
Listener<T> l;
synchronized (this) {
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/io/vertx/core/FutureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
package io.vertx.core;

import io.vertx.core.impl.ContextInternal;
import io.vertx.core.impl.NoStackTraceThrowable;
import io.vertx.core.impl.NoStackTraceException;
import io.vertx.core.impl.future.PromiseInternal;
import io.vertx.test.core.Repeat;
import org.junit.Test;
Expand Down Expand Up @@ -202,7 +202,7 @@ public void testFailFutureToHandler() {
public void testCreateFailedWithNullFailure() {
Future<String> future = Future.failedFuture((Throwable)null);
Checker<String> checker = new Checker<>(future);
NoStackTraceThrowable failure = (NoStackTraceThrowable) checker.assertFailed();
NoStackTraceException failure = (NoStackTraceException) checker.assertFailed();
assertNull(failure.getMessage());
}

Expand All @@ -211,7 +211,7 @@ public void testFailureFutureWithNullFailure() {
Promise<String> promise = Promise.promise();
promise.fail((Throwable)null);
Checker<String> checker = new Checker<>(promise.future());
NoStackTraceThrowable failure = (NoStackTraceThrowable) checker.assertFailed();
NoStackTraceException failure = (NoStackTraceException) checker.assertFailed();
assertNull(failure.getMessage());
}

Expand Down Expand Up @@ -1647,7 +1647,7 @@ private void testListenersReportFailureOnContextAfterCompletion(Function<Context
@Test
public void testAndThenComplete() {
waitFor(4);
Throwable throwable = new NoStackTraceThrowable("test");
Throwable throwable = new NoStackTraceException("test");

testAndThen(Future.succeededFuture(), null, null);

Expand All @@ -1668,7 +1668,7 @@ public void testAndThenComplete() {
@Repeat(times = 50)
public void testAndThenCompleteContextual() {
waitFor(4);
Throwable throwable = new NoStackTraceThrowable("test");
Throwable throwable = new NoStackTraceException("test");

ContextInternal context = (ContextInternal) vertx.getOrCreateContext();

Expand Down