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 18:02:49 UTC

[juneau] branch master updated (ca352d8da -> 9af471d9e)

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 ca352d8da [juneau-utest] Throw IllegalArgumentException instead of RuntimeException
     new b2cbd121b [juneau-utest] Throw IllegalArgumentException instead of RuntimeException
     new 073f721b8 [juneau-commons] Reuse String#isEmpty() instead of custom length check
     new 806c26521 [juneau-marshall] Reuse String#isEmpty() instead of custom length check
     new 9af471d9e [juneau-rest-server] Reuse String#isEmpty() instead of custom length check

The 4 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/StringUtils.java  | 12 ++++++------
 .../main/java/org/apache/juneau/UriResolver.java    |  2 +-
 .../org/apache/juneau/json/JsonParserSession.java   |  2 +-
 .../org/apache/juneau/objecttools/ObjectRest.java   |  6 +++---
 .../main/java/org/apache/juneau/xml/XmlUtils.java   |  2 +-
 .../java/org/apache/juneau/rest/util/RestUtils.java |  2 +-
 .../juneau/CloseableByteArrayInputStream.java       |  2 +-
 .../org/apache/juneau/CloseableStringReader.java    | 21 ++++++++++++---------
 .../rest/annotation/BeanConfig_Swaps_Test.java      |  6 +++---
 .../juneau/rest/annotation/RestPostCall_Test.java   |  4 ++--
 .../juneau/rest/annotation/RestPreCall_Test.java    |  4 ++--
 .../juneau/rest/annotation/RestStartCall_Test.java  |  4 ++--
 12 files changed, 35 insertions(+), 32 deletions(-)


[juneau] 03/04: [juneau-marshall] Reuse String#isEmpty() instead of custom length check

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 806c26521f72e75ff42f0049a54bfec42c202c79
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 14:02:08 2023 -0400

    [juneau-marshall] Reuse String#isEmpty() instead of custom length check
---
 .../src/main/java/org/apache/juneau/UriResolver.java                | 2 +-
 .../src/main/java/org/apache/juneau/json/JsonParserSession.java     | 2 +-
 .../src/main/java/org/apache/juneau/objecttools/ObjectRest.java     | 6 +++---
 .../src/main/java/org/apache/juneau/xml/XmlUtils.java               | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/UriResolver.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/UriResolver.java
index e3681cacd..214031a88 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/UriResolver.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/UriResolver.java
@@ -263,7 +263,7 @@ public class UriResolver {
 	}
 
 	private static boolean isSpecialUri(String s) {
-		if (s == null || s.length() == 0)
+		if (s == null || s.isEmpty())
 			return false;
 		char c = s.charAt(0);
 		if (c != 's' && c != 'c' && c != 'r')
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonParserSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonParserSession.java
index 6bd757930..0bc7b3b9c 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonParserSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonParserSession.java
@@ -407,7 +407,7 @@ public final class JsonParserSession extends ReaderParserSession {
 
 			// Lax allows blank strings to represent 0.
 			// Strict does not allow blank strings.
-			if (s.length() == 0)
+			if (s.isEmpty())
 				throw new ParseException(this, "Invalid JSON number: ''{0}''", s);
 
 			// Need to weed out octal and hexadecimal formats:  0123,-0123,0x123,-0x123.
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/objecttools/ObjectRest.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/objecttools/ObjectRest.java
index c4b9e7b39..d7582b1dc 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/objecttools/ObjectRest.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/objecttools/ObjectRest.java
@@ -771,7 +771,7 @@ public final class ObjectRest {
 		String childKey = (i == -1 ? url : url.substring(i + 1));
 
 		if (method == PUT) {
-			if (url.length() == 0) {
+			if (url.isEmpty()) {
 				if (rootLocked)
 					throw new ObjectRestException(HTTP_FORBIDDEN, "Cannot overwrite root object");
 				Object o = root.o;
@@ -809,7 +809,7 @@ public final class ObjectRest {
 
 		if (method == POST) {
 			// Handle POST to root special
-			if (url.length() == 0) {
+			if (url.isEmpty()) {
 				ClassMeta cm = root.cm;
 				Object o = root.o;
 				if (cm.isCollection()) {
@@ -853,7 +853,7 @@ public final class ObjectRest {
 		}
 
 		if (method == DELETE) {
-			if (url.length() == 0) {
+			if (url.isEmpty()) {
 				if (rootLocked)
 					throw new ObjectRestException(HTTP_FORBIDDEN, "Cannot overwrite root object");
 				Object o = root.o;
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlUtils.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlUtils.java
index 8b2c8c774..e75e1099b 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlUtils.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlUtils.java
@@ -388,7 +388,7 @@ public final class XmlUtils {
 	public static final String decode(String value, StringBuilder sb) {
 		if (value == null)
 			return null;
-		if (value.length() == 0 || value.indexOf('_') == -1)
+		if (value.isEmpty() || value.indexOf('_') == -1)
 			return value;
 		if (sb == null)
 			sb = new StringBuilder(value.length());


[juneau] 02/04: [juneau-commons] Reuse String#isEmpty() instead of custom length check

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 073f721b897b8f9850949ab3dd76635059214021
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 14:01:55 2023 -0400

    [juneau-commons] Reuse String#isEmpty() instead of custom length check
---
 .../java/org/apache/juneau/common/internal/StringUtils.java  | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/StringUtils.java b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/StringUtils.java
index 4777380c6..891f014f7 100644
--- a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/StringUtils.java
+++ b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/StringUtils.java
@@ -182,7 +182,7 @@ public final class StringUtils {
 		if (o == null)
 			return null;
 		String s = o.toString();
-		if (s.length() == 0)
+		if (s.isEmpty())
 			return null;
 		if (s.length() == 1)
 			return s.charAt(0);
@@ -940,7 +940,7 @@ public final class StringUtils {
 	 * @return A new string if characters were removed, or the same string if not or if the input was <jk>null</jk>.
 	 */
 	public static String unEscapeChars(String s, AsciiSet escaped) {
-		if (s == null || s.length() == 0)
+		if (s == null || s.isEmpty())
 			return s;
 		int count = 0;
 		for (int i = 0; i < s.length(); i++)
@@ -1793,7 +1793,7 @@ public final class StringUtils {
 	public static String trimSlashes(String s) {
 		if (s == null)
 			return null;
-		if (s.length() == 0)
+		if (s.isEmpty())
 			return s;
 		while (endsWith(s, '/'))
 			s = s.substring(0, s.length()-1);
@@ -2313,7 +2313,7 @@ public final class StringUtils {
 	}
 
 	private static int multiplier(String s) {
-		char c = s.length() == 0 ? null : s.charAt(s.length()-1);
+		char c = s.isEmpty() ? null : s.charAt(s.length()-1);
 		if (c == 'G') return 1024*1024*1024;
 		if (c == 'M') return 1024*1024;
 		if (c == 'K') return 1024;
@@ -2353,7 +2353,7 @@ public final class StringUtils {
 	}
 
 	private static long multiplier2(String s) {
-		char c = s.length() == 0 ? null : s.charAt(s.length()-1);
+		char c = s.isEmpty() ? null : s.charAt(s.length()-1);
 		if (c == 'P') return 1024*1024*1024*1024*1024;
 		if (c == 'T') return 1024*1024*1024*1024;
 		if (c == 'G') return 1024*1024*1024;
@@ -2546,7 +2546,7 @@ public final class StringUtils {
 	 * @return The first character in the string, or <c>0</c> if the string is <jk>null</jk> or empty.
 	 */
 	public static char firstChar(String s) {
-		if (s == null || s.length() == 0)
+		if (s == null || s.isEmpty())
 			return 0;
 		return s.charAt(0);
 	}


[juneau] 04/04: [juneau-rest-server] Reuse String#isEmpty() instead of custom length check

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 9af471d9e67063641a5a1e57edc43d9c5f4a2467
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 14:02:22 2023 -0400

    [juneau-rest-server] Reuse String#isEmpty() instead of custom length
    check
---
 .../src/main/java/org/apache/juneau/rest/util/RestUtils.java            | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/RestUtils.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/RestUtils.java
index e04cddb9e..f6dfe54db 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/RestUtils.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/util/RestUtils.java
@@ -392,7 +392,7 @@ public final class RestUtils {
 	public static String trimContextPath(String contextPath, String path) {
 		if (path == null)
 			return null;
-		if (path.length() == 0 || path.equals("/") || contextPath.length() == 0 || contextPath.equals("/"))
+		if (path.isEmpty() || path.equals("/") || contextPath.isEmpty() || contextPath.equals("/"))
 			return path;
 		String op = path;
 		if (path.charAt(0) == '/')


[juneau] 01/04: [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 b2cbd121b5524b7851c281bdfe83123df6b0525c
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 13:58:01 2023 -0400

    [juneau-utest] Throw IllegalArgumentException instead of
    RuntimeException
---
 .../juneau/CloseableByteArrayInputStream.java       |  2 +-
 .../org/apache/juneau/CloseableStringReader.java    | 21 ++++++++++++---------
 .../rest/annotation/BeanConfig_Swaps_Test.java      |  6 +++---
 .../juneau/rest/annotation/RestPostCall_Test.java   |  4 ++--
 .../juneau/rest/annotation/RestPreCall_Test.java    |  4 ++--
 .../juneau/rest/annotation/RestStartCall_Test.java  |  4 ++--
 6 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/juneau-utest/src/test/java/org/apache/juneau/CloseableByteArrayInputStream.java b/juneau-utest/src/test/java/org/apache/juneau/CloseableByteArrayInputStream.java
index 716d4a0cc..8c84c3e04 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/CloseableByteArrayInputStream.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/CloseableByteArrayInputStream.java
@@ -27,7 +27,7 @@ public class CloseableByteArrayInputStream extends ByteArrayInputStream {
 	@Override
 	public int read() {
 		if (isClosed)
-			throw new RuntimeException("Stream is closed");
+			throw new IllegalStateException("Stream is closed");
 		return super.read();
 	}
 
diff --git a/juneau-utest/src/test/java/org/apache/juneau/CloseableStringReader.java b/juneau-utest/src/test/java/org/apache/juneau/CloseableStringReader.java
index 836a3b56e..67d536413 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/CloseableStringReader.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/CloseableStringReader.java
@@ -24,22 +24,25 @@ public class CloseableStringReader extends StringReader {
 		super(in);
 	}
 
+	private void checkOpen() {
+        if (isClosed)
+			throw new IllegalStateException("Reader is closed");
+    }
+
+    @Override
+	public void close() {
+		isClosed = true;
+	}
+
 	@Override
 	public int read() throws IOException {
-		if (isClosed)
-			throw new RuntimeException("Reader is closed");
+		checkOpen();
 		return super.read();
 	}
 
 	@Override
 	public int read(char[] cbuf, int off, int len) throws IOException {
-		if (isClosed)
-			throw new RuntimeException("Reader is closed");
+		checkOpen();
 		return super.read(cbuf, off, len);
 	}
-
-	@Override
-	public void close() {
-		isClosed = true;
-	}
 }
\ No newline at end of file
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/BeanConfig_Swaps_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/BeanConfig_Swaps_Test.java
index 2367e204f..c7ba277f0 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/BeanConfig_Swaps_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/BeanConfig_Swaps_Test.java
@@ -46,7 +46,7 @@ public class BeanConfig_Swaps_Test {
 		@Override /* ObjectSwap */
 		public A unswap(BeanSession session, String in, ClassMeta<?> hint) throws ParseException {
 			if (! in.startsWith("A1"))
-				throw new RuntimeException("Invalid input for SwapA1!");
+				throw new IllegalArgumentException("Invalid input for SwapA1!");
 			A a = new A();
 			a.f1 = Integer.parseInt(in.substring(3));
 			return a;
@@ -61,7 +61,7 @@ public class BeanConfig_Swaps_Test {
 		@Override /* ObjectSwap */
 		public A unswap(BeanSession session, String in, ClassMeta<?> hint) throws ParseException {
 			if (! in.startsWith("A2"))
-				throw new RuntimeException("Invalid input for SwapA2!");
+				throw new IllegalArgumentException("Invalid input for SwapA2!");
 			A a = new A();
 			a.f1 = Integer.parseInt(in.substring(3));
 			return a;
@@ -76,7 +76,7 @@ public class BeanConfig_Swaps_Test {
 		@Override /* ObjectSwap */
 		public A unswap(BeanSession session, String in, ClassMeta<?> hint) throws ParseException {
 			if (! in.startsWith("A3"))
-				throw new RuntimeException("Invalid input for SwapA3!");
+				throw new IllegalArgumentException("Invalid input for SwapA3!");
 			A a = new A();
 			a.f1 = Integer.parseInt(in.substring(3));
 			return a;
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPostCall_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPostCall_Test.java
index 88439a75c..086fd10e4 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPostCall_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPostCall_Test.java
@@ -42,7 +42,7 @@ public class RestPostCall_Test {
 			res.setHeader("post3-called", ""+post3Called);
 			post3Called = false;
 			if (res.getHeader("post4-called") != null)
-				throw new RuntimeException("post4 called multiple times.");
+				throw new IllegalArgumentException("post4 called multiple times.");
 			res.setHeader("post4-called", "true");
 		}
 		@RestGet(path="/")
@@ -62,7 +62,7 @@ public class RestPostCall_Test {
 			res.setHeader("post1-called", ""+post1Called);
 			post1Called = false;
 			if (res.getHeader("post2-called") != null)
-				throw new RuntimeException("post2 called multiple times.");
+				throw new IllegalArgumentException("post2 called multiple times.");
 			res.setHeader("post2-called", "true");
 		}
 	}
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPreCall_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPreCall_Test.java
index d85305656..1952cc77c 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPreCall_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPreCall_Test.java
@@ -43,7 +43,7 @@ public class RestPreCall_Test {
 			res.setHeader("pre3-called", ""+pre3Called);
 			pre3Called = false;
 			if (res.getHeader("pre4-called") != null)
-				throw new RuntimeException("pre4 called multiple times.");
+				throw new IllegalArgumentException("pre4 called multiple times.");
 			res.setHeader("pre4-called", "true");
 		}
 		@RestGet(path="/")
@@ -67,7 +67,7 @@ public class RestPreCall_Test {
 			res.setHeader("pre1-called", ""+pre1Called);
 			pre1Called = false;
 			if (res.getHeader("pre2-called") != null)
-				throw new RuntimeException("pre2 called multiple times.");
+				throw new IllegalArgumentException("pre2 called multiple times.");
 			res.setHeader("pre2-called", "true");
 		}
 	}
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestStartCall_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestStartCall_Test.java
index ddd8794cd..f1f6dde87 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestStartCall_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestStartCall_Test.java
@@ -42,7 +42,7 @@ public class RestStartCall_Test {
 			res.setHeader("start3-called", ""+start3Called);
 			start3Called = false;
 			if (res.getHeader("start4-called") != null)
-				throw new RuntimeException("start4 called multiple times.");
+				throw new IllegalArgumentException("start4 called multiple times.");
 			res.setHeader("start4-called", "true");
 		}
 		@RestGet(path="/")
@@ -66,7 +66,7 @@ public class RestStartCall_Test {
 			res.setHeader("start1-called", ""+start1Called);
 			start1Called = false;
 			if (res.getHeader("start2-called") != null)
-				throw new RuntimeException("start2 called multiple times.");
+				throw new IllegalArgumentException("start2 called multiple times.");
 			res.setHeader("start2-called", "true");
 		}
 	}