You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by gg...@apache.org on 2023/06/23 17:50:57 UTC

[juneau] branch master updated (d1d4eb3fe -> ca352d8da)

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

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


    from d1d4eb3fe [juneau-dto] Throw IllegalArgumentException instead of RuntimeException
     new f030b36fa [juneau-rest-client] Throw a specialized RuntimeException instead of RuntimeException
     new afab8ae4d [juneau-rest-common] Throw a specialized RuntimeException instead of RuntimeException
     new d51d57d01 [juneau-rest-mock] Throw a specialized RuntimeException instead of RuntimeException
     new 98aa38fc8 [juneau-common] Throw IllegalArgumentException instead of RuntimeException
     new 6d1514eee [juneau-marshall] Throw IllegalArgumentException instead of RuntimeException
     new 6ea90f255 [juneau-examples-rest] Throw IllegalArgumentException instead of RuntimeException
     new fed265804 [juneau-examples-rest-ftest] Throw IllegalArgumentException instead of RuntimeException
     new c23e3bd2b [juneau-microservice-core] Throw IllegalArgumentException instead of RuntimeException
     new 18909f190 [juneau-rest-server] Throw IllegalArgumentException instead of RuntimeException
     new 880531a53 [juneau-microservice-jetty] Throw IllegalArgumentException instead of RuntimeException
     new ca352d8da [juneau-utest] Throw IllegalArgumentException instead of RuntimeException

The 11 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/juneau/common/internal/AsciiSet.java    |  2 +-
 .../juneau/common/internal/ThrowableUtils.java     |  2 +-
 .../main/java/org/apache/juneau/BeanBuilder.java   |  4 +--
 .../java/org/apache/juneau/BeanPropertyMeta.java   |  6 ++--
 .../apache/juneau/annotation/AnnotationImpl.java   |  2 +-
 .../org/apache/juneau/collections/JsonMap.java     |  2 +-
 .../main/java/org/apache/juneau/cp/BeanStore.java  |  4 +--
 .../org/apache/juneau/cp/ContextBeanCreator.java   |  2 +-
 .../org/apache/juneau/internal/ListBuilder.java    |  4 +--
 .../org/apache/juneau/internal/MapBuilder.java     |  4 +--
 .../org/apache/juneau/internal/SetBuilder.java     |  2 +-
 .../juneau/examples/rest/SamplesMicroservice.java  |  2 +-
 .../juneau/examples/rest/PhotosResource.java       |  2 +-
 .../juneau/examples/rest/dto/AtomFeedResource.java |  2 +-
 .../examples/rest/dto/JsonSchemaResource.java      |  2 +-
 .../juneau/microservice/resources/LogParser.java   |  2 +-
 .../jetty/BasicJettyServerFactory.java             |  4 +--
 .../microservice/jetty/JettyMicroservice.java      | 10 +++----
 .../org/apache/juneau/rest/client/RestRequest.java | 18 +++++------
 .../apache/juneau/http/entity/BasicHttpEntity.java | 35 ++++++++++++++--------
 .../org/apache/juneau/http/entity/FileEntity.java  |  8 ++---
 .../apache/juneau/http/entity/ReaderEntity.java    |  9 +++---
 .../apache/juneau/http/entity/StreamEntity.java    |  9 +++---
 .../org/apache/juneau/http/header/HeaderList.java  |  4 +--
 .../java/org/apache/juneau/http/part/PartList.java |  4 +--
 .../apache/juneau/rest/mock/MockRestClient.java    |  4 +--
 .../java/org/apache/juneau/rest/RestContext.java   |  6 ++--
 .../rest/swagger/BasicSwaggerProviderSession.java  |  4 +--
 .../java/org/apache/juneau/rest/util/UrlPath.java  |  2 +-
 .../juneau/rest/vars/SerializedRequestAttrVar.java |  2 +-
 .../java/org/apache/juneau/rest/widget/Widget.java |  2 +-
 .../a/rttests/RoundTripBeanInheritanceTest.java    |  6 ++--
 .../juneau/a/rttests/RoundTripBeanMapsTest.java    | 10 +++----
 .../a/rttests/RoundTripObjectsAsStringsTest.java   | 12 ++++----
 .../juneau/config/ConfigMapListenerTest.java       |  2 +-
 35 files changed, 99 insertions(+), 96 deletions(-)


[juneau] 10/11: [juneau-microservice-jetty] Throw IllegalArgumentException instead of RuntimeException

Posted by gg...@apache.org.
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 880531a53a9079eef8ece2f20257588a95e08aad
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 13:50:05 2023 -0400

    [juneau-microservice-jetty] Throw IllegalArgumentException instead of
    RuntimeException
---
 .../juneau/microservice/jetty/BasicJettyServerFactory.java     |  4 ++--
 .../apache/juneau/microservice/jetty/JettyMicroservice.java    | 10 ++++------
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/juneau-microservice/juneau-microservice-jetty/src/main/java/org/apache/juneau/microservice/jetty/BasicJettyServerFactory.java b/juneau-microservice/juneau-microservice-jetty/src/main/java/org/apache/juneau/microservice/jetty/BasicJettyServerFactory.java
index 707ce28eb..01fa84a20 100644
--- a/juneau-microservice/juneau-microservice-jetty/src/main/java/org/apache/juneau/microservice/jetty/BasicJettyServerFactory.java
+++ b/juneau-microservice/juneau-microservice-jetty/src/main/java/org/apache/juneau/microservice/jetty/BasicJettyServerFactory.java
@@ -13,6 +13,7 @@
 package org.apache.juneau.microservice.jetty;
 
 import java.io.*;
+import java.util.Objects;
 
 import org.apache.juneau.common.internal.*;
 import org.apache.juneau.internal.*;
@@ -31,8 +32,7 @@ public class BasicJettyServerFactory implements JettyServerFactory {
 
 	@Override
 	public Server create(String jettyXml) throws Exception {
-		if (jettyXml == null)
-			throw new RuntimeException("jetty.xml file location was not specified in the configuration file (Jetty/config) or manifest file (Jetty-Config) or found on the file system or classpath.");
+	    Objects.requireNonNull(jettyXml, "jetty.xml file location was not specified in the configuration file (Jetty/config) or manifest file (Jetty-Config) or found on the file system or classpath.");
 		File f = FileUtils.createTempFile("jetty.xml");
 		try (Reader r = new StringReader(jettyXml); Writer w = new FileWriter(f)) {
 			IOUtils.pipe(r, w);
diff --git a/juneau-microservice/juneau-microservice-jetty/src/main/java/org/apache/juneau/microservice/jetty/JettyMicroservice.java b/juneau-microservice/juneau-microservice-jetty/src/main/java/org/apache/juneau/microservice/jetty/JettyMicroservice.java
index 4fe8b8e91..3dcbee605 100644
--- a/juneau-microservice/juneau-microservice-jetty/src/main/java/org/apache/juneau/microservice/jetty/JettyMicroservice.java
+++ b/juneau-microservice/juneau-microservice-jetty/src/main/java/org/apache/juneau/microservice/jetty/JettyMicroservice.java
@@ -556,7 +556,7 @@ public class JettyMicroservice extends Microservice {
 		for (Connector c : getServer().getConnectors())
 			if (c instanceof ServerConnector)
 				return ((ServerConnector)c).getPort();
-		throw new RuntimeException("Could not locate ServerConnector in Jetty server.");
+		throw new IllegalStateException("Could not locate ServerConnector in Jetty server.");
 	}
 
 	/**
@@ -576,7 +576,7 @@ public class JettyMicroservice extends Microservice {
 			if (h instanceof ServletContextHandler)
 				return ((ServletContextHandler)h).getContextPath();
 		}
-		throw new RuntimeException("Could not locate ServletContextHandler in Jetty server.");
+		throw new IllegalStateException("Could not locate ServletContextHandler in Jetty server.");
 	}
 
 	/**
@@ -771,7 +771,7 @@ public class JettyMicroservice extends Microservice {
 			if (sch != null)
 				return sch;
 		}
-		throw new RuntimeException("Servlet context handler not found in jetty server.");
+		throw new IllegalStateException("Servlet context handler not found in jetty server.");
 	}
 
 	/**
@@ -793,9 +793,7 @@ public class JettyMicroservice extends Microservice {
 	 * @return The underlying Jetty server, or <jk>null</jk> if {@link #createServer()} has not yet been called.
 	 */
 	public Server getServer() {
-		if (server == null)
-			throw new RuntimeException("Server not found.  createServer() must be called first.");
-		return server;
+		return Objects.requireNonNull(server, "Server not found.  createServer() must be called first.");
 	}
 
 	/**


[juneau] 11/11: [juneau-utest] Throw IllegalArgumentException instead of RuntimeException

Posted by gg...@apache.org.
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 ca352d8da192c2f27d59fb7cab8479c631f33198
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 13:50:30 2023 -0400

    [juneau-utest] Throw IllegalArgumentException instead of
    RuntimeException
---
 .../juneau/a/rttests/RoundTripBeanInheritanceTest.java       |  6 +++---
 .../org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java   | 10 +++++-----
 .../juneau/a/rttests/RoundTripObjectsAsStringsTest.java      | 12 ++++++------
 .../java/org/apache/juneau/config/ConfigMapListenerTest.java |  2 +-
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java b/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java
index 286066adb..ae6663aa6 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java
@@ -126,15 +126,15 @@ public class RoundTripBeanInheritanceTest extends RoundTripTest {
 		}
 
 		public String isX() {
-			throw new RuntimeException("Should not be called!");
+			throw new IllegalCallerException("Should not be called!");
 		}
 
 		public String isY() {
-			throw new RuntimeException("Should not be called!");
+			throw new IllegalCallerException("Should not be called!");
 		}
 
 		public String isZ() {
-			throw new RuntimeException("Should not be called!");
+			throw new IllegalCallerException("Should not be called!");
 		}
 	}
 
diff --git a/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java b/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java
index 134adfaa0..8db38c31e 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanMapsTest.java
@@ -828,7 +828,7 @@ public class RoundTripBeanMapsTest extends RoundTripTest {
 		// This method should not be interpreted as the setter for this
 		// property because it doesn't match the getter return type above.
 		public void setA(KEnum a) {
-			throw new RuntimeException("Should not be called!");
+			throw new IllegalCallerException("Should not be called!");
 		}
 
 		public void setA(String a) {
@@ -840,11 +840,11 @@ public class RoundTripBeanMapsTest extends RoundTripTest {
 		}
 
 		public void setB(String b) {
-			throw new RuntimeException("Should not be called!");
+			throw new IllegalCallerException("Should not be called!");
 		}
 
 		public void setB(Object b) {
-			throw new RuntimeException("Should not be called!");
+			throw new IllegalCallerException("Should not be called!");
 		}
 
 		public void setB(KEnum b) {
@@ -860,11 +860,11 @@ public class RoundTripBeanMapsTest extends RoundTripTest {
 		}
 
 		public void setC(String c) {
-			throw new RuntimeException("Should not be called!");
+			throw new IllegalCallerException("Should not be called!");
 		}
 
 		public void setC(Object c) {
-			throw new RuntimeException("Should not be called!");
+			throw new IllegalCallerException("Should not be called!");
 		}
 	}
 
diff --git a/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripObjectsAsStringsTest.java b/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripObjectsAsStringsTest.java
index e09daf31a..4052ba269 100755
--- a/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripObjectsAsStringsTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripObjectsAsStringsTest.java
@@ -209,13 +209,13 @@ public class RoundTripObjectsAsStringsTest extends RoundTripTest {
 	public static class C1 {
 		public String f;
 		public static C2 valueOf(String s) {
-			throw new RuntimeException("Shouldn't be called!");
+			throw new IllegalCallerException("Shouldn't be called!");
 		}
 		public static C2 parse(String s) {
-			throw new RuntimeException("Shouldn't be called!");
+			throw new IllegalCallerException("Shouldn't be called!");
 		}
 		public static C2 parseString(String s) {
-			throw new RuntimeException("Shouldn't be called!");
+			throw new IllegalCallerException("Shouldn't be called!");
 		}
 		public static C1 fromString(String s) {
 			C1 x = new C1();
@@ -232,10 +232,10 @@ public class RoundTripObjectsAsStringsTest extends RoundTripTest {
 	public static class C2 {
 		public String f;
 		public static C2 parse(String s) {
-			throw new RuntimeException("Shouldn't be called!");
+			throw new IllegalCallerException("Shouldn't be called!");
 		}
 		public static C2 parseString(String s) {
-			throw new RuntimeException("Shouldn't be called!");
+			throw new IllegalCallerException("Shouldn't be called!");
 		}
 		public static C2 valueOf(String s) {
 			C2 x = new C2();
@@ -251,7 +251,7 @@ public class RoundTripObjectsAsStringsTest extends RoundTripTest {
 	public static class C3 {
 		public String f;
 		public static C2 parseString(String s) {
-			throw new RuntimeException("Shouldn't be called!");
+			throw new IllegalCallerException("Shouldn't be called!");
 		}
 		public static C3 parse(String s) {
 			C3 x = new C3();
diff --git a/juneau-utest/src/test/java/org/apache/juneau/config/ConfigMapListenerTest.java b/juneau-utest/src/test/java/org/apache/juneau/config/ConfigMapListenerTest.java
index bf5c35661..ae248ba93 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/config/ConfigMapListenerTest.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/config/ConfigMapListenerTest.java
@@ -590,6 +590,6 @@ public class ConfigMapListenerTest {
 
 	private static void wait(CountDownLatch latch) throws InterruptedException {
 		if (! latch.await(10, TimeUnit.SECONDS))
-			throw new RuntimeException("Latch failed.");
+			fail("Latch failed.");
 	}
 }


[juneau] 06/11: [juneau-examples-rest] Throw IllegalArgumentException instead of RuntimeException

Posted by gg...@apache.org.
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 6ea90f255a5c68bdd3f3d54c6a8bd1b41407304a
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 13:48:45 2023 -0400

    [juneau-examples-rest] Throw IllegalArgumentException instead of
    RuntimeException
---
 .../src/main/java/org/apache/juneau/examples/rest/PhotosResource.java   | 2 +-
 .../main/java/org/apache/juneau/examples/rest/dto/AtomFeedResource.java | 2 +-
 .../java/org/apache/juneau/examples/rest/dto/JsonSchemaResource.java    | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java
index 57823de85..8340a6cf8 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/PhotosResource.java
@@ -84,7 +84,7 @@ public class PhotosResource extends BasicRestServlet {
 			try {
 				return new URI("photos/"+id);
 			} catch (URISyntaxException e) {
-				throw new RuntimeException(e); // Shouldn't happen.
+				throw new IllegalStateException(e); // Shouldn't happen.
 			}
 		}
 
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/dto/AtomFeedResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/dto/AtomFeedResource.java
index fa9fadecb..e8564be85 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/dto/AtomFeedResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/dto/AtomFeedResource.java
@@ -103,7 +103,7 @@ public class AtomFeedResource extends BasicRestServlet {
 					)
 				);
 		} catch (Exception e) {
-			throw new RuntimeException(e);
+			throw new IllegalStateException(e);
 		}
 	}
 
diff --git a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/dto/JsonSchemaResource.java b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/dto/JsonSchemaResource.java
index 6f7fe75fa..d9f0bd1ea 100644
--- a/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/dto/JsonSchemaResource.java
+++ b/juneau-examples/juneau-examples-rest/src/main/java/org/apache/juneau/examples/rest/dto/JsonSchemaResource.java
@@ -82,7 +82,7 @@ public class JsonSchemaResource extends BasicRestServlet {
 				)
 				.addRequired("firstName", "lastName");
 		} catch (Exception e) {
-			throw new RuntimeException(e);
+			throw new IllegalStateException(e);
 		}
 	}
 


[juneau] 05/11: [juneau-marshall] Throw IllegalArgumentException instead of RuntimeException

Posted by gg...@apache.org.
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 6d1514eee478970fa833c6d91ae59794c7a5cb38
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 13:48:26 2023 -0400

    [juneau-marshall] Throw IllegalArgumentException instead of
    RuntimeException
---
 .../src/main/java/org/apache/juneau/BeanBuilder.java                | 4 ++--
 .../src/main/java/org/apache/juneau/BeanPropertyMeta.java           | 6 +++---
 .../src/main/java/org/apache/juneau/annotation/AnnotationImpl.java  | 2 +-
 .../src/main/java/org/apache/juneau/collections/JsonMap.java        | 2 +-
 .../src/main/java/org/apache/juneau/cp/BeanStore.java               | 4 ++--
 .../src/main/java/org/apache/juneau/cp/ContextBeanCreator.java      | 2 +-
 .../src/main/java/org/apache/juneau/internal/ListBuilder.java       | 4 ++--
 .../src/main/java/org/apache/juneau/internal/MapBuilder.java        | 4 ++--
 .../src/main/java/org/apache/juneau/internal/SetBuilder.java        | 2 +-
 9 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanBuilder.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanBuilder.java
index 775659192..41f349702 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanBuilder.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanBuilder.java
@@ -87,7 +87,7 @@ public class BeanBuilder<T> {
 	 */
 	protected BeanCreator<? extends T> creator() {
 		return beanStore
-			.createBean(type().orElseThrow(()->new RuntimeException("Type not specified.")))
+			.createBean(type().orElseThrow(() -> new IllegalStateException("Type not specified.")))
 			.builder(BeanBuilder.class, this);
 	}
 
@@ -98,7 +98,7 @@ public class BeanBuilder<T> {
 	 */
 	protected T buildDefault() {
 		return beanStore
-			.createBean(type().orElseThrow(()->new RuntimeException("Type not specified.")))
+			.createBean(type().orElseThrow(() -> new IllegalStateException("Type not specified.")))
 			.builder(BeanBuilder.class, this)
 			.run();
 	}
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
index a5706add3..428d33eb8 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
@@ -331,13 +331,13 @@ public final class BeanPropertyMeta implements Comparable<BeanPropertyMeta> {
 			if (ci.isChildOf(ObjectSwap.class)) {
 				ObjectSwap ps = BeanCreator.of(ObjectSwap.class).type(c).run();
 				if (ps.forMediaTypes() != null)
-					throw new RuntimeException("TODO - Media types on swaps not yet supported on bean properties.");
+					throw new UnsupportedOperationException("TODO - Media types on swaps not yet supported on bean properties.");
 				if (ps.withTemplate() != null)
-					throw new RuntimeException("TODO - Templates on swaps not yet supported on bean properties.");
+					throw new UnsupportedOperationException("TODO - Templates on swaps not yet supported on bean properties.");
 				return ps;
 			}
 			if (ci.isChildOf(Surrogate.class))
-				throw new RuntimeException("TODO - Surrogate swaps not yet supported on bean properties.");
+				throw new UnsupportedOperationException("TODO - Surrogate swaps not yet supported on bean properties.");
 			throw new BasicRuntimeException("Invalid class used in @Swap annotation.  Must be a subclass of ObjectSwap or Surrogate. {0}", c);
 		}
 
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
index 3e91180ec..684b08e6c 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
@@ -71,7 +71,7 @@ public class AnnotationImpl implements Annotation {
 	@Override /* Object */
 	public int hashCode() {
 		if (hashCode == -1)
-			throw new RuntimeException("Programming error.  postConstruct() was never called on annotation.");
+			throw new IllegalArgumentException("Programming error. postConstruct() was never called on annotation.");
 		return hashCode;
 	}
 
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/collections/JsonMap.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/collections/JsonMap.java
index 2cbcbf4bb..438b9ec38 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/collections/JsonMap.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/collections/JsonMap.java
@@ -371,7 +371,7 @@ public class JsonMap extends LinkedHashMap<String,Object> {
 	 */
 	public JsonMap(Object... keyValuePairs) {
 		if (keyValuePairs.length % 2 != 0)
-			throw new RuntimeException("Odd number of parameters passed into JsonMap(Object...)");
+			throw new IllegalArgumentException("Odd number of parameters passed into JsonMap(Object...)");
 		for (int i = 0; i < keyValuePairs.length; i+=2)
 			put(stringify(keyValuePairs[i]), keyValuePairs[i+1]);
 	}
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanStore.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanStore.java
index 3eb46fd8a..96e477468 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanStore.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/BeanStore.java
@@ -576,7 +576,7 @@ public class BeanStore {
 	 * @return The method finder.  Never <jk>null</jk>.
 	 */
 	public <T> BeanCreateMethodFinder<T> createMethodFinder(Class<T> beanType) {
-		return new BeanCreateMethodFinder<>(beanType, outer.orElseThrow(()->new RuntimeException("Method cannot be used without outer bean definition.")), this);
+		return new BeanCreateMethodFinder<>(beanType, outer.orElseThrow(() -> new IllegalArgumentException("Method cannot be used without outer bean definition.")), this);
 	}
 
 	/**
@@ -694,7 +694,7 @@ public class BeanStore {
 
 	private void assertCanWrite() {
 		if (readOnly)
-			throw new RuntimeException("Method cannot be used because BeanStore is read-only.");
+			throw new IllegalStateException("Method cannot be used because BeanStore is read-only.");
 	}
 
 	private JsonMap properties() {
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/ContextBeanCreator.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/ContextBeanCreator.java
index eaca9b5d3..4308b7f72 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/ContextBeanCreator.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/ContextBeanCreator.java
@@ -92,7 +92,7 @@ public class ContextBeanCreator<T> {
 	public ContextBeanCreator<T> type(Class<? extends T> value) {
 		builder = Context.createBuilder((Class<? extends Context>) value);
 		if (builder == null)
-			throw new RuntimeException("Creator for class {0} not found." + value.getName());
+			throw new IllegalArgumentException("Creator for class {0} not found." + value.getName());
 		return this;
 	}
 
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ListBuilder.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ListBuilder.java
index 0fcde38ef..4d3447e81 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ListBuilder.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ListBuilder.java
@@ -226,9 +226,9 @@ public final class ListBuilder<E> {
 	 * @param values The values to add.
 	 * @return This object.
 	 */
-	public ListBuilder<E> addAny(Object...values) {
+	public ListBuilder<E> addAny(Object... values) {
 		if (elementType == null)
-			throw new RuntimeException("Unknown element type.  Cannot use this method.");
+			throw new IllegalStateException("Unknown element type. Cannot use this method.");
 		try {
 			if (values != null) {
 				for (Object o : values) {
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/MapBuilder.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/MapBuilder.java
index 053190942..e6a84b94f 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/MapBuilder.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/MapBuilder.java
@@ -204,7 +204,7 @@ public final class MapBuilder<K,V> {
 	@SuppressWarnings("unchecked")
 	public MapBuilder<K,V> addAny(Object...values) {
 		if (keyType == null || valueType == null)
-			throw new RuntimeException("Unknown key and value types.  Cannot use this method.");
+			throw new IllegalStateException("Unknown key and value types. Cannot use this method.");
 		try {
 			for (Object o : values) {
 				if (o != null) {
@@ -232,7 +232,7 @@ public final class MapBuilder<K,V> {
 	@SuppressWarnings("unchecked")
 	public MapBuilder<K,V> addPairs(Object...pairs) {
 		if (pairs.length % 2 != 0)
-			throw new RuntimeException("Odd number of parameters passed into AMap.ofPairs()");
+			throw new IllegalArgumentException("Odd number of parameters passed into AMap.ofPairs()");
 		for (int i = 0; i < pairs.length; i+=2)
 			add((K)pairs[i], (V)pairs[i+1]);
 		return this;
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/SetBuilder.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/SetBuilder.java
index 18247ce94..4e8e5336a 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/SetBuilder.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/SetBuilder.java
@@ -211,7 +211,7 @@ public final class SetBuilder<E> {
 	 */
 	public SetBuilder<E> addAny(Object...values) {
 		if (elementType == null)
-			throw new RuntimeException("Unknown element type.  Cannot use this method.");
+			throw new IllegalStateException("Unknown element type. Cannot use this method.");
 		try {
 			if (values != null) {
 				for (Object o : values) {


[juneau] 09/11: [juneau-rest-server] Throw IllegalArgumentException instead of RuntimeException

Posted by gg...@apache.org.
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 <gg...@rocketsoftware.com>
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);
 		}
 	}
 


[juneau] 01/11: [juneau-rest-client] Throw a specialized RuntimeException instead of RuntimeException

Posted by gg...@apache.org.
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 f030b36fa247e92950f07588b0920ad2cd951945
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 12:47:12 2023 -0400

    [juneau-rest-client] Throw a specialized RuntimeException instead of
    RuntimeException
---
 .../org/apache/juneau/rest/client/RestRequest.java     | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestRequest.java b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestRequest.java
index f949b4acc..ff9944c89 100644
--- a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestRequest.java
+++ b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestRequest.java
@@ -1046,7 +1046,7 @@ public class RestRequest extends BeanSession implements HttpUriRequest, Configur
 	@FluentSetter
 	public RestRequest headerPairs(String...pairs) {
 		if (pairs.length % 2 != 0)
-			throw new RuntimeException("Odd number of parameters passed into headerPairs(String...)");
+			throw new IllegalArgumentException("Odd number of parameters passed into headerPairs(String...)");
 		HeaderList b = headerData;
 		for (int i = 0; i < pairs.length; i+=2)
 			b.append(pairs[i], pairs[i+1]);
@@ -1076,7 +1076,7 @@ public class RestRequest extends BeanSession implements HttpUriRequest, Configur
 	@FluentSetter
 	public RestRequest queryDataPairs(String...pairs) throws RestCallException {
 		if (pairs.length % 2 != 0)
-			throw new RuntimeException("Odd number of parameters passed into queryDataPairs(String...)");
+			throw new IllegalArgumentException("Odd number of parameters passed into queryDataPairs(String...)");
 		PartList b = queryData;
 		for (int i = 0; i < pairs.length; i+=2)
 			b.append(pairs[i], pairs[i+1]);
@@ -1106,7 +1106,7 @@ public class RestRequest extends BeanSession implements HttpUriRequest, Configur
 	@FluentSetter
 	public RestRequest formDataPairs(String...pairs) throws RestCallException {
 		if (pairs.length % 2 != 0)
-			throw new RuntimeException("Odd number of parameters passed into formDataPairs(String...)");
+			throw new IllegalArgumentException("Odd number of parameters passed into formDataPairs(String...)");
 		PartList b = formData;
 		for (int i = 0; i < pairs.length; i+=2)
 			b.append(pairs[i], pairs[i+1]);
@@ -1138,7 +1138,7 @@ public class RestRequest extends BeanSession implements HttpUriRequest, Configur
 	@FluentSetter
 	public RestRequest pathDataPairs(String...pairs) {
 		if (pairs.length % 2 != 0)
-			throw new RuntimeException("Odd number of parameters passed into pathDataPairs(String...)");
+			throw new IllegalArgumentException("Odd number of parameters passed into pathDataPairs(String...)");
 		PartList b = pathData;
 		for (int i = 0; i < pairs.length; i+=2)
 			b.set(pairs[i], pairs[i+1]);
@@ -1172,7 +1172,7 @@ public class RestRequest extends BeanSession implements HttpUriRequest, Configur
 	@FluentSetter
 	public RestRequest headersBean(Object value) {
 		if (! isBean(value))
-			throw new RuntimeException("Object passed into headersBean(Object) is not a bean.");
+			throw new IllegalArgumentException("Object passed into headersBean(Object) is not a bean.");
 		HeaderList b = headerData;
 		toBeanMap(value, PropertyNamerDUCS.INSTANCE).forEach((k,v) -> b.append(createHeader(k, v)));
 		return this;
@@ -1201,7 +1201,7 @@ public class RestRequest extends BeanSession implements HttpUriRequest, Configur
 	@FluentSetter
 	public RestRequest queryDataBean(Object value) {
 		if (! isBean(value))
-			throw new RuntimeException("Object passed into queryDataBean(Object) is not a bean.");
+			throw new IllegalArgumentException("Object passed into queryDataBean(Object) is not a bean.");
 		PartList b = queryData;
 		toBeanMap(value).forEach((k,v) -> b.append(createPart(QUERY, k, v)));
 		return this;
@@ -1230,7 +1230,7 @@ public class RestRequest extends BeanSession implements HttpUriRequest, Configur
 	@FluentSetter
 	public RestRequest formDataBean(Object value) {
 		if (! isBean(value))
-			throw new RuntimeException("Object passed into formDataBean(Object) is not a bean.");
+			throw new IllegalArgumentException("Object passed into formDataBean(Object) is not a bean.");
 		PartList b = formData;
 		toBeanMap(value).forEach((k,v) -> b.append(createPart(FORMDATA, k, v)));
 		return this;
@@ -1259,7 +1259,7 @@ public class RestRequest extends BeanSession implements HttpUriRequest, Configur
 	@FluentSetter
 	public RestRequest pathDataBean(Object value) {
 		if (! isBean(value))
-			throw new RuntimeException("Object passed into pathDataBean(Object) is not a bean.");
+			throw new IllegalArgumentException("Object passed into pathDataBean(Object) is not a bean.");
 		PartList b = pathData;
 		toBeanMap(value).forEach((k,v) -> b.set(createPart(PATH, k, v)));
 		return this;
@@ -1860,7 +1860,7 @@ public class RestRequest extends BeanSession implements HttpUriRequest, Configur
 					String name = x.name, value = x.value;
 					String var = "{" + name + "}";
 					if (path.indexOf(var) == -1 && ! name.equals("/*"))
-						throw new RuntimeException("Path variable {"+name+"} was not found in path.");
+						throw new IllegalStateException("Path variable {" + name + "} was not found in path.");
 					if (name.equals("/*"))
 						path = path.replaceAll("\\/\\*$", "/" + value);
 					else


[juneau] 03/11: [juneau-rest-mock] Throw a specialized RuntimeException instead of RuntimeException

Posted by gg...@apache.org.
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 d51d57d01aa9edb3355a62ac617f7bf23d0deb8a
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 12:47:38 2023 -0400

    [juneau-rest-mock] Throw a specialized RuntimeException instead of
    RuntimeException
---
 .../src/main/java/org/apache/juneau/rest/mock/MockRestClient.java     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
index 454dcc81f..fe2388b26 100644
--- a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
+++ b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock/MockRestClient.java
@@ -2143,7 +2143,7 @@ public class MockRestClient extends RestClient implements HttpClientConnection {
 
 			MockPathResolver pr = new MockPathResolver(target, contextPath, servletPath, path, null);
 			if (pr.getError() != null)
-				throw new RuntimeException(pr.getError());
+				throw new IllegalStateException(pr.getError());
 
 			MockServletRequest r = MockServletRequest
 				.create(request.getRequestLine().getMethod(), pr.getURI())
@@ -2207,7 +2207,7 @@ public class MockRestClient extends RestClient implements HttpClientConnection {
 
 			// If the status isn't set, something's broken.
 			if (res.getStatus() == 0)
-				throw new RuntimeException("Response status was 0.");
+				throw new IllegalStateException("Response status was 0.");
 
 			// A bug in HttpClient causes an infinite loop if the response is less than 200.
 			// As a workaround, just add 1000 to the status code (which is better than an infinite loop).


[juneau] 04/11: [juneau-common] Throw IllegalArgumentException instead of RuntimeException

Posted by gg...@apache.org.
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 98aa38fc86f1d8ec3c3ce41782ed844473e0cd56
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 13:48:07 2023 -0400

    [juneau-common] Throw IllegalArgumentException instead of
    RuntimeException
---
 .../src/main/java/org/apache/juneau/common/internal/AsciiSet.java       | 2 +-
 .../src/main/java/org/apache/juneau/common/internal/ThrowableUtils.java | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/AsciiSet.java b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/AsciiSet.java
index 53a3636c2..6fbb63e8d 100644
--- a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/AsciiSet.java
+++ b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/AsciiSet.java
@@ -75,7 +75,7 @@ public final class AsciiSet {
 		public AsciiSet.Builder ranges(String...s) {
 			for (String ss : s) {
 				if (ss.length() != 3 || ss.charAt(1) != '-')
-					throw new RuntimeException("Value passed to ranges() must be 3 characters");
+					throw new IllegalArgumentException("Value passed to ranges() must be 3 characters");
 				range(ss.charAt(0), ss.charAt(2));
 			}
 			return this;
diff --git a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/ThrowableUtils.java b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/ThrowableUtils.java
index eed0a6ec3..f6264fc64 100644
--- a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/ThrowableUtils.java
+++ b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/ThrowableUtils.java
@@ -43,7 +43,7 @@ public class ThrowableUtils {
 		try {
 			return type.isInstance(t) ? type.cast(t) : type.getConstructor(Throwable.class).newInstance(t);
 		} catch (Exception e) {
-			throw new RuntimeException(e);
+			throw new IllegalArgumentException(e);
 		}
 	}
 


[juneau] 07/11: [juneau-examples-rest-ftest] Throw IllegalArgumentException instead of RuntimeException

Posted by gg...@apache.org.
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 fed265804076b63c527634a36181ddfb3223ca90
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 13:49:00 2023 -0400

    [juneau-examples-rest-ftest] Throw IllegalArgumentException instead of
    RuntimeException
---
 .../test/java/org/apache/juneau/examples/rest/SamplesMicroservice.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/juneau-examples/juneau-examples-rest-jetty-ftest/src/test/java/org/apache/juneau/examples/rest/SamplesMicroservice.java b/juneau-examples/juneau-examples-rest-jetty-ftest/src/test/java/org/apache/juneau/examples/rest/SamplesMicroservice.java
index a5c816903..bc2ecad2b 100644
--- a/juneau-examples/juneau-examples-rest-jetty-ftest/src/test/java/org/apache/juneau/examples/rest/SamplesMicroservice.java
+++ b/juneau-examples/juneau-examples-rest-jetty-ftest/src/test/java/org/apache/juneau/examples/rest/SamplesMicroservice.java
@@ -85,7 +85,7 @@ public class SamplesMicroservice {
 		try {
 			return RestClient.create().rootUrl(microserviceURI);
 		} catch (Exception e) {
-			throw new RuntimeException(e);
+			throw new IllegalStateException(e);
 		}
 	}
 


[juneau] 02/11: [juneau-rest-common] Throw a specialized RuntimeException instead of RuntimeException

Posted by gg...@apache.org.
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 afab8ae4dc9c2302dd1f359e7572c605f3b076d8
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 12:47:26 2023 -0400

    [juneau-rest-common] Throw a specialized RuntimeException instead of
    RuntimeException
---
 .../apache/juneau/http/entity/BasicHttpEntity.java | 35 ++++++++++++++--------
 .../org/apache/juneau/http/entity/FileEntity.java  |  8 ++---
 .../apache/juneau/http/entity/ReaderEntity.java    |  9 +++---
 .../apache/juneau/http/entity/StreamEntity.java    |  9 +++---
 .../org/apache/juneau/http/header/HeaderList.java  |  4 +--
 .../java/org/apache/juneau/http/part/PartList.java |  4 +--
 6 files changed, 38 insertions(+), 31 deletions(-)

diff --git a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/BasicHttpEntity.java b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/BasicHttpEntity.java
index cdfb42899..3baf45504 100644
--- a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/BasicHttpEntity.java
+++ b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/BasicHttpEntity.java
@@ -12,18 +12,27 @@
 // ***************************************************************************************************************************
 package org.apache.juneau.http.entity;
 
-import static org.apache.juneau.common.internal.IOUtils.*;
-
-import java.io.*;
-import java.nio.charset.*;
-import java.util.function.*;
-
-import org.apache.http.*;
-import org.apache.juneau.annotation.*;
-import org.apache.juneau.assertions.*;
-import org.apache.juneau.common.internal.*;
-import org.apache.juneau.http.header.*;
-import org.apache.juneau.internal.*;
+import static org.apache.juneau.common.internal.IOUtils.UTF8;
+import static org.apache.juneau.common.internal.IOUtils.read;
+import static org.apache.juneau.common.internal.IOUtils.readBytes;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UncheckedIOException;
+import java.nio.charset.Charset;
+import java.util.function.Supplier;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.juneau.annotation.BeanIgnore;
+import org.apache.juneau.assertions.FluentByteArrayAssertion;
+import org.apache.juneau.assertions.FluentStringAssertion;
+import org.apache.juneau.common.internal.IOUtils;
+import org.apache.juneau.http.header.ContentEncoding;
+import org.apache.juneau.http.header.ContentType;
+import org.apache.juneau.internal.FluentSetter;
+import org.apache.juneau.internal.FluentSetters;
 
 /**
  * A basic {@link org.apache.http.HttpEntity} implementation with additional features.
@@ -384,7 +393,7 @@ public class BasicHttpEntity implements HttpEntity {
 		try {
 			return asBytes();
 		} catch (IOException e) {
-			throw new RuntimeException(e);
+			throw new UncheckedIOException(e);
 		}
 	}
 
diff --git a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/FileEntity.java b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/FileEntity.java
index db6a3501e..131b118dd 100644
--- a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/FileEntity.java
+++ b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/FileEntity.java
@@ -17,6 +17,7 @@ import static org.apache.juneau.common.internal.IOUtils.*;
 
 import java.io.*;
 import java.nio.charset.*;
+import java.util.Objects;
 import java.util.function.*;
 
 import org.apache.juneau.common.internal.*;
@@ -77,12 +78,11 @@ public class FileEntity extends BasicHttpEntity {
 
 	private File content() {
 		File f = contentOrElse((File)null);
-		if (f == null)
-			throw new RuntimeException("File is null.");
+		Objects.requireNonNull(f, "File");
 		if (! f.exists())
-			throw new RuntimeException("File "+f.getAbsolutePath()+" does not exist.");
+			throw new IllegalStateException("File " + f.getAbsolutePath() + " does not exist.");
 		if (! f.canRead())
-			throw new RuntimeException("File "+f.getAbsolutePath()+" is not readable.");
+			throw new IllegalStateException("File " + f.getAbsolutePath() + " is not readable.");
 		return f;
 	}
 
diff --git a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/ReaderEntity.java b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/ReaderEntity.java
index 450545f3a..d052375de 100644
--- a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/ReaderEntity.java
+++ b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/ReaderEntity.java
@@ -17,6 +17,7 @@ import static org.apache.juneau.common.internal.IOUtils.*;
 
 import java.io.*;
 import java.nio.charset.*;
+import java.util.Objects;
 import java.util.function.*;
 
 import org.apache.juneau.http.header.*;
@@ -74,11 +75,9 @@ public class ReaderEntity extends BasicHttpEntity {
 	// Other methods
 	//-----------------------------------------------------------------------------------------------------------------
 
-	private Reader content() {
-		Reader r = contentOrElse((Reader)null);
-		if (r == null)
-			throw new RuntimeException("Reader is null.");
-		return r;
+	@SuppressWarnings("resource") // Caller closes
+    private Reader content() {
+		return Objects.requireNonNull(contentOrElse((Reader) null), "Reader is null.");
 	}
 
 	@Override /* AbstractHttpEntity */
diff --git a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/StreamEntity.java b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/StreamEntity.java
index 1fd4f3021..612b11d32 100644
--- a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/StreamEntity.java
+++ b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/entity/StreamEntity.java
@@ -17,6 +17,7 @@ import static org.apache.juneau.common.internal.IOUtils.*;
 
 import java.io.*;
 import java.nio.charset.*;
+import java.util.Objects;
 import java.util.function.*;
 
 import org.apache.juneau.http.header.*;
@@ -74,11 +75,9 @@ public class StreamEntity extends BasicHttpEntity {
 	// Other methods
 	//-----------------------------------------------------------------------------------------------------------------
 
-	private InputStream content() {
-		InputStream is = contentOrElse((InputStream)null);
-		if (is == null)
-			throw new RuntimeException("Input stream is null.");
-		return is;
+	@SuppressWarnings("resource") // Caller closes
+    private InputStream content() {
+		return Objects.requireNonNull(contentOrElse((InputStream) null), "Input stream is null.");
 	}
 
 	@Override /* AbstractHttpEntity */
diff --git a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/header/HeaderList.java b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/header/HeaderList.java
index 88cfdf90f..2ddeff8ae 100644
--- a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/header/HeaderList.java
+++ b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/header/HeaderList.java
@@ -120,12 +120,12 @@ public class HeaderList extends ControlledArrayList<Header> {
 	 * @throws RuntimeException If odd number of parameters were specified.
 	 * @return A new instance.
 	 */
-	public static HeaderList ofPairs(String...pairs) {
+	public static HeaderList ofPairs(String... pairs) {
 		HeaderList x = new HeaderList();
 		if (pairs == null)
 			pairs = new String[0];
 		if (pairs.length % 2 != 0)
-			throw new RuntimeException("Odd number of parameters passed into HeaderList.ofPairs()");
+			throw new IllegalArgumentException("Odd number of parameters passed into HeaderList.ofPairs()");
 		for (int i = 0; i < pairs.length; i+=2)
 			x.add(BasicHeader.of(pairs[i], pairs[i+1]));
 		return x;
diff --git a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/part/PartList.java b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/part/PartList.java
index cc22bb7e7..e70029714 100644
--- a/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/part/PartList.java
+++ b/juneau-rest/juneau-rest-common/src/main/java/org/apache/juneau/http/part/PartList.java
@@ -106,12 +106,12 @@ public class PartList extends ControlledArrayList<NameValuePair> {
 	 * @throws RuntimeException If odd number of parameters were specified.
 	 * @return A new instance.
 	 */
-	public static PartList ofPairs(String...pairs) {
+	public static PartList ofPairs(String... pairs) {
 		PartList x = new PartList();
 		if (pairs == null)
 			pairs = new String[0];
 		if (pairs.length % 2 != 0)
-			throw new RuntimeException("Odd number of parameters passed into PartList.ofPairs()");
+			throw new IllegalArgumentException("Odd number of parameters passed into PartList.ofPairs()");
 		for (int i = 0; i < pairs.length; i+=2)
 			x.add(BasicPart.of(pairs[i], pairs[i+1]));
 		return x;


[juneau] 08/11: [juneau-microservice-core] Throw IllegalArgumentException instead of RuntimeException

Posted by gg...@apache.org.
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 c23e3bd2b7ebbd5ca62d07fcb2fe98a721b0b2c1
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 13:49:18 2023 -0400

    [juneau-microservice-core] Throw IllegalArgumentException instead of
    RuntimeException
---
 .../main/java/org/apache/juneau/microservice/resources/LogParser.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/juneau-microservice/juneau-microservice-core/src/main/java/org/apache/juneau/microservice/resources/LogParser.java b/juneau-microservice/juneau-microservice-core/src/main/java/org/apache/juneau/microservice/resources/LogParser.java
index 78b36488e..d35c63cc7 100644
--- a/juneau-microservice/juneau-microservice-core/src/main/java/org/apache/juneau/microservice/resources/LogParser.java
+++ b/juneau-microservice/juneau-microservice-core/src/main/java/org/apache/juneau/microservice/resources/LogParser.java
@@ -89,7 +89,7 @@ public final class LogParser implements Iterable<LogParser.Entry>, Iterator<LogP
 				}
 			}
 		} catch (IOException e) {
-			throw new RuntimeException(e);
+			throw new UncheckedIOException(e);
 		}
 		return current;
 	}