This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 28139c737d SonarQube bug fixes
28139c737d is described below
commit 28139c737d17816447f2bf39f9986578aa94a94f
Author: James Bognar <[email protected]>
AuthorDate: Thu Feb 5 11:40:02 2026 -0500
SonarQube bug fixes
---
.../apache/juneau/commons/inject/BeanCreator2.java | 10 +++++---
.../apache/juneau/commons/reflect/ClassInfo.java | 8 +++---
.../apache/juneau/commons/utils/StringUtils.java | 2 +-
.../urlencoding/UrlEncodingParserSession.java | 10 +++++---
.../main/java/org/apache/juneau/xml/XmlUtils.java | 14 +++++-----
.../apache/juneau/examples/bean/BeanExample.java | 8 +++---
.../apache/juneau/examples/bean/atom/AtomFeed.java | 8 +++---
.../juneau/examples/rest/dto/AtomFeedResource.java | 8 +++---
scripts/push.py | 30 +++++++++++++---------
9 files changed, 59 insertions(+), 39 deletions(-)
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/inject/BeanCreator2.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/inject/BeanCreator2.java
index a36597da50..40cc8f53d4 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/inject/BeanCreator2.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/inject/BeanCreator2.java
@@ -186,6 +186,8 @@ import org.apache.juneau.commons.reflect.*;
@SuppressWarnings("java:S115")
public class BeanCreator2<T> {
+ private static final String CLASSNAME_Autowired = "Autowired";
+
// Argument name constants for assertArgNotNull
private static final String ARG_beanType = "beanType";
private static final String ARG_fallback = "fallback";
@@ -1121,7 +1123,7 @@ public class BeanCreator2<T> {
.filter(x -> x.isAll(NOT_STATIC,
NOT_DEPRECATED, NOT_SYNTHETIC, NOT_BRIDGE))
.filter(x ->
buildMethodNames.contains(x.getNameSimple()))
.filter(x -> opt(x).map(x2 ->
x2.getReturnType()).filter(x2 -> x2.is(beanSubType.inner()) ||
x2.isParentOf(beanSubType)).isPresent()) // Accept methods that return
beanSubType or a parent type of beanSubType
- .filter(x ->
x.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n ->
eqAny(n, "Inject", "Autowired")) ? x.canResolveAllParameters(store2) :
x.getParameterCount() == 0)
+ .filter(x ->
x.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n ->
eqAny(n, "Inject", CLASSNAME_Autowired)) ? x.canResolveAllParameters(store2) :
x.getParameterCount() == 0)
.sorted(methodComparator)
.findFirst();
@@ -1135,7 +1137,7 @@ public class BeanCreator2<T> {
log("Expected beanSubType: %s",
beanSubType.getName());
// Check if method has @Inject annotation
- boolean hasInject =
method.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n
-> eqAny(n, "Inject", "Autowired"));
+ boolean hasInject =
method.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n
-> eqAny(n, "Inject", CLASSNAME_Autowired));
if (hasInject) {
log("Method has @Inject annotation,
resolving parameters from bean store");
} else {
@@ -1167,7 +1169,7 @@ public class BeanCreator2<T> {
.filter(x -> x.isAll(NOT_STATIC,
NOT_DEPRECATED, NOT_SYNTHETIC, NOT_BRIDGE))
.filter(x ->
!buildMethodNames.contains(x.getNameSimple())) // Skip standard build methods
we already checked
.filter(x ->
x.getReturnType().is(beanSubType.inner())) // Must return exact beanSubType,
not parent
- .filter(x ->
x.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n ->
eqAny(n, "Inject", "Autowired")) ? x.canResolveAllParameters(store2) :
x.getParameterCount() == 0)
+ .filter(x ->
x.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n ->
eqAny(n, "Inject", CLASSNAME_Autowired)) ? x.canResolveAllParameters(store2) :
x.getParameterCount() == 0)
.sorted(methodComparator)
.findFirst();
@@ -1578,7 +1580,7 @@ public class BeanCreator2<T> {
var returnType = x.getReturnType();
return returnType.is(beanSubType.inner()) ||
returnType.is(beanType.inner()) || returnType.isParentOf(beanSubType);
})
- .anyMatch(x ->
x.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n ->
eqAny(n, "Inject", "Autowired")) || x.getParameterCount() == 0);
+ .anyMatch(x ->
x.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n ->
eqAny(n, "Inject", CLASSNAME_Autowired)) || x.getParameterCount() == 0);
if (hasBuildMethod) {
log("Builder is valid: has build/create/get method
returning bean type");
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ClassInfo.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ClassInfo.java
index 8cd7b751ab..cd344ad1e7 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ClassInfo.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/reflect/ClassInfo.java
@@ -69,6 +69,8 @@ import org.apache.juneau.commons.lang.*;
@SuppressWarnings({ "unchecked", "rawtypes", "java:S115" })
public class ClassInfo extends ElementInfo implements Annotatable, Type,
Comparable<ClassInfo> {
+ private static final String CLASSNAME_Autowired = "Autowired";
+
// Argument name constants for assertArgNotNull
private static final String ARG_type = "type";
private static final String ARG_pt = "pt";
@@ -2962,13 +2964,13 @@ public class ClassInfo extends ElementInfo implements
Annotatable, Type, Compara
public <T> T inject(T bean, BeanStore beanStore) {
// Inject into fields
getAllFields().stream()
- .filter(x -> x.isNotFinal() &&
x.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n ->
eq(n, "Inject") || eq(n, "Autowired")))
+ .filter(x -> x.isNotFinal() &&
x.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n ->
eq(n, "Inject") || eq(n, CLASSNAME_Autowired)))
.forEach(x -> x.inject(beanStore, bean));
// Inject into methods
getAllMethods().stream()
- .filter(x -> x.isNotAbstract() &&
eq(x.getTypeParameters().length, 0) &&
x.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n ->
eq(n, "Inject") || eq(n, "Autowired")))
- .filter(x -> x.isNotAbstract() &&
eq(x.getTypeParameters().length, 0) &&
x.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n ->
eq(n, "Inject") || eq(n, "Autowired")))
+ .filter(x -> x.isNotAbstract() &&
eq(x.getTypeParameters().length, 0) &&
x.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n ->
eq(n, "Inject") || eq(n, CLASSNAME_Autowired)))
+ .filter(x -> x.isNotAbstract() &&
eq(x.getTypeParameters().length, 0) &&
x.getAnnotations().stream().map(AnnotationInfo::getNameSimple).anyMatch(n ->
eq(n, "Inject") || eq(n, CLASSNAME_Autowired)))
.forEach(x -> x.inject(beanStore, bean));
// Call @PostConstruct methods after all injection is complete
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/StringUtils.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/StringUtils.java
index 60b63cec88..e1fa742979 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/StringUtils.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/StringUtils.java
@@ -49,7 +49,7 @@ import org.apache.juneau.commons.reflect.*;
/**
* Reusable string utility methods.
*/
-@SuppressWarnings("java:S115")
+@SuppressWarnings({"java:S115", "java:S1192"}) // S115: Constant names, S1192:
Duplicated string literals (HTML entities)
public class StringUtils {
// Argument name constants for assertArgNotNull
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java
index 4f02d7b9a0..bbe40a68c2 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java
@@ -48,6 +48,8 @@ import org.apache.juneau.uon.*;
@SuppressWarnings({"unchecked","rawtypes","resource","java:S110"})
public class UrlEncodingParserSession extends UonParserSession {
+ private static final String CONST_value = "_value";
+
/**
* Builder class.
*/
@@ -238,8 +240,8 @@ public class UrlEncodingParserSession extends
UonParserSession {
if (sType.isObject()) {
var m = new JsonMap(this);
parseIntoMap2(r, m, getClassMeta(Map.class,
String.class, Object.class), outer);
- if (m.containsKey("_value"))
- o = m.get("_value");
+ if (m.containsKey(CONST_value))
+ o = m.get(CONST_value);
else
o = cast(m, null, eType);
} else if (sType.isMap()) {
@@ -271,8 +273,8 @@ public class UrlEncodingParserSession extends
UonParserSession {
parseIntoMap2(r, m, getClassMeta(Map.class,
String.class, Object.class), outer);
if (m.containsKey(getBeanTypePropertyName(eType)))
o = cast(m, null, eType);
- else if (m.containsKey("_value"))
- o = convertToType(m.get("_value"), sType);
+ else if (m.containsKey(CONST_value))
+ o = convertToType(m.get(CONST_value), sType);
else if (nn(sType.getProxyInvocationHandler())) {
o = newBeanMap(outer,
sType.inner()).load(m).getBean();
} else {
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 de9ab89298..6e5a9a8c1a 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
@@ -40,6 +40,8 @@ import org.apache.juneau.xml.annotation.*;
@SuppressWarnings("resource")
public class XmlUtils {
+ private static final String CONST_x0000 = "_x0000_";
+
/**
* Prevents instantiation.
*/
@@ -140,7 +142,7 @@ public class XmlUtils {
@SuppressWarnings("java:S3776")
public static Writer encodeAttrName(Writer w, Object value) throws
IOException {
if (value == null)
- return w.append("_x0000_");
+ return w.append(CONST_x0000);
var s = value.toString();
if (needsAttrNameEncoding(s)) {
@@ -189,7 +191,7 @@ public class XmlUtils {
public static Writer encodeAttrValue(Writer w, Object value, boolean
trim) {
try {
if (value == null)
- return w.append("_x0000_");
+ return w.append(CONST_x0000);
var s = value.toString();
if (s.isEmpty())
return w;
@@ -229,7 +231,7 @@ public class XmlUtils {
*/
public static String encodeElementName(Object value) {
if (value == null)
- return "_x0000_";
+ return CONST_x0000;
var s = value.toString();
if (s.isEmpty())
return "_xE000_";
@@ -256,7 +258,7 @@ public class XmlUtils {
public static Writer encodeElementName(Writer w, Object value) {
try {
if (value == null)
- return w.append("_x0000_");
+ return w.append(CONST_x0000);
var s = value.toString();
if (needsElementNameEncoding(s))
return encodeElementNameInner(w, s);
@@ -290,7 +292,7 @@ public class XmlUtils {
try {
if (value == null)
- return w.append("_x0000_");
+ return w.append(CONST_x0000);
var s = value.toString();
if (s.isEmpty())
return w.append("_xE000_");
@@ -330,7 +332,7 @@ public class XmlUtils {
*/
public static String escapeText(Object value) {
if (value == null)
- return "_x0000_";
+ return CONST_x0000;
var s = value.toString();
try {
diff --git
a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/bean/BeanExample.java
b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/bean/BeanExample.java
index 53a2e800df..e074ecf77a 100644
---
a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/bean/BeanExample.java
+++
b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/bean/BeanExample.java
@@ -34,6 +34,8 @@ import org.apache.juneau.json.*;
*/
public class BeanExample {
+ private static final String CONST_timestamp = "2016-12-31T05:02:03Z";
+
/**
* DTO Samples
*
@@ -106,7 +108,7 @@ public class BeanExample {
html = Json5Serializer.DEFAULT.serialize(mainJsp);
var feed =
- feed("tag:foo.org", "Title", "2016-12-31T05:02:03Z")
+ feed("tag:foo.org", "Title", CONST_timestamp)
.setSubtitle(text("html").setText("Subtitle"))
.setLinks(
link("alternate", "text/html",
"http://foo.org/").setHreflang("en"),
@@ -116,12 +118,12 @@ public class BeanExample {
generator("Example
Toolkit").setUri("http://www.foo.org/").setVersion("1.0")
)
.setEntries(
- entry("tag:foo.org", "Title",
"2016-12-31T05:02:03Z")
+ entry("tag:foo.org", "Title", CONST_timestamp)
.setLinks(
link("alternate", "text/html",
"http://foo.org/2005/04/02/atom"),
link("enclosure", "audio/mpeg",
"http://foo.org/audio/foobar.mp3").setLength(1337)
)
- .setPublished("2016-12-31T05:02:03Z")
+ .setPublished(CONST_timestamp)
.setAuthors(
person("John Smith").setUri(new
URI("http://foo.org/")).setEmail("[email protected]")
)
diff --git
a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/bean/atom/AtomFeed.java
b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/bean/atom/AtomFeed.java
index e991daa326..99634d5fb5 100644
---
a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/bean/atom/AtomFeed.java
+++
b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/bean/atom/AtomFeed.java
@@ -29,6 +29,8 @@ import org.apache.juneau.bean.atom.*;
@SuppressWarnings("java:S1118")
public class AtomFeed {
+ private static final String CONST_timestamp = "2016-12-31T05:02:03Z";
+
/**
* @return A sample Atom feed.
* @throws URISyntaxException Won't happen
@@ -36,7 +38,7 @@ public class AtomFeed {
public static Feed getAtomFeed() throws URISyntaxException {
return
- feed("tag:foo.org", "Title", "2016-12-31T05:02:03Z")
+ feed("tag:foo.org", "Title", CONST_timestamp)
.setSubtitle(text("html").setText("Subtitle"))
.setLinks(
link("alternate", "text/html",
"http://foo.org/").setHreflang("en"),
@@ -46,12 +48,12 @@ public class AtomFeed {
generator("Example
Toolkit").setUri("http://www.foo.org/").setVersion("1.0")
)
.setEntries(
- entry("tag:foo.org", "Title",
"2016-12-31T05:02:03Z")
+ entry("tag:foo.org", "Title", CONST_timestamp)
.setLinks(
link("alternate", "text/html",
"http://foo.org/2005/04/02/atom"),
link("enclosure", "audio/mpeg",
"http://foo.org/audio/foobar.mp3").setLength(1337)
)
- .setPublished("2016-12-31T05:02:03Z")
+ .setPublished(CONST_timestamp)
.setAuthors(
person("John Smith").setUri(new
URI("http://foo.org/")).setEmail("[email protected]")
)
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 df0189ca0f..29eb66ed97 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
@@ -68,6 +68,8 @@ import org.apache.juneau.serializer.annotation.*;
public class AtomFeedResource extends BasicRestServlet {
private static final long serialVersionUID = 1L;
+ private static final String CONST_timestamp = "2016-12-31T05:02:03Z";
+
private Feed feed; // The root resource object
/**
@@ -85,7 +87,7 @@ public class AtomFeedResource extends BasicRestServlet {
public void init() {
try {
feed =
- feed("tag:foo.org", "Title",
"2016-12-31T05:02:03Z")
+ feed("tag:foo.org", "Title", CONST_timestamp)
.setSubtitle(text("html").setText("Subtitle"))
.setLinks(
link("alternate", "text/html",
"http://foo.org/").setHreflang("en"),
@@ -95,12 +97,12 @@ public class AtomFeedResource extends BasicRestServlet {
generator("Example
Toolkit").setUri("http://www.foo.org/").setVersion("1.0")
)
.setEntries(
- entry("tag:foo.org", "Title",
"2016-12-31T05:02:03Z")
+ entry("tag:foo.org", "Title",
CONST_timestamp)
.setLinks(
link("alternate", "text/html",
"http://foo.org/2005/04/02/atom"),
link("enclosure", "audio/mpeg",
"http://foo.org/audio/foobar.mp3").setLength(1337)
)
- .setPublished("2016-12-31T05:02:03Z")
+ .setPublished(CONST_timestamp)
.setAuthors(
person("John Smith").setUri(new
URI("http://foo.org/")).setEmail("[email protected]")
)
diff --git a/scripts/push.py b/scripts/push.py
index 37ddabd4af..b01ca4c591 100755
--- a/scripts/push.py
+++ b/scripts/push.py
@@ -28,6 +28,12 @@ Usage: python3 push.py "commit message"
python3 push.py "commit message" --skip-tests
"""
+# Sound file paths
+MACOS_SUCCESS_SOUND = "/System/Library/Sounds/Glass.aiff"
+MACOS_FAILURE_SOUND = "/System/Library/Sounds/Basso.aiff"
+LINUX_SUCCESS_SOUND = "/usr/share/sounds/freedesktop/stereo/complete.oga"
+LINUX_FAILURE_SOUND = "/usr/share/sounds/freedesktop/stereo/dialog-error.oga"
+
import argparse
import os
import platform
@@ -85,10 +91,10 @@ def play_sound(success=True):
if system == "Darwin": # macOS
if success:
# Success sound
- sound_path = "/System/Library/Sounds/Glass.aiff"
+ sound_path = MACOS_SUCCESS_SOUND
else:
# Failure sound
- sound_path = "/System/Library/Sounds/Basso.aiff"
+ sound_path = MACOS_FAILURE_SOUND
if os.path.exists(sound_path):
subprocess.run(
@@ -102,7 +108,7 @@ def play_sound(success=True):
# Try to play a beep or use speaker-test
try:
subprocess.run(
- ["paplay",
"/usr/share/sounds/freedesktop/stereo/complete.oga"],
+ ["paplay", LINUX_SUCCESS_SOUND],
capture_output=True,
timeout=5
)
@@ -116,7 +122,7 @@ def play_sound(success=True):
else:
try:
subprocess.run(
- ["paplay",
"/usr/share/sounds/freedesktop/stereo/dialog-error.oga"],
+ ["paplay", LINUX_FAILURE_SOUND],
capture_output=True,
timeout=5
)
@@ -151,10 +157,10 @@ def play_sound(success=True):
if system == "Darwin": # macOS
if success:
# Success sound
- sound_path = "/System/Library/Sounds/Glass.aiff"
+ sound_path = MACOS_SUCCESS_SOUND
else:
# Failure sound
- sound_path = "/System/Library/Sounds/Basso.aiff"
+ sound_path = MACOS_FAILURE_SOUND
if os.path.exists(sound_path):
subprocess.run(
@@ -168,7 +174,7 @@ def play_sound(success=True):
# Try to play a beep or use speaker-test
try:
subprocess.run(
- ["paplay",
"/usr/share/sounds/freedesktop/stereo/complete.oga"],
+ ["paplay", LINUX_SUCCESS_SOUND],
capture_output=True,
timeout=5
)
@@ -182,7 +188,7 @@ def play_sound(success=True):
else:
try:
subprocess.run(
- ["paplay",
"/usr/share/sounds/freedesktop/stereo/dialog-error.oga"],
+ ["paplay", LINUX_FAILURE_SOUND],
capture_output=True,
timeout=5
)
@@ -233,10 +239,10 @@ def play_sound(success=True):
if system == "Darwin": # macOS
if success:
# Success sound
- sound_path = "/System/Library/Sounds/Glass.aiff"
+ sound_path = MACOS_SUCCESS_SOUND
else:
# Failure sound
- sound_path = "/System/Library/Sounds/Basso.aiff"
+ sound_path = MACOS_FAILURE_SOUND
if os.path.exists(sound_path):
subprocess.run(
@@ -250,7 +256,7 @@ def play_sound(success=True):
# Try to play a beep or use speaker-test
try:
subprocess.run(
- ["paplay",
"/usr/share/sounds/freedesktop/stereo/complete.oga"],
+ ["paplay", LINUX_SUCCESS_SOUND],
capture_output=True,
timeout=5
)
@@ -264,7 +270,7 @@ def play_sound(success=True):
else:
try:
subprocess.run(
- ["paplay",
"/usr/share/sounds/freedesktop/stereo/dialog-error.oga"],
+ ["paplay", LINUX_FAILURE_SOUND],
capture_output=True,
timeout=5
)