Skip to content

Commit 6164032

Browse files
authored
Fixes #13599 - Merge ConstantThrowable and StaticException (#13600)
Deprecated `StaticException` in favor of `ConstantThrowable`, because `StaticException` had a constructor that made it capture the stack trace, which was unnecessary and would have been deprecated. Signed-off-by: Simone Bordet <[email protected]>
1 parent 7c0ffb2 commit 6164032

File tree

12 files changed

+32
-22
lines changed

12 files changed

+32
-22
lines changed

jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPart.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
import org.eclipse.jetty.io.content.ByteBufferContentSource;
4343
import org.eclipse.jetty.io.content.ChunksContentSource;
4444
import org.eclipse.jetty.util.BufferUtil;
45+
import org.eclipse.jetty.util.ConstantThrowable;
4546
import org.eclipse.jetty.util.IO;
4647
import org.eclipse.jetty.util.QuotedStringTokenizer;
4748
import org.eclipse.jetty.util.SearchPattern;
48-
import org.eclipse.jetty.util.StaticException;
4949
import org.eclipse.jetty.util.StringUtil;
5050
import org.eclipse.jetty.util.TypeUtil;
5151
import org.eclipse.jetty.util.UrlEncoded;
@@ -183,7 +183,7 @@ public static String generateBoundary(String prefix, int randomLength)
183183
*/
184184
public abstract static class Part implements Content.Source.Factory, Closeable
185185
{
186-
static final Throwable CLOSE_EXCEPTION = new StaticException("Closed");
186+
static final Throwable CLOSE_EXCEPTION = new ConstantThrowable("Closed");
187187

188188
private final AutoLock lock = new AutoLock();
189189
private final ByteBufferPool.Sized bufferPool;

jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/content/ContentSourcePublisher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import java.util.concurrent.atomic.AtomicReference;
2020

2121
import org.eclipse.jetty.io.Content;
22+
import org.eclipse.jetty.util.ConstantThrowable;
2223
import org.eclipse.jetty.util.IteratingCallback;
2324
import org.eclipse.jetty.util.MathUtils;
24-
import org.eclipse.jetty.util.StaticException;
2525
import org.slf4j.Logger;
2626
import org.slf4j.LoggerFactory;
2727

@@ -130,7 +130,7 @@ public void cancel()
130130
private static final class ActiveSubscription extends IteratingCallback implements Flow.Subscription, Runnable
131131
{
132132
private static final long NO_MORE_DEMAND = -1;
133-
private static final Throwable COMPLETED = new StaticException("Source.Content read fully");
133+
private static final Throwable COMPLETED = new ConstantThrowable("Completed");
134134
private final AtomicReference<Throwable> cancelled;
135135
private final AtomicLong demand;
136136
private Content.Source content;

jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/HttpStream.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.eclipse.jetty.io.Content;
2222
import org.eclipse.jetty.io.Content.Chunk;
2323
import org.eclipse.jetty.util.Callback;
24-
import org.eclipse.jetty.util.StaticException;
24+
import org.eclipse.jetty.util.ConstantThrowable;
2525

2626
/**
2727
* A HttpStream is an abstraction that together with {@link MetaData.Request}, represents the
@@ -31,7 +31,7 @@
3131
*/
3232
public interface HttpStream extends Callback
3333
{
34-
Exception CONTENT_NOT_CONSUMED = new StaticException("Unconsumed request content");
34+
Throwable CONTENT_NOT_CONSUMED = new ConstantThrowable("Unconsumed");
3535

3636
/**
3737
* <p>Attribute name to be used as a {@link Request} attribute to store/retrieve

jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/HttpChannelTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ public boolean handle(Request request, Response response, Callback callback)
797797

798798
assertThat(stream.isComplete(), is(true));
799799
assertThat(stream.getFailure(), notNullValue());
800-
assertThat(stream.getFailure().getMessage(), containsString("Unconsumed request content"));
800+
assertThat(stream.getFailure().getMessage(), containsString("Unconsumed"));
801801
assertThat(stream.getResponse(), notNullValue());
802802
assertThat(stream.getResponse().getStatus(), equalTo(200));
803803
assertThat(stream.getResponseHeaders().get(HttpHeader.CONTENT_TYPE), equalTo(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()));

jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Blocker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
public class Blocker
7676
{
7777
private static final Logger LOG = LoggerFactory.getLogger(Blocker.class);
78-
private static final Throwable ACQUIRED = new StaticException("ACQUIRED");
79-
private static final Throwable SUCCEEDED = new StaticException("SUCCEEDED");
78+
private static final Throwable ACQUIRED = new ConstantThrowable("ACQUIRED");
79+
private static final Throwable SUCCEEDED = new ConstantThrowable("SUCCEEDED");
8080

8181
public interface Runnable extends java.lang.Runnable, AutoCloseable, Invocable
8282
{

jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ConstantThrowable.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414
package org.eclipse.jetty.util;
1515

1616
/**
17-
* A {@link Throwable} that may be used in static contexts. It uses Java 7
18-
* constructor that prevents setting stackTrace inside exception object.
17+
* <p>A {@link Throwable} that may be used in static contexts,
18+
* for example when stored as a {@code static} field.</p>
19+
* <p>Suppressed exceptions are disabled; adding a suppressed
20+
* exception has no effect, so that instances of this class
21+
* stored as {@code static} fields do not accumulate suppressed
22+
* exceptions.</p>
23+
* <p>The stack trace is also disabled, since it would only be
24+
* captured at the time this exception is created, not when the
25+
* failure actually occurs.</p>
1926
*/
2027
public class ConstantThrowable extends Throwable
2128
{

jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/StaticException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
* meaning calling {@link #addSuppressed(Throwable)} has no effect.
1919
* This prevents potential memory leaks where a statically-stored exception would accumulate
2020
* suppressed exceptions added to them.
21+
*
22+
* @deprecated use {@link ConstantThrowable} instead
2123
*/
24+
@Deprecated(since = "12.1.2", forRemoval = true)
2225
public class StaticException extends Exception
2326
{
2427
/**

jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/util/WebSocketDemander.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
import java.nio.channels.ReadPendingException;
1717

1818
import org.eclipse.jetty.util.Callback;
19+
import org.eclipse.jetty.util.ConstantThrowable;
1920
import org.eclipse.jetty.util.CountingCallback;
2021
import org.eclipse.jetty.util.ExceptionUtil;
2122
import org.eclipse.jetty.util.IteratingCallback;
22-
import org.eclipse.jetty.util.StaticException;
2323
import org.eclipse.jetty.util.thread.AutoLock;
2424
import org.eclipse.jetty.websocket.core.Extension;
2525
import org.eclipse.jetty.websocket.core.Frame;
@@ -39,7 +39,7 @@
3939
*/
4040
public abstract class WebSocketDemander extends IteratingCallback implements DemandChain
4141
{
42-
private static final Throwable SENTINEL_CLOSE_EXCEPTION = new StaticException("Closed");
42+
private static final Throwable SENTINEL_CLOSE_EXCEPTION = new ConstantThrowable("Closed");
4343

4444
private final AutoLock _lock = new AutoLock();
4545
private final IncomingFrames _emitFrame;

jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/util/WebSocketFlusher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import java.util.Queue;
2020

2121
import org.eclipse.jetty.util.Callback;
22+
import org.eclipse.jetty.util.ConstantThrowable;
2223
import org.eclipse.jetty.util.IteratingCallback;
23-
import org.eclipse.jetty.util.StaticException;
2424
import org.eclipse.jetty.util.thread.AutoLock;
2525
import org.eclipse.jetty.websocket.core.OutgoingEntry;
2626
import org.eclipse.jetty.websocket.core.OutgoingFrames;
@@ -35,7 +35,7 @@
3535
*/
3636
public abstract class WebSocketFlusher implements OutgoingFrames
3737
{
38-
private static final Throwable SENTINEL_CLOSE_EXCEPTION = new StaticException("Closed");
38+
private static final Throwable SENTINEL_CLOSE_EXCEPTION = new ConstantThrowable("Closed");
3939
private final Logger log = LoggerFactory.getLogger(this.getClass());
4040

4141
private final AutoLock _lock = new AutoLock();

jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/AsyncContentProducer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import org.eclipse.jetty.http.HttpStatus;
2121
import org.eclipse.jetty.http.Trailers;
2222
import org.eclipse.jetty.io.Content;
23+
import org.eclipse.jetty.util.ConstantThrowable;
2324
import org.eclipse.jetty.util.NanoTime;
24-
import org.eclipse.jetty.util.StaticException;
2525
import org.eclipse.jetty.util.TypeUtil;
2626
import org.eclipse.jetty.util.thread.AutoLock;
2727
import org.eclipse.jetty.util.thread.Invocable;
@@ -35,7 +35,7 @@
3535
class AsyncContentProducer implements ContentProducer
3636
{
3737
private static final Logger LOG = LoggerFactory.getLogger(AsyncContentProducer.class);
38-
private static final Content.Chunk RECYCLED_ERROR_CHUNK = Content.Chunk.from(new StaticException("ContentProducer has been recycled"), true);
38+
private static final Content.Chunk RECYCLED_ERROR_CHUNK = Content.Chunk.from(new ConstantThrowable("Recycled"), true);
3939

4040
final AutoLock _lock;
4141
private final ServletChannel _servletChannel;

0 commit comments

Comments
 (0)