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

veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git

commit d2bc8ad1ff3c74a28f6be5b791f0e42724ab9eda
Author: Andreas Veithen-Knowles <[email protected]>
AuthorDate: Thu Jun 11 06:19:10 2026 +0000

    Automatically apply @StringOrCharacterData in type casts
---
 .../StringOrCharacterDataAnnotatedTypeFactory.java | 24 ++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git 
a/buildutils/stringorcharacterdata-checker/src/main/java/org/apache/axiom/checker/StringOrCharacterDataAnnotatedTypeFactory.java
 
b/buildutils/stringorcharacterdata-checker/src/main/java/org/apache/axiom/checker/StringOrCharacterDataAnnotatedTypeFactory.java
index 56355a3a6..dc04f06fe 100644
--- 
a/buildutils/stringorcharacterdata-checker/src/main/java/org/apache/axiom/checker/StringOrCharacterDataAnnotatedTypeFactory.java
+++ 
b/buildutils/stringorcharacterdata-checker/src/main/java/org/apache/axiom/checker/StringOrCharacterDataAnnotatedTypeFactory.java
@@ -19,6 +19,7 @@
 package org.apache.axiom.checker;
 
 import com.sun.source.tree.BinaryTree;
+import com.sun.source.tree.TypeCastTree;
 import java.lang.annotation.Annotation;
 import java.util.LinkedHashSet;
 import java.util.Set;
@@ -70,10 +71,16 @@ public class StringOrCharacterDataAnnotatedTypeFactory 
extends BaseAnnotatedType
 
     /**
      * Runs after {@link 
org.checkerframework.framework.type.treeannotator.PropagationTreeAnnotator}
-     * and re-applies {@code @StringOrCharacterData} to binary expressions 
whose result type is
-     * {@link String}. This is necessary because {@code 
PropagationTreeAnnotator} computes the LUB
-     * of the operand qualifiers for binary {@code +}, so a string 
concatenation such as {@code
-     * "literal " + intValue} would otherwise produce {@code 
@UnknownCharacterDataType String}.
+     * and re-applies {@code @StringOrCharacterData} to:
+     *
+     * <ul>
+     *   <li>Binary expressions whose result type is {@link String}. This is 
necessary because
+     *       {@code PropagationTreeAnnotator} computes the LUB of the operand 
qualifiers for binary
+     *       {@code +}, so a string concatenation such as {@code "literal " + 
intValue} would
+     *       otherwise produce {@code @UnknownCharacterDataType String}.
+     *   <li>Type cast expressions whose target type is {@link String} or 
implements {@link
+     *       org.apache.axiom.core.stream.CharacterData}.
+     * </ul>
      */
     private class StringOrCharacterDataTreeAnnotator extends TreeAnnotator {
 
@@ -88,6 +95,15 @@ public class StringOrCharacterDataAnnotatedTypeFactory 
extends BaseAnnotatedType
             }
             return null;
         }
+
+        @Override
+        public Void visitTypeCast(TypeCastTree node, AnnotatedTypeMirror type) 
{
+            TypeMirror underlyingType = type.getUnderlyingType();
+            if (TypesUtils.isString(underlyingType) || 
isCharacterData(underlyingType)) {
+                type.replaceAnnotation(STRING_OR_CHARACTER_DATA);
+            }
+            return null;
+        }
     }
 
     @Override

Reply via email to