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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new de6c0a2592c Remove deprecated Class.newInstance usage in StaxProcessor 
(#11751)
de6c0a2592c is described below

commit de6c0a2592ceb8aad2f64fe54e3f28ed4ff94a08
Author: AurĂ©lien Pupier <[email protected]>
AuthorDate: Wed Oct 18 11:39:44 2023 +0200

    Remove deprecated Class.newInstance usage in StaxProcessor (#11751)
    
    Javadoc explanation:
    ```
    Deprecated.
    This method propagates any exception thrown by the nullary constructor,
    including a checked exception. Use of this method effectively bypasses
    the compile-time exception checking that would otherwise be performed by
    the compiler. The Constructor.newInstance method avoids this problem by
    wrapping any exception thrown by the constructor in a (checked)
    InvocationTargetException.
    
    The call
    
     clazz.newInstance()
    
    can be replaced by
    
     clazz.getDeclaredConstructor().newInstance()
    
    The latter sequence of calls is inferred to be able to throw the
    additional exception types InvocationTargetException and
    NoSuchMethodException. Both of these exception types are subclasses of
    ReflectiveOperationException.
    ```
    
    Signed-off-by: AurĂ©lien Pupier <[email protected]>
---
 .../src/main/java/org/apache/camel/component/stax/StAXProcessor.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java
 
b/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java
index b9cf046ba04..38fbb1f5ff6 100644
--- 
a/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java
+++ 
b/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java
@@ -54,7 +54,7 @@ public class StAXProcessor implements Processor {
             StaxStreamXMLReader reader = new StaxStreamXMLReader(stream);
             ContentHandler handler;
             if (this.contentHandlerClass != null) {
-                handler = this.contentHandlerClass.newInstance();
+                handler = 
this.contentHandlerClass.getDeclaredConstructor().newInstance();
             } else {
                 handler = this.contentHandler;
             }

Reply via email to