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 e37249c4c7 Add SuppressWarnings for Optional null-check issues and
update format in AI.md
e37249c4c7 is described below
commit e37249c4c79ea29e842b5ca6b20e2c05ded141be
Author: James Bognar <[email protected]>
AuthorDate: Mon Feb 9 11:59:52 2026 -0500
Add SuppressWarnings for Optional null-check issues and update format in
AI.md
---
AI.md | 9 ++++++++-
.../org/apache/juneau/commons/function/ResettableSupplier.java | 9 +++++++++
.../main/java/org/apache/juneau/commons/settings/Settings.java | 6 ++++++
.../src/main/java/org/apache/juneau/commons/utils/Utils.java | 3 +++
.../src/main/java/org/apache/juneau/rest/RestResponse.java | 3 +++
5 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/AI.md b/AI.md
index b315ae3d1b..6cbb9b6eec 100644
--- a/AI.md
+++ b/AI.md
@@ -17,7 +17,14 @@ This document outlines the rules, guidelines, and best
practices that AI assista
### Task Interpretation Commands
- **"make a plan"** or **"come up with a plan"** - When the user asks to make
a plan for something, provide a summary of suggested changes only. **Do NOT
make actual code changes**. The plan should outline what needs to be done, but
implementation should wait for explicit user approval.
-- **"suppress warnings"** or **"suppress issues"** - When the user asks to
suppress warnings or issues that appear to refer to SonarLint/SonarQube issues,
add `@SuppressWarnings("java:Sxxx")` annotations to the appropriate class or
method level. Use the specific rule ID from the warning (e.g., `java:S100`,
`java:S115`, `java:S116`). Apply class-level suppressions when multiple
methods/fields are affected, or method-level suppressions for specific methods.
+- **"suppress warnings"** or **"suppress issues"** - When the user asks to
suppress warnings or issues that appear to refer to SonarLint/SonarQube issues,
add `@SuppressWarnings` annotations to the appropriate class or method level.
Use the specific rule ID from the warning (e.g., `java:S100`, `java:S115`,
`java:S116`). Apply class-level suppressions when multiple methods/fields are
affected, or method-level suppressions for specific methods.
+- **SuppressWarnings Format**: When adding `@SuppressWarnings` annotations,
use this format:
+ ```java
+ @SuppressWarnings({
+ "java:Sxxx" // Short reason why
+ })
+ ```
+ Use the multi-line format with curly braces and include a brief comment
explaining why the suppression is needed.
### Script Shortcut Commands
- **"start docs"** or **"start docusaurus"** - Runs
`scripts/start-docusaurus.py`
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/function/ResettableSupplier.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/function/ResettableSupplier.java
index 63a80d932e..f1591873c2 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/function/ResettableSupplier.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/function/ResettableSupplier.java
@@ -101,6 +101,9 @@ public class ResettableSupplier<T> implements
OptionalSupplier<T> {
* @return The cached or newly computed value.
*/
@Override
+ @SuppressWarnings({
+ "java:S2789" // null check on Optional is intentional -
AtomicReference uses null to represent "not initialized" state
+ })
public T get() {
Optional<T> h = cache.get();
if (h == null) {
@@ -167,6 +170,9 @@ public class ResettableSupplier<T> implements
OptionalSupplier<T> {
*
* @return <jk>true</jk> if the supplier has not been called yet,
<jk>false</jk> if a value has been cached.
*/
+ @SuppressWarnings({
+ "java:S2789" // null check on Optional is intentional -
AtomicReference uses null to represent "not initialized" state
+ })
public boolean isSupplied() {
return cache.get() == null;
}
@@ -180,6 +186,9 @@ public class ResettableSupplier<T> implements
OptionalSupplier<T> {
*
* @return A new {@link ResettableSupplier} instance with the same
state as this supplier.
*/
+ @SuppressWarnings({
+ "java:S2789" // null check on Optional is intentional -
AtomicReference uses null to represent "not initialized" state
+ })
public ResettableSupplier<T> copy() {
Optional<T> o = cache.get();
if (o == null)
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/Settings.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/Settings.java
index 74f601d4ac..ab0367cbab 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/Settings.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/Settings.java
@@ -165,6 +165,9 @@ public class Settings {
* Returns properties for this Settings object itself.
* Note that these are initialized at startup and not changeable
through System.setProperty().
*/
+ @SuppressWarnings({
+ "java:S2789" // null check on Optional is intentional -
SettingSource.get() returns null if key doesn't exist, Optional.empty() if key
exists with null value
+ })
private static final Optional<String> initProperty(String property) {
var v = SYSTEM_PROPERTY_SOURCE.get(property);
if (v != null)
@@ -362,6 +365,9 @@ public class Settings {
* @param name The property name. Must not be <jk>null</jk>.
* @return A {@link StringSetting} that provides the property value, or
<jk>null</jk> if not found.
*/
+ @SuppressWarnings({
+ "java:S2789" // null check on Optional is intentional -
SettingStore.get()/SettingSource.get() return null if key doesn't exist,
Optional.empty() if key exists with null value
+ })
public StringSetting get(String name) {
assertArgNotNull(ARG_name, name);
return new StringSetting(this, () -> {
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/Utils.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/Utils.java
index bf806775d9..f2741f975a 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/Utils.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/Utils.java
@@ -1407,6 +1407,9 @@ public class Utils {
* @return A thread-safe memoizing wrapper around the supplier.
* @throws NullPointerException if supplier is <jk>null</jk>.
*/
+ @SuppressWarnings({
+ "java:S2789" // null check on Optional is intentional -
AtomicReference uses null to represent "not initialized" state
+ })
public static <T> OptionalSupplier<T> mem(Supplier<T> supplier) {
assertArgNotNull(ARG_supplier, supplier);
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
index f51331a9b9..0f88bb91c8 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestResponse.java
@@ -809,6 +809,9 @@ public class RestResponse extends
HttpServletResponseWrapper {
return this;
}
+ @SuppressWarnings({
+ "java:S2789" // null check on Optional is intentional - content
field can be null if never set
+ })
private Object getRawOutput() { return content == null ? null :
content.orElse(null); }
private FinishablePrintWriter getWriter(boolean raw, boolean autoflush)
throws NotAcceptable, IOException {