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:51:07 UTC

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

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.");
 	}
 
 	/**