Skip to content

Commit a73d3f1

Browse files
committed
Drop MiscUtils.trimStackTrace in favor of Netty's ThrowableUtil.unknownStackTrace
1 parent 14cc500 commit a73d3f1

File tree

6 files changed

+27
-25
lines changed

6 files changed

+27
-25
lines changed

client/src/main/java/org/asynchttpclient/exception/ChannelClosedException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
import java.io.IOException;
1616

17-
import static org.asynchttpclient.util.MiscUtils.trimStackTrace;
17+
import static io.netty.util.internal.ThrowableUtil.*;
1818

1919
@SuppressWarnings("serial")
2020
public final class ChannelClosedException extends IOException {
2121

22-
public static final ChannelClosedException INSTANCE = trimStackTrace(new ChannelClosedException());
22+
public static final ChannelClosedException INSTANCE = unknownStackTrace(new ChannelClosedException(), ChannelClosedException.class, "INSTANCE");
2323

2424
private ChannelClosedException() {
2525
super("Channel closed");

client/src/main/java/org/asynchttpclient/exception/PoolAlreadyClosedException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
*/
1313
package org.asynchttpclient.exception;
1414

15-
import java.io.IOException;
15+
import static io.netty.util.internal.ThrowableUtil.unknownStackTrace;
1616

17-
import static org.asynchttpclient.util.MiscUtils.trimStackTrace;
17+
import java.io.IOException;
1818

1919
@SuppressWarnings("serial")
2020
public class PoolAlreadyClosedException extends IOException {
2121

22-
public static final PoolAlreadyClosedException INSTANCE = trimStackTrace(new PoolAlreadyClosedException());
22+
public static final PoolAlreadyClosedException INSTANCE = unknownStackTrace(new PoolAlreadyClosedException(), PoolAlreadyClosedException.class, "INSTANCE");
2323

2424
private PoolAlreadyClosedException() {
2525
super("Pool is already closed");

client/src/main/java/org/asynchttpclient/exception/RemotelyClosedException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
*/
1313
package org.asynchttpclient.exception;
1414

15-
import java.io.IOException;
15+
import static io.netty.util.internal.ThrowableUtil.unknownStackTrace;
1616

17-
import static org.asynchttpclient.util.MiscUtils.trimStackTrace;
17+
import java.io.IOException;
1818

1919
@SuppressWarnings("serial")
2020
public final class RemotelyClosedException extends IOException {
2121

22-
public static final RemotelyClosedException INSTANCE = trimStackTrace(new RemotelyClosedException());
23-
22+
public static final RemotelyClosedException INSTANCE = unknownStackTrace(new RemotelyClosedException(), RemotelyClosedException.class, "INSTANCE");
23+
2424
public RemotelyClosedException() {
2525
super("Remotely closed");
2626
}

client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
package org.asynchttpclient.netty.channel;
1515

16-
import static org.asynchttpclient.util.MiscUtils.trimStackTrace;
16+
import static io.netty.util.internal.ThrowableUtil.unknownStackTrace;
1717
import io.netty.bootstrap.Bootstrap;
1818
import io.netty.buffer.ByteBufAllocator;
1919
import io.netty.channel.Channel;
@@ -53,16 +53,20 @@
5353
import javax.net.ssl.SSLEngine;
5454
import javax.net.ssl.SSLException;
5555

56-
import org.asynchttpclient.*;
56+
import org.asynchttpclient.AsyncHandler;
57+
import org.asynchttpclient.AsyncHttpClientConfig;
58+
import org.asynchttpclient.ClientStats;
59+
import org.asynchttpclient.HostStats;
60+
import org.asynchttpclient.SslEngineFactory;
5761
import org.asynchttpclient.channel.ChannelPool;
5862
import org.asynchttpclient.channel.ChannelPoolPartitioning;
5963
import org.asynchttpclient.channel.NoopChannelPool;
6064
import org.asynchttpclient.exception.PoolAlreadyClosedException;
6165
import org.asynchttpclient.exception.TooManyConnectionsException;
6266
import org.asynchttpclient.exception.TooManyConnectionsPerHostException;
6367
import org.asynchttpclient.handler.AsyncHandlerExtensions;
64-
import org.asynchttpclient.netty.OnLastHttpContentCallback;
6568
import org.asynchttpclient.netty.NettyResponseFuture;
69+
import org.asynchttpclient.netty.OnLastHttpContentCallback;
6670
import org.asynchttpclient.netty.handler.AsyncHttpClientHandler;
6771
import org.asynchttpclient.netty.handler.HttpHandler;
6872
import org.asynchttpclient.netty.handler.WebSocketHandler;
@@ -129,8 +133,9 @@ public ChannelManager(final AsyncHttpClientConfig config, Timer nettyTimer) {
129133
}
130134
this.channelPool = channelPool;
131135

132-
tooManyConnections = trimStackTrace(new TooManyConnectionsException(config.getMaxConnections()));
133-
tooManyConnectionsPerHost = trimStackTrace(new TooManyConnectionsPerHostException(config.getMaxConnectionsPerHost()));
136+
137+
tooManyConnections = unknownStackTrace(new TooManyConnectionsException(config.getMaxConnections()), ChannelManager.class, "acquireChannelLock");
138+
tooManyConnectionsPerHost = unknownStackTrace(new TooManyConnectionsPerHostException(config.getMaxConnectionsPerHost()), ChannelManager.class, "acquireChannelLock");
134139
maxTotalConnectionsEnabled = config.getMaxConnections() > 0;
135140
maxConnectionsPerHostEnabled = config.getMaxConnectionsPerHost() > 0;
136141

client/src/main/java/org/asynchttpclient/netty/handler/intercept/Redirect30xInterceptor.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
package org.asynchttpclient.netty.handler.intercept;
1515

1616
import static io.netty.handler.codec.http.HttpHeaderNames.*;
17+
import static io.netty.util.internal.ThrowableUtil.unknownStackTrace;
1718
import static org.asynchttpclient.util.HttpConstants.Methods.GET;
1819
import static org.asynchttpclient.util.HttpConstants.ResponseStatusCodes.*;
1920
import static org.asynchttpclient.util.HttpUtils.*;
20-
import static org.asynchttpclient.util.MiscUtils.*;
21+
import static org.asynchttpclient.util.MiscUtils.isNonEmpty;
2122
import io.netty.channel.Channel;
2223
import io.netty.handler.codec.http.HttpHeaders;
2324
import io.netty.handler.codec.http.HttpResponse;
@@ -50,21 +51,22 @@ public class Redirect30xInterceptor {
5051
REDIRECT_STATUSES.add(SEE_OTHER_303);
5152
REDIRECT_STATUSES.add(TEMPORARY_REDIRECT_307);
5253
}
53-
54+
5455
private static final Logger LOGGER = LoggerFactory.getLogger(Redirect30xInterceptor.class);
5556

5657
private final ChannelManager channelManager;
5758
private final AsyncHttpClientConfig config;
5859
private final NettyRequestSender requestSender;
5960
private final MaxRedirectException maxRedirectException;
60-
61+
6162
public Redirect30xInterceptor(ChannelManager channelManager, AsyncHttpClientConfig config, NettyRequestSender requestSender) {
6263
this.channelManager = channelManager;
6364
this.config = config;
6465
this.requestSender = requestSender;
65-
maxRedirectException = trimStackTrace(new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects()));
66+
maxRedirectException = unknownStackTrace(new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects()), Redirect30xInterceptor.class,
67+
"exitAfterHandlingRedirect");
6668
}
67-
69+
6870
public boolean exitAfterHandlingRedirect(//
6971
Channel channel,//
7072
NettyResponseFuture<?> future,//
@@ -164,7 +166,7 @@ else if (request.getBodyGenerator() != null)
164166
}
165167
return false;
166168
}
167-
169+
168170
private HttpHeaders propagatedHeaders(Request request, Realm realm, boolean keepBody) {
169171

170172
HttpHeaders headers = request.getHeaders()//

client/src/main/java/org/asynchttpclient/util/MiscUtils.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ public static void closeSilently(Closeable closeable) {
5959
}
6060
}
6161

62-
public static <T extends Exception> T trimStackTrace(T e) {
63-
e.setStackTrace(new StackTraceElement[] {});
64-
return e;
65-
}
66-
6762
public static Throwable getCause(Throwable t) {
6863
Throwable cause = t.getCause();
6964
return cause != null ? getCause(cause) : t;

0 commit comments

Comments
 (0)