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

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

commit 18909f190c320226479ad04a4cad9ec7cb30493b
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Jun 23 13:49:44 2023 -0400

    [juneau-rest-server] Throw IllegalArgumentException instead of
    RuntimeException
---
 .../src/main/java/org/apache/juneau/rest/RestContext.java           | 6 ++----
 .../org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java | 4 ++--
 .../src/main/java/org/apache/juneau/rest/util/UrlPath.java          | 2 +-
 .../java/org/apache/juneau/rest/vars/SerializedRequestAttrVar.java  | 2 +-
 .../src/main/java/org/apache/juneau/rest/widget/Widget.java         | 2 +-
 5 files changed, 7 insertions(+), 9 deletions(-)

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 3103360c2..77e297746 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
@@ -447,9 +447,7 @@ public class RestContext extends Context {
                 * @return The REST servlet/bean instance that this context is 
defined against.
                 */
                public Supplier<?> resource() {
-                       if (resource == null)
-                               throw new RuntimeException("Resource not 
available.  init(Object) has not been called.");
-                       return resource;
+                       return Objects.requireNonNull(resource, "Resource not 
available. init(Object) has not been called.");
                }
 
                /**
@@ -928,7 +926,7 @@ public class RestContext extends Context {
                        Value<Config> v = Value.empty();
 
                        // Find our config file.  It's the last non-empty 
@RestResource(config).
-                       VarResolver vr = 
beanStore.getBean(VarResolver.class).orElseThrow(()->new 
RuntimeException("VarResolver not found."));
+                       VarResolver vr = 
beanStore.getBean(VarResolver.class).orElseThrow(() -> new 
IllegalArgumentException("VarResolver not found."));
                        Value<String> cfv = Value.empty();
                        
ClassInfo.of(resourceClass).forEachAnnotation(Rest.class, x -> 
isNotEmpty(x.config()), x -> cfv.set(vr.resolve(x.config())));
                        String cf = cfv.orElse("");
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
index 23bc7f576..a81f80335 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/swagger/BasicSwaggerProviderSession.java
@@ -970,7 +970,7 @@ public class BasicSwaggerProviderSession {
                                .appendIf(ne, "$ref", a.$ref())
                        ;
                } catch (ParseException e) {
-                       throw new RuntimeException(e);
+                       throw new IllegalArgumentException(e);
                }
        }
 
@@ -1068,7 +1068,7 @@ public class BasicSwaggerProviderSession {
                for (Header aa : a) {
                        String name = StringUtils.firstNonEmpty(aa.name(), 
aa.value());
                        if (isEmpty(name))
-                               throw new RuntimeException("@Header used 
without name or value.");
+                               throw new IllegalArgumentException("@Header 
used without name or value.");
                        merge(om.getMap(name, true), aa.schema());
                }
                return om;
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/UrlPath.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/UrlPath.java
index 471759aff..50161ebe3 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/UrlPath.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/UrlPath.java
@@ -37,7 +37,7 @@ public class UrlPath {
         */
        public static UrlPath of(String path) {
                if (path != null && ! path.startsWith("/"))
-                       throw new RuntimeException("Invalid path specified.  
Must be null or start with '/' per HttpServletRequest.getPathInfo().");
+                       throw new IllegalArgumentException("Invalid path 
specified. Must be null or start with '/' per 
HttpServletRequest.getPathInfo().");
                return new UrlPath(path);
        }
 
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/SerializedRequestAttrVar.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/SerializedRequestAttrVar.java
index 4a8fc4376..e7d98eff6 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/SerializedRequestAttrVar.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/SerializedRequestAttrVar.java
@@ -54,7 +54,7 @@ public class SerializedRequestAttrVar extends StreamedVar {
        public void resolveTo(VarResolverSession session, Writer w, String key) 
throws Exception {
                int i = key.indexOf(',');
                if (i == -1)
-                       throw new RuntimeException("Invalid format for $SA var. 
 Must be of the format $SA{contentType,key[,defaultValue]}");
+                       throw new IllegalArgumentException("Invalid format for 
$SA var. Must be of the format $SA{contentType,key[,defaultValue]}");
                String[] s2 = split(key);
                RestRequest req = 
session.getBean(RestRequest.class).orElseThrow(InternalServerError::new);
                Object o = req.getAttribute(key).orElse(key);
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/Widget.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/Widget.java
index 613ab3113..8790afa17 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/Widget.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/Widget.java
@@ -153,7 +153,7 @@ public abstract class Widget implements HtmlWidget {
                                s = s.replaceAll("(?s)\\/\\*(.*?)\\*\\/\\s*", 
"");
                        return s;
                } catch (IOException e) {
-                       throw new RuntimeException(e);
+                       throw new UncheckedIOException(e);
                }
        }
 

Reply via email to