This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch jbFixRestNpe
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/jbFixRestNpe by this push:
     new d91f55461 Clean up exception handling in REST server.
d91f55461 is described below

commit d91f55461b1b5fa78a9dd87d50b39b1f232f1c6b
Author: JamesBognar <[email protected]>
AuthorDate: Sun Aug 14 12:53:03 2022 -0400

    Clean up exception handling in REST server.
---
 .../apache/juneau/rest/HttpRuntimeException.java   | 121 ---------------------
 .../java/org/apache/juneau/rest/RestContext.java   | 110 +++++++------------
 .../java/org/apache/juneau/rest/RestOpContext.java |   5 +-
 .../java/org/apache/juneau/rest/RestOpInvoker.java |  15 +--
 .../java/org/apache/juneau/rest/RestRequest.java   |   1 -
 .../apache/juneau/rest/converter/Traversable.java  |   4 +-
 .../apache/juneau/rest/debug/DebugEnablement.java  |   4 +-
 .../apache/juneau/rest/rrpc/RrpcRestOpSession.java |   6 +-
 .../apache/juneau/rest/servlet/RestServlet.java    |  18 +--
 .../juneau/rest/swagger/SwaggerProvider.java       |   4 +-
 .../apache/juneau/rest/vars/RequestSwaggerVar.java |   4 +-
 11 files changed, 59 insertions(+), 233 deletions(-)

diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/HttpRuntimeException.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/HttpRuntimeException.java
deleted file mode 100644
index 1f346135e..000000000
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/HttpRuntimeException.java
+++ /dev/null
@@ -1,121 +0,0 @@
-// 
***************************************************************************************************************************
-// * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements.  See the NOTICE file *
-// * distributed with this work for additional information regarding copyright 
ownership.  The ASF licenses this file        *
-// * to you under the Apache License, Version 2.0 (the "License"); you may not 
use this file except in compliance            *
-// * with the License.  You may obtain a copy of the License at                
                                              *
-// *                                                                           
                                              *
-// *  http://www.apache.org/licenses/LICENSE-2.0                               
                                              *
-// *                                                                           
                                              *
-// * Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an  *
-// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
express or implied.  See the License for the        *
-// * specific language governing permissions and limitations under the 
License.                                              *
-// 
***************************************************************************************************************************
-package org.apache.juneau.rest;
-
-import java.lang.reflect.*;
-
-import org.apache.juneau.*;
-import org.apache.juneau.http.annotation.*;
-import org.apache.juneau.http.response.*;
-import org.apache.juneau.parser.*;
-import org.apache.juneau.reflect.*;
-
-/**
- * A {@link RuntimeException} meant to wrap a non-{@link RuntimeException}.
- *
- * <ul class='seealso'>
- *     <li class='link'>{@doc jrs.LoggingAndDebugging}
- *     <li class='extlink'>{@source}
- * </ul>
- *
- * @serial exclude
- */
-public final class HttpRuntimeException extends BasicRuntimeException {
-       private static final long serialVersionUID = 1L;
-
-       final Throwable t;
-
-       /**
-        * Constructor.
-        *
-        * @param t Wrapped exception.
-        */
-       public HttpRuntimeException(Throwable t) {
-               super(t, t == null ? "" : t.getMessage());
-               this.t = t;
-       }
-
-       /**
-        * Returns the wrapped throwable.
-        *
-        * @return The wrapped throwable.
-        */
-       public Throwable getInner() {
-               return t;
-       }
-
-       /**
-        * Takes in an arbitrary {@link Throwable} and converts it to an 
appropriate runtime exception for producing an
-        * HTTP response.
-        *
-        * @param t The throwable to wrap.
-        * @param ec The exception class to create if the specified throwable 
cannot produce a valid HTTP response.
-        * @return RuntimeException The new exception to throw.
-        */
-       public static RuntimeException toHttpException(Throwable t, Class<?> 
ec) {
-               return toHttpException(t, ec, null);
-       }
-
-       /**
-        * Takes in an arbitrary {@link Throwable} and converts it to an 
appropriate runtime exception for producing an
-        * HTTP response.
-        *
-        * @param t The throwable to wrap.
-        * @param ec The exception class to create if the specified throwable 
cannot produce a valid HTTP response.
-        * @param msg The message text to pass to the ec class constructor.
-        * @param args The message arguments to pass to the ec class 
constructor.
-        * @return RuntimeException The new exception to throw.
-        */
-       public static RuntimeException toHttpException(Throwable t, Class<?> 
ec, String msg, Object...args) {
-
-               if (t instanceof InvocationTargetException)
-                       t = ((InvocationTargetException)t).getCause();
-
-               if (t instanceof ExecutableException)
-                       t = ((ExecutableException)t).getTargetException();
-
-               if (t instanceof ParseException)
-                       throw new BadRequest(t);
-
-               ClassInfo ci = ClassInfo.of(t);
-
-               // If it's any RuntimeException annotated with @Response, it 
can be rethrown.
-               if (ci.isRuntimeException()) {
-                       if (ci.hasAnnotation(Response.class) || 
ci.isChildOf(BasicHttpException.class))
-                               return (RuntimeException)t;
-               }
-
-               // If it's a non-RuntimeException but annotated with @Response, 
it can be wrapped and rethrown.
-               if (ci.hasAnnotation(Response.class))
-                       return new HttpRuntimeException(t);
-
-               if (ec == null)
-                       ec = InternalServerError.class;
-               ClassInfo eci = ClassInfo.of(ec);
-
-               try {
-                       ConstructorInfo cci = eci.getPublicConstructor(x -> 
x.hasParamTypes(Throwable.class, String.class, Object[].class));
-                       if (cci != null)
-                               return toHttpException((Throwable)cci.invoke(t, 
msg, args), InternalServerError.class);
-
-                       cci = eci.getPublicConstructor(x -> 
x.hasParamTypes(Throwable.class));
-                       if (cci != null)
-                               return 
toHttpException((Throwable)cci.invoke(t), InternalServerError.class);
-
-                       System.err.println("WARNING:  Class '"+ec+"' does not 
have a public constructor that takes in valid arguments.");
-                       return new InternalServerError(t);
-               } catch (ExecutableException e) {
-                       throw new InternalServerError(e.getCause());
-               }
-       }
-}
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index 5c9fbd567..2edf6f153 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -19,7 +19,6 @@ import static org.apache.juneau.internal.ClassUtils.*;
 import static org.apache.juneau.internal.CollectionUtils.*;
 import static org.apache.juneau.internal.IOUtils.*;
 import static org.apache.juneau.internal.StringUtils.*;
-import static org.apache.juneau.rest.HttpRuntimeException.*;
 import static org.apache.juneau.rest.processor.ResponseProcessor.*;
 import static java.util.Collections.*;
 import static java.util.Optional.*;
@@ -51,7 +50,6 @@ import org.apache.juneau.encoders.*;
 import org.apache.juneau.html.*;
 import org.apache.juneau.html.annotation.*;
 import org.apache.juneau.httppart.*;
-import org.apache.juneau.httppart.bean.*;
 import org.apache.juneau.internal.*;
 import org.apache.juneau.jsonschema.*;
 import org.apache.juneau.oapi.*;
@@ -5416,7 +5414,6 @@ public class RestContext extends Context {
        private final ThrownStore thrownStore;
        private final ConcurrentHashMap<Locale,Swagger> swaggerCache = new 
ConcurrentHashMap<>();
        private final Instant startTime;
-       private final Map<Class<?>,ResponseBeanMeta> responseBeanMetas = new 
ConcurrentHashMap<>();
        final Charset defaultCharset;
        final long maxInput;
 
@@ -6205,7 +6202,7 @@ public class RestContext extends Context {
                                if (s != null)
                                        swaggerCache.put(locale, s);
                        } catch (Exception e) {
-                               throw toHttpException(e, 
InternalServerError.class);
+                               throw new InternalServerError(e);
                        }
                }
                return optional(s);
@@ -6334,7 +6331,7 @@ public class RestContext extends Context {
                        }
 
                } catch (Throwable e) {
-                       handleError(sb.build(), convertThrowable(e, 
InternalServerError.class));
+                       handleError(sb.build(), convertThrowable(e));
                }
 
                RestSession s = sb.build();
@@ -6345,7 +6342,7 @@ public class RestContext extends Context {
                        startCall(s);
                        s.run();
                } catch (Throwable e) {
-                       handleError(s, convertThrowable(e, 
InternalServerError.class));
+                       handleError(s, convertThrowable(e));
                } finally {
                        try {
                                s.finish();
@@ -6418,27 +6415,20 @@ public class RestContext extends Context {
         * </ul>
         *
         * @param t The thrown object.
-        * @param defaultThrowable The default throwable class to create.
         * @return The converted thrown object.
         */
-       public Throwable convertThrowable(Throwable t, Class<?> 
defaultThrowable) {
+       protected Throwable convertThrowable(Throwable t) {
 
-               ClassInfo ci = ClassInfo.of(t);
-
-               if (ci.is(InvocationTargetException.class)) {
+               if (t instanceof InvocationTargetException)
                        t = ((InvocationTargetException)t).getTargetException();
-                       ci = ClassInfo.of(t);
-               }
 
-               if (ci.is(HttpRuntimeException.class)) {
-                       t = ((HttpRuntimeException)t).getInner();
-                       ci = ClassInfo.of(t);
-               }
-
-               if (ci.is(ExecutableException.class)) {
+               if (t instanceof ExecutableException)
                        t = ((ExecutableException)t).getTargetException();
-                       ci = ClassInfo.of(t);
-               }
+
+               if (t instanceof BasicHttpException)
+                       return t;
+
+               ClassInfo ci = ClassInfo.of(t);
 
                if (ci.hasAnnotation(Response.class))
                        return t;
@@ -6454,25 +6444,7 @@ public class RestContext extends Context {
                if (n.contains("Empty") || n.contains("NotFound"))
                        return new NotFound(t);
 
-               if (defaultThrowable == null)
-                       return new InternalServerError(t);
-
-               ClassInfo eci = ClassInfo.of(defaultThrowable);
-
-               try {
-                       ConstructorInfo cci = eci.getPublicConstructor(x -> 
x.hasParamTypes(Throwable.class, String.class, Object[].class));
-                       if (cci != null)
-                               return toHttpException((Throwable)cci.invoke(t, 
t.getMessage(), new Object[0]), InternalServerError.class);
-
-                       cci = eci.getPublicConstructor(x -> 
x.hasParamTypes(Throwable.class));
-                       if (cci != null)
-                               return 
toHttpException((Throwable)cci.invoke(t), InternalServerError.class);
-
-                       System.err.println("WARNING:  Class '"+eci+"' does not 
have a public constructor that takes in valid arguments.");
-                       return new InternalServerError(t);
-               } catch (ExecutableException e) {
-                       return new InternalServerError(e.getCause());
-               }
+               return t;
        }
 
        /**
@@ -6530,11 +6502,7 @@ public class RestContext extends Context {
                HttpServletRequest req = session.getRequest();
                HttpServletResponse res = session.getResponse();
 
-               Throwable t = null;
-               if (e instanceof HttpRuntimeException)
-                       t = ((HttpRuntimeException)e).getInner();
-               if (t == null)
-                       t = e2.getRootCause();
+               Throwable t = e2.getRootCause();
                if (t != null) {
                        Thrown t2 = thrown(t);
                        res.setHeader(t2.getName(), t2.getValue());
@@ -6581,7 +6549,10 @@ public class RestContext extends Context {
                        } catch 
(IllegalAccessException|IllegalArgumentException e) {
                                throw 
InternalServerError.create().message("Error occurred invoking start-call method 
''{0}''.", x.getFullName()).causedBy(e).build();
                        } catch (InvocationTargetException e) {
-                               throw toHttpException(e.getTargetException(), 
InternalServerError.class);
+                               Throwable t = e.getTargetException();
+                               if (t instanceof BasicHttpException)
+                                       throw (BasicHttpException)t;
+                               throw new InternalServerError(t);
                        }
                }
        }
@@ -6707,28 +6678,28 @@ public class RestContext extends Context {
                return rc;
        }
 
-       /**
-        * If the specified object is annotated with {@link Response}, this 
returns the response metadata about that object.
-        *
-        * @param o The object to check.
-        * @return The response metadata, or <jk>null</jk> if it wasn't 
annotated with {@link Response}.
-        */
-       public ResponseBeanMeta getResponseBeanMeta(Object o) {
-               if (o == null)
-                       return null;
-               Class<?> c = o.getClass();
-               ResponseBeanMeta rbm = responseBeanMetas.get(c);
-               if (rbm == null) {
-                       rbm = ResponseBeanMeta.create(c, getAnnotations());
-                       if (rbm == null)
-                               rbm = ResponseBeanMeta.NULL;
-                       responseBeanMetas.put(c, rbm);
-               }
-               if (rbm == ResponseBeanMeta.NULL)
-                       return null;
-               return rbm;
-       }
-
+//     /**
+//      * If the specified object is annotated with {@link Response}, this 
returns the response metadata about that object.
+//      *
+//      * @param o The object to check.
+//      * @return The response metadata, or <jk>null</jk> if it wasn't 
annotated with {@link Response}.
+//      */
+//     public ResponseBeanMeta getResponseBeanMeta(Object o) {
+//             if (o == null)
+//                     return null;
+//             Class<?> c = o.getClass();
+//             ResponseBeanMeta rbm = responseBeanMetas.get(c);
+//             if (rbm == null) {
+//                     rbm = ResponseBeanMeta.create(c, getAnnotations());
+//                     if (rbm == null)
+//                             rbm = ResponseBeanMeta.NULL;
+//                     responseBeanMetas.put(c, rbm);
+//             }
+//             if (rbm == ResponseBeanMeta.NULL)
+//                     return null;
+//             return rbm;
+//     }
+//
        /**
         * Returns the annotations applied to this context.
         *
@@ -6738,6 +6709,9 @@ public class RestContext extends Context {
                return builder.getApplied();
        }
 
+
+
+
        
//-----------------------------------------------------------------------------------------------------------------
        // Helper methods
        
//-----------------------------------------------------------------------------------------------------------------
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
index c7c8b09b9..853365ce7 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpContext.java
@@ -21,7 +21,6 @@ import static org.apache.juneau.collections.JsonMap.*;
 import static org.apache.juneau.http.HttpHeaders.*;
 import static org.apache.juneau.http.HttpParts.*;
 import static org.apache.juneau.httppart.HttpPartType.*;
-import static org.apache.juneau.rest.HttpRuntimeException.*;
 import static org.apache.juneau.rest.util.RestUtils.*;
 import java.lang.annotation.*;
 import java.lang.reflect.Method;
@@ -146,7 +145,7 @@ public class RestOpContext extends Context implements 
Comparable<RestOpContext>
                        try {
                                return 
beanStore.createBean(RestOpContext.class).type(getType().orElse(getDefaultImplClass())).builder(RestOpContext.Builder.class,
 this).run();
                        } catch (Exception e) {
-                               throw toHttpException(e, 
InternalServerError.class);
+                               throw new InternalServerError(e);
                        }
                }
 
@@ -195,7 +194,7 @@ public class RestOpContext extends Context implements 
Comparable<RestOpContext>
                                processParameterAnnotations();
 
                        } catch (Exception e) {
-                               throw toHttpException(e, 
InternalServerError.class);
+                               throw new InternalServerError(e);
                        }
                }
 
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpInvoker.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpInvoker.java
index 4c987646f..5f03bd864 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpInvoker.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOpInvoker.java
@@ -12,12 +12,8 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau.rest;
 
-import static org.apache.juneau.rest.HttpRuntimeException.*;
-
 import java.lang.reflect.*;
 
-import org.apache.http.*;
-import org.apache.juneau.http.annotation.*;
 import org.apache.juneau.http.response.*;
 import org.apache.juneau.reflect.*;
 import org.apache.juneau.rest.arg.*;
@@ -59,8 +55,10 @@ public class RestOpInvoker extends MethodInvoker {
                        ParamInfo pi = inner().getParam(i);
                        try {
                                args[i] = opArgs[i].resolve(opSession);
+                       } catch (BasicHttpException e) {
+                               throw e;
                        } catch (Exception e) {
-                               throw toHttpException(e, BadRequest.class, 
"Could not resolve parameter {0} of type ''{1}'' on method ''{2}''.", i, 
pi.getParameterType(), getFullName());
+                               throw new BadRequest(e, "Could not resolve 
parameter {0} of type ''{1}'' on method ''{2}''.", i, pi.getParameterType(), 
getFullName());
                        }
                }
                try {
@@ -88,12 +86,7 @@ public class RestOpInvoker extends MethodInvoker {
                        RestResponse res = opSession.getResponse();
                        Throwable e2 = e.getTargetException();
                        res.setStatus(500);  // May be overridden later.
-                       Class<?> c = e2.getClass();
-                       if (e2 instanceof HttpResponse || 
c.getAnnotation(Response.class) != null || c.getAnnotation(Content.class) != 
null) {
-                               res.setContent(e2);
-                       } else {
-                               throw toHttpException(e2, 
InternalServerError.class, "Method ''{0}'' threw an unexpected exception.", 
getFullName());
-                       }
+                       
res.setContent(opSession.getRestContext().convertThrowable(e2));
                }
        }
 }
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
index c5d52fb35..130c69ac5 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
@@ -21,7 +21,6 @@ import static org.apache.juneau.internal.ThrowableUtils.*;
 import static org.apache.juneau.internal.CollectionUtils.*;
 import static org.apache.juneau.internal.IOUtils.*;
 import static org.apache.juneau.serializer.Serializer.*;
-import static org.apache.juneau.rest.HttpRuntimeException.*;
 import static java.lang.Integer.*;
 import static java.util.Collections.*;
 import static java.util.Optional.*;
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/converter/Traversable.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/converter/Traversable.java
index 45cd1e8b9..646f42687 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/converter/Traversable.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/converter/Traversable.java
@@ -12,8 +12,6 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau.rest.converter;
 
-import static org.apache.juneau.rest.HttpRuntimeException.*;
-
 import org.apache.juneau.*;
 import org.apache.juneau.rest.*;
 import org.apache.juneau.swap.*;
@@ -65,7 +63,7 @@ public final class Traversable implements RestConverter {
                        } catch (ObjectRestException e) {
                                throw new BasicHttpException(e.getStatus(), e);
                        } catch (Throwable t) {
-                               throw toHttpException(t, 
InternalServerError.class);
+                               throw new InternalServerError(t);
                        }
                }
 
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/debug/DebugEnablement.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/debug/DebugEnablement.java
index a3cfa5bad..3a151f8ab 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/debug/DebugEnablement.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/debug/DebugEnablement.java
@@ -15,8 +15,6 @@ package org.apache.juneau.rest.debug;
 import static org.apache.juneau.Enablement.*;
 import static org.apache.juneau.collections.JsonMap.*;
 import static org.apache.juneau.internal.ObjectUtils.*;
-import static org.apache.juneau.rest.HttpRuntimeException.*;
-
 import java.lang.reflect.Method;
 import java.util.function.*;
 
@@ -101,7 +99,7 @@ public abstract class DebugEnablement {
                        try {
                                return creator.run();
                        } catch (Exception e) {
-                               throw toHttpException(e, 
InternalServerError.class);
+                               throw new InternalServerError(e);
                        }
                }
 
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/rrpc/RrpcRestOpSession.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/rrpc/RrpcRestOpSession.java
index 1a0e9fcca..517b11502 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/rrpc/RrpcRestOpSession.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/rrpc/RrpcRestOpSession.java
@@ -13,8 +13,6 @@
 package org.apache.juneau.rest.rrpc;
 
 import static org.apache.juneau.internal.StringUtils.*;
-import static org.apache.juneau.rest.HttpRuntimeException.*;
-
 import java.io.*;
 import java.lang.reflect.*;
 
@@ -134,8 +132,10 @@ public class RrpcRestOpSession extends RestOpSession {
                                        }
                                        res.setContent(m.invoke(o, args));
                                        return;
+                               } catch (BasicHttpException e) {
+                                       throw e;
                                } catch (Exception e) {
-                                       throw toHttpException(e, 
InternalServerError.class);
+                                       throw new InternalServerError(e);
                                }
                        }
                }
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/servlet/RestServlet.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/servlet/RestServlet.java
index d1d6dfcde..1c8312bf5 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/servlet/RestServlet.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/servlet/RestServlet.java
@@ -16,8 +16,6 @@ import static java.util.logging.Level.*;
 import static javax.servlet.http.HttpServletResponse.*;
 import static org.apache.juneau.internal.ClassUtils.*;
 import static org.apache.juneau.internal.StringUtils.*;
-import static org.apache.juneau.rest.HttpRuntimeException.*;
-
 import java.io.*;
 import java.text.*;
 import java.util.concurrent.atomic.*;
@@ -84,23 +82,15 @@ public abstract class RestServlet extends HttpServlet {
                        initException.set(e);
                        log(SEVERE, e, "Servlet init error on class ''{0}''", 
className(this));
                        throw e;
+               } catch (BasicHttpException e) {
+                       initException.set(e);
+                       log(SEVERE, e, "Servlet init error on class ''{0}''", 
className(this));
                } catch (Throwable e) {
-                       initException.set(toHttpException(e, 
InternalServerError.class));
+                       initException.set(new InternalServerError(e));
                        log(SEVERE, e, "Servlet init error on class ''{0}''", 
className(this));
                }
        }
 
-//     /**
-//      * Instantiates the bean store to use for creating beans for this 
servlet.
-//      *
-//      * @param parent The parent bean store.
-//      * @return A new bean store.
-//      */
-//     @Rest
-//     public BeanStore createBeanStore(Optional<BeanStore> parent) {
-//             return BeanStore.of(parent.orElse(null), this);
-//     }
-
        /**
         * Sets the context object for this servlet.
         *
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/SwaggerProvider.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/SwaggerProvider.java
index 02bf2f137..5c95fbbf0 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/SwaggerProvider.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/SwaggerProvider.java
@@ -13,8 +13,6 @@
 package org.apache.juneau.rest.swagger;
 
 import static org.apache.juneau.internal.CollectionUtils.*;
-import static org.apache.juneau.rest.HttpRuntimeException.*;
-
 import java.util.*;
 import java.util.function.*;
 
@@ -99,7 +97,7 @@ public interface SwaggerProvider {
                        try {
                                return creator.run();
                        } catch (Exception e) {
-                               throw toHttpException(e, 
InternalServerError.class);
+                               throw new InternalServerError(e);
                        }
                }
 
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/RequestSwaggerVar.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/RequestSwaggerVar.java
index 70bfb2ce6..f6662ef08 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/RequestSwaggerVar.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/RequestSwaggerVar.java
@@ -12,8 +12,6 @@
 // 
***************************************************************************************************************************
 package org.apache.juneau.rest.vars;
 
-import static org.apache.juneau.rest.HttpRuntimeException.*;
-
 import java.util.*;
 
 import org.apache.juneau.dto.swagger.*;
@@ -131,7 +129,7 @@ public class RequestSwaggerVar extends 
MultipartResolvingVar {
                        }
                        return null;
                } catch (Exception e) {
-                       throw toHttpException(e, InternalServerError.class);
+                       throw new InternalServerError(e);
                }
        }
 

Reply via email to