Skip to content

Commit

Permalink
use an exception with suppressed exceptions disabled in static variab…
Browse files Browse the repository at this point in the history
…les.

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
  • Loading branch information
lorban committed Jun 10, 2022
1 parent c34483e commit e175625
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Expand Up @@ -19,6 +19,7 @@

import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.util.StaticException;
import org.eclipse.jetty.util.component.Destroyable;
import org.eclipse.jetty.util.thread.AutoLock;
import org.slf4j.Logger;
Expand All @@ -31,8 +32,8 @@
class AsyncContentProducer implements ContentProducer
{
private static final Logger LOG = LoggerFactory.getLogger(AsyncContentProducer.class);
private static final HttpInput.ErrorContent RECYCLED_ERROR_CONTENT = new HttpInput.ErrorContent(new IllegalStateException("ContentProducer has been recycled"));
private static final Throwable UNCONSUMED_CONTENT_EXCEPTION = new IOException("Unconsumed content")
private static final HttpInput.ErrorContent RECYCLED_ERROR_CONTENT = new HttpInput.ErrorContent(new StaticException("ContentProducer has been recycled"));
private static final Throwable UNCONSUMED_CONTENT_EXCEPTION = new StaticException("Unconsumed content")
{
@Override
public Throwable fillInStackTrace()
Expand Down Expand Up @@ -190,7 +191,7 @@ public boolean consumeAll()
Throwable x = UNCONSUMED_CONTENT_EXCEPTION;
if (LOG.isDebugEnabled())
{
x = new IOException("Unconsumed content");
x = new StaticException("Unconsumed content");
LOG.debug("consumeAll {}", this, x);
}
failCurrentContent(x);
Expand Down
@@ -0,0 +1,29 @@
//
// ========================================================================
// Copyright (c) 1995-2022 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//

package org.eclipse.jetty.util;

/**
* This exception can safely be stored in a static variable as suppressed exceptions are disabled,
* meaning calling {@link #addSuppressed(Throwable)} has no effect.
* This prevents potential memory leaks where a statically-stored exception would accumulate
* suppressed exceptions added to them.
*/
public class StaticException extends Exception
{
public StaticException(String message)
{
// Make sure to call the super constructor that disables suppressed exception.
super(message, null, false, true);
}
}

0 comments on commit e175625

Please sign in to comment.