diff --git a/src/main/java/com/hivemq/client/internal/mqtt/MqttBlockingClient.java b/src/main/java/com/hivemq/client/internal/mqtt/MqttBlockingClient.java index dcce1bfdc..d573e10b0 100644 --- a/src/main/java/com/hivemq/client/internal/mqtt/MqttBlockingClient.java +++ b/src/main/java/com/hivemq/client/internal/mqtt/MqttBlockingClient.java @@ -168,7 +168,7 @@ private static class MqttPublishes implements Mqtt5Publishes, FlowableSubscriber private final @NotNull AtomicReference<@Nullable Subscription> subscription = new AtomicReference<>(); private final @NotNull LinkedList entries = new LinkedList<>(); private @Nullable Mqtt5Publish queuedPublish; - private boolean cancelled; + private @Nullable Throwable error; MqttPublishes(final @NotNull Flowable publishes) { publishes.subscribe(this); @@ -192,7 +192,7 @@ private void request() { @Override public void onNext(final @NotNull Mqtt5Publish publish) { synchronized (entries) { - if (cancelled) { + if (error != null) { return; } Entry entry; @@ -216,9 +216,10 @@ public void onComplete() { @Override public void onError(final @NotNull Throwable t) { synchronized (entries) { - if (cancelled) { + if (error != null) { return; } + error = t; Entry entry; while ((entry = entries.poll()) != null) { entry.result.set(t); @@ -231,8 +232,8 @@ public void onError(final @NotNull Throwable t) { public @NotNull Mqtt5Publish receive() throws InterruptedException { final Entry entry; synchronized (entries) { - if (cancelled) { - throw new CancellationException(); + if (error != null) { + throw handleError(error); } final Mqtt5Publish publish = receiveNowUnsafe(); if (publish != null) { @@ -253,10 +254,7 @@ public void onError(final @NotNull Throwable t) { return (Mqtt5Publish) result; } if (result instanceof Throwable) { - if (result instanceof RuntimeException) { - throw AsyncRuntimeException.fillInStackTrace((RuntimeException) result); - } - throw new RuntimeException((Throwable) result); + throw handleError((Throwable) result); } if (interruptedException != null) { throw interruptedException; @@ -275,8 +273,8 @@ public void onError(final @NotNull Throwable t) { final Entry entry; synchronized (entries) { - if (cancelled) { - throw new CancellationException(); + if (error != null) { + throw handleError(error); } final Mqtt5Publish publish = receiveNowUnsafe(); if (publish != null) { @@ -297,10 +295,7 @@ public void onError(final @NotNull Throwable t) { return Optional.of((Mqtt5Publish) result); } if (result instanceof Throwable) { - if (result instanceof RuntimeException) { - throw AsyncRuntimeException.fillInStackTrace((RuntimeException) result); - } - throw new RuntimeException((Throwable) result); + throw handleError((Throwable) result); } if (interruptedException != null) { throw interruptedException; @@ -312,8 +307,8 @@ public void onError(final @NotNull Throwable t) { public @NotNull Optional receiveNow() { final Mqtt5Publish publish; synchronized (entries) { - if (cancelled) { - throw new CancellationException(); + if (error != null) { + throw handleError(error); } publish = receiveNowUnsafe(); } @@ -337,18 +332,25 @@ public void close() { subscription.cancel(); } synchronized (entries) { - if (cancelled) { + if (error != null) { return; } - cancelled = true; + error = new CancellationException(); Entry entry; while ((entry = entries.poll()) != null) { - entry.result.set(new CancellationException()); + entry.result.set(error); entry.latch.countDown(); } } } + private @NotNull RuntimeException handleError(final @NotNull Throwable t) { + if (t instanceof RuntimeException) { + return AsyncRuntimeException.fillInStackTrace((RuntimeException) t); + } + throw new RuntimeException(t); + } + private static class Entry { static final @NotNull Object CANCELLED = new Object(); diff --git a/src/main/java/com/hivemq/client/internal/mqtt/mqtt3/Mqtt3BlockingClientView.java b/src/main/java/com/hivemq/client/internal/mqtt/mqtt3/Mqtt3BlockingClientView.java index c6c604bbe..4da63fc78 100644 --- a/src/main/java/com/hivemq/client/internal/mqtt/mqtt3/Mqtt3BlockingClientView.java +++ b/src/main/java/com/hivemq/client/internal/mqtt/mqtt3/Mqtt3BlockingClientView.java @@ -28,7 +28,6 @@ import com.hivemq.client.internal.mqtt.message.unsubscribe.MqttUnsubscribe; import com.hivemq.client.internal.mqtt.mqtt3.exceptions.Mqtt3ExceptionFactory; import com.hivemq.client.internal.mqtt.util.MqttChecks; -import com.hivemq.client.internal.util.AsyncRuntimeException; import com.hivemq.client.internal.util.Checks; import com.hivemq.client.mqtt.MqttGlobalPublishFilter; import com.hivemq.client.mqtt.mqtt3.Mqtt3AsyncClient; @@ -68,7 +67,7 @@ public class Mqtt3BlockingClientView implements Mqtt3BlockingClient { try { return Mqtt3ConnAckView.of(delegate.connect(mqttConnect)); } catch (final Mqtt5MessageException e) { - throw AsyncRuntimeException.fillInStackTrace(Mqtt3ExceptionFactory.map(e)); + throw Mqtt3ExceptionFactory.mapWithStackTrace(e); } } @@ -78,7 +77,7 @@ public class Mqtt3BlockingClientView implements Mqtt3BlockingClient { try { return Mqtt3SubAckView.of(delegate.subscribe(mqttSubscribe)); } catch (final Mqtt5MessageException e) { - throw AsyncRuntimeException.fillInStackTrace(Mqtt3ExceptionFactory.map(e)); + throw Mqtt3ExceptionFactory.mapWithStackTrace(e); } } @@ -95,7 +94,7 @@ public void unsubscribe(final @Nullable Mqtt3Unsubscribe unsubscribe) { try { delegate.unsubscribe(mqttUnsubscribe); } catch (final Mqtt5MessageException e) { - throw AsyncRuntimeException.fillInStackTrace(Mqtt3ExceptionFactory.map(e)); + throw Mqtt3ExceptionFactory.mapWithStackTrace(e); } } @@ -105,7 +104,7 @@ public void publish(final @Nullable Mqtt3Publish publish) { try { delegate.publish(mqttPublish); } catch (final Mqtt5MessageException e) { - throw AsyncRuntimeException.fillInStackTrace(Mqtt3ExceptionFactory.map(e)); + throw Mqtt3ExceptionFactory.mapWithStackTrace(e); } } @@ -114,7 +113,7 @@ public void disconnect() { try { delegate.disconnect(Mqtt3DisconnectView.DELEGATE); } catch (final Mqtt5MessageException e) { - throw AsyncRuntimeException.fillInStackTrace(Mqtt3ExceptionFactory.map(e)); + throw Mqtt3ExceptionFactory.mapWithStackTrace(e); } } @@ -145,8 +144,8 @@ private static class Mqtt3PublishesView implements Mqtt3Publishes { public @NotNull Mqtt3Publish receive() throws InterruptedException { try { return Mqtt3PublishView.of(delegate.receive()); - } catch (final Mqtt5MessageException e) { - throw AsyncRuntimeException.fillInStackTrace(Mqtt3ExceptionFactory.map(e)); + } catch (final RuntimeException e) { + throw Mqtt3ExceptionFactory.mapWithStackTrace(e); } } @@ -161,8 +160,8 @@ private static class Mqtt3PublishesView implements Mqtt3Publishes { try { return delegate.receive(timeout, timeUnit).map(Mqtt3PublishView.JAVA_MAPPER); - } catch (final Mqtt5MessageException e) { - throw AsyncRuntimeException.fillInStackTrace(Mqtt3ExceptionFactory.map(e)); + } catch (final RuntimeException e) { + throw Mqtt3ExceptionFactory.mapWithStackTrace(e); } } @@ -170,8 +169,8 @@ private static class Mqtt3PublishesView implements Mqtt3Publishes { public @NotNull Optional receiveNow() { try { return delegate.receiveNow().map(Mqtt3PublishView.JAVA_MAPPER); - } catch (final Mqtt5MessageException e) { - throw AsyncRuntimeException.fillInStackTrace(Mqtt3ExceptionFactory.map(e)); + } catch (final RuntimeException e) { + throw Mqtt3ExceptionFactory.mapWithStackTrace(e); } } diff --git a/src/main/java/com/hivemq/client/internal/mqtt/mqtt3/exceptions/Mqtt3ExceptionFactory.java b/src/main/java/com/hivemq/client/internal/mqtt/mqtt3/exceptions/Mqtt3ExceptionFactory.java index 2e0d8a7c1..7353a1d9c 100644 --- a/src/main/java/com/hivemq/client/internal/mqtt/mqtt3/exceptions/Mqtt3ExceptionFactory.java +++ b/src/main/java/com/hivemq/client/internal/mqtt/mqtt3/exceptions/Mqtt3ExceptionFactory.java @@ -20,6 +20,7 @@ import com.hivemq.client.internal.mqtt.message.connect.connack.mqtt3.Mqtt3ConnAckView; import com.hivemq.client.internal.mqtt.message.subscribe.suback.MqttSubAck; import com.hivemq.client.internal.mqtt.message.subscribe.suback.mqtt3.Mqtt3SubAckView; +import com.hivemq.client.mqtt.exceptions.MqttSessionExpiredException; import com.hivemq.client.mqtt.mqtt3.exceptions.*; import com.hivemq.client.mqtt.mqtt5.exceptions.Mqtt5MessageException; import com.hivemq.client.mqtt.mqtt5.message.Mqtt5Message; @@ -37,12 +38,33 @@ public final class Mqtt3ExceptionFactory { Mqtt3ExceptionFactory::map; public static @NotNull Throwable map(final @NotNull Throwable throwable) { - if (throwable instanceof Mqtt5MessageException) { - return map((Mqtt5MessageException) throwable); + if (throwable instanceof RuntimeException) { + return map((RuntimeException) throwable); } return throwable; } + public static @NotNull RuntimeException map(final @NotNull RuntimeException e) { + if (e instanceof Mqtt5MessageException) { + return map((Mqtt5MessageException) e); + } + if (e instanceof MqttSessionExpiredException) { + final Throwable cause = e.getCause(); + if (cause instanceof Mqtt5MessageException) { + return new MqttSessionExpiredException(e.getMessage(), map((Mqtt5MessageException) cause)); + } + } + return e; + } + + public static @NotNull RuntimeException mapWithStackTrace(final @NotNull RuntimeException e) { + final RuntimeException mapped = map(e); + if (mapped != e) { + mapped.setStackTrace(e.getStackTrace()); + } + return mapped; + } + public static @NotNull Mqtt3MessageException map(final @NotNull Mqtt5MessageException mqtt5MessageException) { final Mqtt5Message mqttMessage = mqtt5MessageException.getMqttMessage(); final String message = mqtt5MessageException.getMessage(); diff --git a/src/main/java/com/hivemq/client/internal/util/AsyncRuntimeException.java b/src/main/java/com/hivemq/client/internal/util/AsyncRuntimeException.java index 479373e75..8684652d7 100644 --- a/src/main/java/com/hivemq/client/internal/util/AsyncRuntimeException.java +++ b/src/main/java/com/hivemq/client/internal/util/AsyncRuntimeException.java @@ -20,6 +20,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; + /** * @author Silvio Giebl */ @@ -27,38 +29,45 @@ public abstract class AsyncRuntimeException extends RuntimeException { public static @NotNull RuntimeException fillInStackTrace(final @NotNull RuntimeException e) { if (e instanceof AsyncRuntimeException) { - e.fillInStackTrace(); + final AsyncRuntimeException copy = ((AsyncRuntimeException) e).copy(); + final StackTraceElement[] stackTrace = copy.getStackTrace(); + // remove the copy and fillInStackTrace method calls from the trace + int remove = 0; + while (remove < stackTrace.length) { + final StackTraceElement stackTraceElement = stackTrace[remove]; + remove++; + if (stackTraceElement.getClassName().equals(AsyncRuntimeException.class.getCanonicalName()) && + stackTraceElement.getMethodName().equals("fillInStackTrace")) { + break; + } + } + copy.setStackTrace(Arrays.copyOfRange(stackTrace, remove, stackTrace.length)); + return copy; } return e; } - private final boolean afterSuper; - - protected AsyncRuntimeException() { - super(); - afterSuper = true; - } - protected AsyncRuntimeException(final @Nullable String message) { super(message, null); - afterSuper = true; } protected AsyncRuntimeException(final @Nullable String message, final @Nullable Throwable cause) { super(message, cause); - afterSuper = true; } protected AsyncRuntimeException(final @Nullable Throwable cause) { super(cause); - afterSuper = true; + } + + protected AsyncRuntimeException(final @NotNull AsyncRuntimeException e) { + super(e.getMessage(), e.getCause()); + super.fillInStackTrace(); } @Override public synchronized @NotNull Throwable fillInStackTrace() { - if (afterSuper) { - return super.fillInStackTrace(); - } return this; } + + protected abstract @NotNull AsyncRuntimeException copy(); } diff --git a/src/main/java/com/hivemq/client/mqtt/exceptions/ConnectionClosedException.java b/src/main/java/com/hivemq/client/mqtt/exceptions/ConnectionClosedException.java index e95048972..da8223376 100644 --- a/src/main/java/com/hivemq/client/mqtt/exceptions/ConnectionClosedException.java +++ b/src/main/java/com/hivemq/client/mqtt/exceptions/ConnectionClosedException.java @@ -35,4 +35,13 @@ public ConnectionClosedException(final @NotNull String message) { public ConnectionClosedException(final @NotNull Throwable cause) { super(cause); } + + private ConnectionClosedException(final @NotNull ConnectionClosedException e) { + super(e); + } + + @Override + protected @NotNull ConnectionClosedException copy() { + return new ConnectionClosedException(this); + } } diff --git a/src/main/java/com/hivemq/client/mqtt/exceptions/ConnectionFailedException.java b/src/main/java/com/hivemq/client/mqtt/exceptions/ConnectionFailedException.java index e9b425630..488b27555 100644 --- a/src/main/java/com/hivemq/client/mqtt/exceptions/ConnectionFailedException.java +++ b/src/main/java/com/hivemq/client/mqtt/exceptions/ConnectionFailedException.java @@ -35,4 +35,13 @@ public ConnectionFailedException(final @NotNull String message) { public ConnectionFailedException(final @NotNull Throwable cause) { super(cause); } + + private ConnectionFailedException(final @NotNull ConnectionFailedException e) { + super(e); + } + + @Override + protected @NotNull ConnectionFailedException copy() { + return new ConnectionFailedException(this); + } } diff --git a/src/main/java/com/hivemq/client/mqtt/exceptions/MqttClientStateException.java b/src/main/java/com/hivemq/client/mqtt/exceptions/MqttClientStateException.java index a9bf2e0cb..b7f347693 100644 --- a/src/main/java/com/hivemq/client/mqtt/exceptions/MqttClientStateException.java +++ b/src/main/java/com/hivemq/client/mqtt/exceptions/MqttClientStateException.java @@ -32,4 +32,13 @@ public class MqttClientStateException extends AsyncRuntimeException { public MqttClientStateException(final @NotNull String message) { super(message); } + + private MqttClientStateException(final @NotNull MqttClientStateException e) { + super(e); + } + + @Override + protected @NotNull MqttClientStateException copy() { + return new MqttClientStateException(this); + } } diff --git a/src/main/java/com/hivemq/client/mqtt/exceptions/MqttDecodeException.java b/src/main/java/com/hivemq/client/mqtt/exceptions/MqttDecodeException.java index aa8609d32..48d534f0e 100644 --- a/src/main/java/com/hivemq/client/mqtt/exceptions/MqttDecodeException.java +++ b/src/main/java/com/hivemq/client/mqtt/exceptions/MqttDecodeException.java @@ -31,4 +31,13 @@ public class MqttDecodeException extends AsyncRuntimeException { public MqttDecodeException(final @NotNull String message) { super(message); } + + private MqttDecodeException(final @NotNull MqttDecodeException e) { + super(e); + } + + @Override + protected @NotNull MqttDecodeException copy() { + return new MqttDecodeException(this); + } } diff --git a/src/main/java/com/hivemq/client/mqtt/exceptions/MqttEncodeException.java b/src/main/java/com/hivemq/client/mqtt/exceptions/MqttEncodeException.java index 866db6418..af219d548 100644 --- a/src/main/java/com/hivemq/client/mqtt/exceptions/MqttEncodeException.java +++ b/src/main/java/com/hivemq/client/mqtt/exceptions/MqttEncodeException.java @@ -31,4 +31,13 @@ public class MqttEncodeException extends AsyncRuntimeException { public MqttEncodeException(final @NotNull String message) { super(message); } + + private MqttEncodeException(final @NotNull MqttEncodeException e) { + super(e); + } + + @Override + protected @NotNull MqttEncodeException copy() { + return new MqttEncodeException(this); + } } diff --git a/src/main/java/com/hivemq/client/mqtt/exceptions/MqttSessionExpiredException.java b/src/main/java/com/hivemq/client/mqtt/exceptions/MqttSessionExpiredException.java index 6cabbfbb2..aa4afcc52 100644 --- a/src/main/java/com/hivemq/client/mqtt/exceptions/MqttSessionExpiredException.java +++ b/src/main/java/com/hivemq/client/mqtt/exceptions/MqttSessionExpiredException.java @@ -31,4 +31,13 @@ public class MqttSessionExpiredException extends AsyncRuntimeException { public MqttSessionExpiredException(final @NotNull String message, final @NotNull Throwable cause) { super(message, cause); } + + private MqttSessionExpiredException(final @NotNull MqttSessionExpiredException e) { + super(e); + } + + @Override + protected @NotNull MqttSessionExpiredException copy() { + return new MqttSessionExpiredException(this); + } } diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3ConnAckException.java b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3ConnAckException.java index 86df2d119..d2c699220 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3ConnAckException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3ConnAckException.java @@ -36,6 +36,16 @@ public Mqtt3ConnAckException( this.connAck = connAck; } + private Mqtt3ConnAckException(final @NotNull Mqtt3ConnAckException e) { + super(e); + connAck = e.connAck; + } + + @Override + protected @NotNull Mqtt3ConnAckException copy() { + return new Mqtt3ConnAckException(this); + } + @Override public @NotNull Mqtt3ConnAck getMqttMessage() { return connAck; diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3DisconnectException.java b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3DisconnectException.java index d6b1e0ff7..ede1de705 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3DisconnectException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3DisconnectException.java @@ -32,6 +32,15 @@ public Mqtt3DisconnectException(final @Nullable String message, final @Nullable super(message, cause); } + private Mqtt3DisconnectException(final @NotNull Mqtt3DisconnectException e) { + super(e); + } + + @Override + protected @NotNull Mqtt3DisconnectException copy() { + return new Mqtt3DisconnectException(this); + } + @Override public @NotNull Mqtt3Disconnect getMqttMessage() { return Mqtt3DisconnectView.INSTANCE; diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3MessageException.java b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3MessageException.java index 7ed6980d9..0e1712803 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3MessageException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3MessageException.java @@ -33,5 +33,9 @@ public abstract class Mqtt3MessageException extends AsyncRuntimeException { super(message, cause); } + Mqtt3MessageException(final @NotNull Mqtt3MessageException e) { + super(e); + } + public abstract @NotNull Mqtt3Message getMqttMessage(); } diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3PubAckException.java b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3PubAckException.java index 5a8dbfd05..f339d54cd 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3PubAckException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3PubAckException.java @@ -32,6 +32,15 @@ public Mqtt3PubAckException(final @Nullable String message, final @Nullable Thro super(message, cause); } + private Mqtt3PubAckException(final @NotNull Mqtt3PubAckException e) { + super(e); + } + + @Override + protected @NotNull Mqtt3PubAckException copy() { + return new Mqtt3PubAckException(this); + } + @Override public @NotNull Mqtt3PubAck getMqttMessage() { return Mqtt3PubAckView.INSTANCE; diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3PubRecException.java b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3PubRecException.java index 25e103825..0e5db560d 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3PubRecException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3PubRecException.java @@ -32,6 +32,15 @@ public Mqtt3PubRecException(final @Nullable String message, final @Nullable Thro super(message, cause); } + private Mqtt3PubRecException(final @NotNull Mqtt3PubRecException e) { + super(e); + } + + @Override + protected @NotNull Mqtt3PubRecException copy() { + return new Mqtt3PubRecException(this); + } + @Override public @NotNull Mqtt3PubRec getMqttMessage() { return Mqtt3PubRecView.INSTANCE; diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3SubAckException.java b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3SubAckException.java index af5a9cefb..7a5af0f66 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3SubAckException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3SubAckException.java @@ -36,6 +36,16 @@ public Mqtt3SubAckException( this.subAck = subAck; } + private Mqtt3SubAckException(final @NotNull Mqtt3SubAckException e) { + super(e); + subAck = e.subAck; + } + + @Override + protected @NotNull Mqtt3SubAckException copy() { + return new Mqtt3SubAckException(this); + } + @Override public @NotNull Mqtt3SubAck getMqttMessage() { return subAck; diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3UnsubAckException.java b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3UnsubAckException.java index b2f2f6e3a..3ddf1431a 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3UnsubAckException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt3/exceptions/Mqtt3UnsubAckException.java @@ -32,6 +32,15 @@ public Mqtt3UnsubAckException(final @Nullable String message, final @Nullable Th super(message, cause); } + private Mqtt3UnsubAckException(final @NotNull Mqtt3UnsubAckException e) { + super(e); + } + + @Override + protected @NotNull Mqtt3UnsubAckException copy() { + return new Mqtt3UnsubAckException(this); + } + @Override public @NotNull Mqtt3UnsubAck getMqttMessage() { return Mqtt3UnsubAckView.INSTANCE; diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5AuthException.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5AuthException.java index fdfaf4603..0ac1ada78 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5AuthException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5AuthException.java @@ -33,6 +33,16 @@ public Mqtt5AuthException(final @NotNull Mqtt5Auth auth, final @NotNull String m this.auth = auth; } + private Mqtt5AuthException(final @NotNull Mqtt5AuthException e) { + super(e); + auth = e.auth; + } + + @Override + protected @NotNull Mqtt5AuthException copy() { + return new Mqtt5AuthException(this); + } + @Override public @NotNull Mqtt5Auth getMqttMessage() { return auth; diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5ConnAckException.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5ConnAckException.java index 09d8ba2ec..574aa5182 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5ConnAckException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5ConnAckException.java @@ -33,6 +33,16 @@ public Mqtt5ConnAckException(final @NotNull Mqtt5ConnAck connAck, final @NotNull this.connAck = connAck; } + private Mqtt5ConnAckException(final @NotNull Mqtt5ConnAckException e) { + super(e); + connAck = e.connAck; + } + + @Override + protected @NotNull Mqtt5ConnAckException copy() { + return new Mqtt5ConnAckException(this); + } + @Override public @NotNull Mqtt5ConnAck getMqttMessage() { return connAck; diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5DisconnectException.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5DisconnectException.java index 793434863..65ae38cba 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5DisconnectException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5DisconnectException.java @@ -38,6 +38,16 @@ public Mqtt5DisconnectException(final @NotNull Mqtt5Disconnect disconnect, final this.disconnect = disconnect; } + private Mqtt5DisconnectException(final @NotNull Mqtt5DisconnectException e) { + super(e); + disconnect = e.disconnect; + } + + @Override + protected @NotNull Mqtt5DisconnectException copy() { + return new Mqtt5DisconnectException(this); + } + @Override public @NotNull Mqtt5Disconnect getMqttMessage() { return disconnect; diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5MessageException.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5MessageException.java index 926bef9be..f14795335 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5MessageException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5MessageException.java @@ -35,5 +35,9 @@ public abstract class Mqtt5MessageException extends AsyncRuntimeException { super(cause.getMessage(), cause); } + Mqtt5MessageException(final @NotNull Mqtt5MessageException e) { + super(e); + } + public abstract @NotNull Mqtt5Message getMqttMessage(); } diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5PubAckException.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5PubAckException.java index 005f6bf34..878ee2d61 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5PubAckException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5PubAckException.java @@ -33,6 +33,16 @@ public Mqtt5PubAckException(final @NotNull Mqtt5PubAck pubAck, final @NotNull St this.pubAck = pubAck; } + private Mqtt5PubAckException(final @NotNull Mqtt5PubAckException e) { + super(e); + pubAck = e.pubAck; + } + + @Override + protected @NotNull Mqtt5PubAckException copy() { + return new Mqtt5PubAckException(this); + } + @Override public @NotNull Mqtt5PubAck getMqttMessage() { return pubAck; diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5PubRecException.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5PubRecException.java index 287bc1a6e..bb959220c 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5PubRecException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5PubRecException.java @@ -33,6 +33,16 @@ public Mqtt5PubRecException(final @NotNull Mqtt5PubRec pubRec, final @NotNull St this.pubRec = pubRec; } + private Mqtt5PubRecException(final @NotNull Mqtt5PubRecException e) { + super(e); + pubRec = e.pubRec; + } + + @Override + protected @NotNull Mqtt5PubRecException copy() { + return new Mqtt5PubRecException(this); + } + @Override public @NotNull Mqtt5PubRec getMqttMessage() { return pubRec; diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5SubAckException.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5SubAckException.java index ddc4d2265..b6ecf7ff3 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5SubAckException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5SubAckException.java @@ -33,6 +33,16 @@ public Mqtt5SubAckException(final @NotNull Mqtt5SubAck subAck, final @NotNull St this.subAck = subAck; } + private Mqtt5SubAckException(final @NotNull Mqtt5SubAckException e) { + super(e); + subAck = e.subAck; + } + + @Override + protected @NotNull Mqtt5SubAckException copy() { + return new Mqtt5SubAckException(this); + } + @Override public @NotNull Mqtt5SubAck getMqttMessage() { return subAck; diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5UnsubAckException.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5UnsubAckException.java index 83f4934c9..f731d9c1b 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5UnsubAckException.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/exceptions/Mqtt5UnsubAckException.java @@ -33,6 +33,16 @@ public Mqtt5UnsubAckException(final @NotNull Mqtt5UnsubAck unsubAck, final @NotN this.unsubAck = unsubAck; } + private Mqtt5UnsubAckException(final @NotNull Mqtt5UnsubAckException e) { + super(e); + unsubAck = e.unsubAck; + } + + @Override + protected @NotNull Mqtt5UnsubAckException copy() { + return new Mqtt5UnsubAckException(this); + } + @Override public @NotNull Mqtt5UnsubAck getMqttMessage() { return unsubAck;