gnodet-bot commented on code in PR #13636:
URL: https://github.com/apache/maven/pull/13636#discussion_r4351103122


##########
impl/maven-core/src/main/java/org/apache/maven/plugin/internal/V4MojoConfigurator.java:
##########
@@ -0,0 +1,382 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugin.internal;
+
+import java.io.File;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.RecordComponent;
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.maven.api.xml.XmlNode;
+import org.apache.maven.plugin.PluginConfigurationException;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import 
org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
+import 
org.codehaus.plexus.component.configurator.expression.TypeAwareExpressionEvaluator;
+
+/** Configures a Maven 4 mojo directly from the public Maven XML model. */
+public final class V4MojoConfigurator {
+    private static final Object NOT_SCALAR = new Object();
+
+    private final ExpressionEvaluator evaluator;
+    private final ClassLoader classLoader;
+    private final PluginDescriptor pluginDescriptor;
+
+    public V4MojoConfigurator(
+            ExpressionEvaluator evaluator, ClassLoader classLoader, 
PluginDescriptor pluginDescriptor) {
+        this.evaluator = evaluator;
+        this.classLoader = classLoader;
+        this.pluginDescriptor = pluginDescriptor;
+    }
+
+    public void configure(Object mojo, XmlNode configuration) throws 
PluginConfigurationException {
+        if (configuration == null) {
+            return;
+        }
+        for (XmlNode child : configuration.children()) {
+            try {
+                set(mojo, child.name(), child);
+            } catch (Exception e) {
+                throw new PluginConfigurationException(
+                        pluginDescriptor,
+                        "Unable to configure '" + child.name() + "' on "
+                                + mojo.getClass().getName(),
+                        e);
+            }
+        }
+    }
+
+    private void set(Object bean, String name, XmlNode node) throws Exception {
+        String title = Character.toUpperCase(name.charAt(0)) + 
name.substring(1);

Review Comment:
   ⚠️ **`name.charAt(0)` throws `StringIndexOutOfBoundsException` for empty 
element names.**
   
   XML schema prevents empty element names in well-formed XML, but `XmlNode` 
can be constructed programmatically with an empty string. 
`Character.toUpperCase("".charAt(0))` throws `StringIndexOutOfBoundsException`. 
Add a guard:
   
   ```suggestion
           if (name.isEmpty()) {
               throw new NoSuchFieldException("<empty element name>");
           }
           String title = Character.toUpperCase(name.charAt(0)) + 
name.substring(1);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to