From 3a03dd549f388b7d5ab91650bd2ce41cee96a0fc Mon Sep 17 00:00:00 2001 From: "A.Fink" Date: Tue, 12 Sep 2023 16:42:35 +0300 Subject: [PATCH 1/5] Replace NoStackTraceThrowable with NoStackTraceException #4854 --- src/main/java/io/vertx/core/Promise.java | 4 ++-- src/main/java/io/vertx/core/dns/DnsException.java | 6 +++--- .../java/io/vertx/core/impl/NoStackTraceException.java | 10 +++++++++- .../java/io/vertx/core/impl/NoStackTraceThrowable.java | 9 +++++---- .../java/io/vertx/core/impl/future/FailedFuture.java | 6 +++--- .../java/io/vertx/core/impl/future/FutureImpl.java | 5 ++--- src/test/java/io/vertx/core/FutureTest.java | 10 +++++----- 7 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/vertx/core/Promise.java b/src/main/java/io/vertx/core/Promise.java index 43b616da6a1..b0c1a490f7f 100644 --- a/src/main/java/io/vertx/core/Promise.java +++ b/src/main/java/io/vertx/core/Promise.java @@ -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; /** @@ -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)); } /** diff --git a/src/main/java/io/vertx/core/dns/DnsException.java b/src/main/java/io/vertx/core/dns/DnsException.java index 604c1d66a23..b154b339abe 100644 --- a/src/main/java/io/vertx/core/dns/DnsException.java +++ b/src/main/java/io/vertx/core/dns/DnsException.java @@ -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; /** @@ -20,10 +20,10 @@ * * @author Norman Maurer */ -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); diff --git a/src/main/java/io/vertx/core/impl/NoStackTraceException.java b/src/main/java/io/vertx/core/impl/NoStackTraceException.java index 0cded0be7d2..348809a5d97 100644 --- a/src/main/java/io/vertx/core/impl/NoStackTraceException.java +++ b/src/main/java/io/vertx/core/impl/NoStackTraceException.java @@ -18,11 +18,19 @@ */ public class NoStackTraceException extends VertxException { + public NoStackTraceException (String message, Throwable cause) { + super(message, cause, true); + } + public NoStackTraceException(String message) { - super(message, null, true); + super(message, null, true);// disable cause too } public NoStackTraceException(Throwable cause) { super(cause, true); } + + public NoStackTraceException() { + super((Throwable) null, true);// disable cause too + } } diff --git a/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java b/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java index 774a7e7d291..27bf2aeca9c 100644 --- a/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java +++ b/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java @@ -12,11 +12,12 @@ package io.vertx.core.impl; /** + * @deprecated Use {@link NoStackTraceException} instead. * @author Tim Fox */ -public class NoStackTraceThrowable extends Throwable { - - public NoStackTraceThrowable(String message) { - super(message, null, false, false); +@Deprecated +public class NoStackTraceThrowable extends NoStackTraceException { + public NoStackTraceThrowable (String message){ + super(message); } } diff --git a/src/main/java/io/vertx/core/impl/future/FailedFuture.java b/src/main/java/io/vertx/core/impl/future/FailedFuture.java index 063f1718162..06db0596c3c 100644 --- a/src/main/java/io/vertx/core/impl/future/FailedFuture.java +++ b/src/main/java/io/vertx/core/impl/future/FailedFuture.java @@ -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; @@ -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(); } /** @@ -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 diff --git a/src/main/java/io/vertx/core/impl/future/FutureImpl.java b/src/main/java/io/vertx/core/impl/future/FutureImpl.java index 14dc5951efb..9f79b5e1a2c 100644 --- a/src/main/java/io/vertx/core/impl/future/FutureImpl.java +++ b/src/main/java/io/vertx/core/impl/future/FutureImpl.java @@ -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; @@ -36,7 +36,6 @@ class FutureImpl extends FutureBase { * Create a future that hasn't completed yet */ FutureImpl() { - super(); } /** @@ -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 l; synchronized (this) { diff --git a/src/test/java/io/vertx/core/FutureTest.java b/src/test/java/io/vertx/core/FutureTest.java index 3636ca906bf..2471c1f497d 100644 --- a/src/test/java/io/vertx/core/FutureTest.java +++ b/src/test/java/io/vertx/core/FutureTest.java @@ -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; @@ -202,7 +202,7 @@ public void testFailFutureToHandler() { public void testCreateFailedWithNullFailure() { Future future = Future.failedFuture((Throwable)null); Checker checker = new Checker<>(future); - NoStackTraceThrowable failure = (NoStackTraceThrowable) checker.assertFailed(); + NoStackTraceException failure = (NoStackTraceException) checker.assertFailed(); assertNull(failure.getMessage()); } @@ -211,7 +211,7 @@ public void testFailureFutureWithNullFailure() { Promise promise = Promise.promise(); promise.fail((Throwable)null); Checker checker = new Checker<>(promise.future()); - NoStackTraceThrowable failure = (NoStackTraceThrowable) checker.assertFailed(); + NoStackTraceException failure = (NoStackTraceException) checker.assertFailed(); assertNull(failure.getMessage()); } @@ -1647,7 +1647,7 @@ private void testListenersReportFailureOnContextAfterCompletion(Function Date: Tue, 12 Sep 2023 22:51:29 +0300 Subject: [PATCH 2/5] core review --- .../java/io/vertx/core/impl/NoStackTraceThrowable.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java b/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java index 27bf2aeca9c..2cb0dd5d9ed 100644 --- a/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java +++ b/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java @@ -12,12 +12,13 @@ package io.vertx.core.impl; /** - * @deprecated Use {@link NoStackTraceException} instead. + * @deprecated Please use {@link NoStackTraceException} instead. NoStackTraceThrowable extends Throwable, which is generally considered a bad practice. * @author Tim Fox */ @Deprecated -public class NoStackTraceThrowable extends NoStackTraceException { +public class NoStackTraceThrowable extends Throwable { + public NoStackTraceThrowable (String message){ - super(message); + super(message, null, false, false); } } From 6b8242c3022c1429102f93df460a900046c1ab26 Mon Sep 17 00:00:00 2001 From: "A.Fink" Date: Tue, 12 Sep 2023 23:09:45 +0300 Subject: [PATCH 3/5] =?UTF-8?q?better=20(temporarily)=20solution:=20VertxE?= =?UTF-8?q?xception=20=E2=86=92=20NoStackTraceThrowable=20=E2=86=92=20NoSt?= =?UTF-8?q?ackTraceException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If some code catches NoStackTraceThrowable, it won't break, but shows deprecated waring. After all code migrates to NoStackTraceException we can remove NoStackTraceThrowable: VertxException → NoStackTraceException I think nobody will miss changing parent of NoStackTraceThrowable from Throwable to RuntimeException --- .../core/impl/NoStackTraceException.java | 35 ++++++++++++++----- .../core/impl/NoStackTraceThrowable.java | 20 +++++++++-- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/vertx/core/impl/NoStackTraceException.java b/src/main/java/io/vertx/core/impl/NoStackTraceException.java index 348809a5d97..8a28ce854a1 100644 --- a/src/main/java/io/vertx/core/impl/NoStackTraceException.java +++ b/src/main/java/io/vertx/core/impl/NoStackTraceException.java @@ -15,22 +15,39 @@ /** * @author Julien Viet + * @see VertxException */ -public class NoStackTraceException extends VertxException { +public class NoStackTraceException extends NoStackTraceThrowable { - public NoStackTraceException (String message, Throwable cause) { - super(message, cause, true); + public NoStackTraceException (String message, Throwable cause){ + super(message, cause); } - public NoStackTraceException(String message) { - super(message, null, true);// disable cause too + public NoStackTraceException (String message){ + super(message); } - public NoStackTraceException(Throwable cause) { - super(cause, true); + public NoStackTraceException (Throwable cause){ + super(cause); } - public NoStackTraceException() { - super((Throwable) null, true);// disable cause too + 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 +// } } diff --git a/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java b/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java index 2cb0dd5d9ed..5d0646075bf 100644 --- a/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java +++ b/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java @@ -11,14 +11,28 @@ 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 Tim Fox */ @Deprecated -public class NoStackTraceThrowable extends Throwable { +public class NoStackTraceThrowable extends VertxException { + + public NoStackTraceThrowable (String message, Throwable cause) { + super(message, cause, true); + } + + public NoStackTraceThrowable(String message) { + super(message, null, true);// disable cause too + } + + public NoStackTraceThrowable(Throwable cause) { + super(cause, true); + } - public NoStackTraceThrowable (String message){ - super(message, null, false, false); + public NoStackTraceThrowable() { + super((Throwable) null, true);// disable cause too } } From c09f004264fc261422d4b14ca1bb37b3f911f153 Mon Sep 17 00:00:00 2001 From: "A.Fink" Date: Wed, 13 Sep 2023 15:23:23 +0300 Subject: [PATCH 4/5] code review: deprecate ctors, not class itself --- src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java b/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java index 5d0646075bf..69c9d91c700 100644 --- a/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java +++ b/src/main/java/io/vertx/core/impl/NoStackTraceThrowable.java @@ -17,21 +17,24 @@ * @deprecated Please use {@link NoStackTraceException} instead. NoStackTraceThrowable extends Throwable, which is generally considered a bad practice. * @author Tim Fox */ -@Deprecated public class NoStackTraceThrowable extends VertxException { + @Deprecated public NoStackTraceThrowable (String message, Throwable cause) { super(message, cause, true); } + @Deprecated public NoStackTraceThrowable(String message) { 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 } From 6d156bb093558a0bfa8ea5c6458c34d01e153c50 Mon Sep 17 00:00:00 2001 From: "A.Fink" Date: Wed, 13 Sep 2023 15:47:37 +0300 Subject: [PATCH 5/5] fix deprecation warning for NoStackTraceException --- src/main/java/io/vertx/core/impl/NoStackTraceException.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/io/vertx/core/impl/NoStackTraceException.java b/src/main/java/io/vertx/core/impl/NoStackTraceException.java index 8a28ce854a1..4e5aab27e78 100644 --- a/src/main/java/io/vertx/core/impl/NoStackTraceException.java +++ b/src/main/java/io/vertx/core/impl/NoStackTraceException.java @@ -17,6 +17,7 @@ * @author Julien Viet * @see VertxException */ +@SuppressWarnings("deprecation") public class NoStackTraceException extends NoStackTraceThrowable { public NoStackTraceException (String message, Throwable cause){