This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new b6a7a46 GROOVY-9451: Unable to access static getter method as field
b6a7a46 is described below
commit b6a7a46799e505d1f3ebd2a28e9cb67be52ea850
Author: Paul King <[email protected]>
AuthorDate: Mon Mar 9 23:33:20 2020 +1000
GROOVY-9451: Unable to access static getter method as field
---
.../java/org/apache/groovy/util/BeanUtils.java | 4 +--
.../org/apache/groovy/util/BeanUtilsTest.groovy | 33 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/groovy/util/BeanUtils.java
b/src/main/java/org/apache/groovy/util/BeanUtils.java
index 5f3669b..d95c8ea 100644
--- a/src/main/java/org/apache/groovy/util/BeanUtils.java
+++ b/src/main/java/org/apache/groovy/util/BeanUtils.java
@@ -36,8 +36,8 @@ public class BeanUtils {
*/
public static String decapitalize(final String property) {
if (property == null || property.isEmpty()) return property;
- if (property.length() > 2 && isUpperCase(property.charAt(1)) &&
isUpperCase(property.charAt(0))) return property;
- final char c[] = property.toCharArray();
+ if (property.length() >= 2 && isUpperCase(property.charAt(1)) &&
isUpperCase(property.charAt(0))) return property;
+ final char[] c = property.toCharArray();
c[0] = Character.toLowerCase(c[0]);
return new String(c);
}
diff --git a/src/test/org/apache/groovy/util/BeanUtilsTest.groovy
b/src/test/org/apache/groovy/util/BeanUtilsTest.groovy
new file mode 100644
index 0000000..78e612b
--- /dev/null
+++ b/src/test/org/apache/groovy/util/BeanUtilsTest.groovy
@@ -0,0 +1,33 @@
+/*
+ * 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.groovy.util
+
+import org.junit.Test
+import static org.apache.groovy.util.BeanUtils.decapitalize
+
+class BeanUtilsTest {
+ @Test
+ void testJavaBeanDecapitalize() {
+ assert decapitalize('Prop') == 'prop'
+ assert decapitalize('prop') == 'prop'
+ assert decapitalize('SomeProp') == 'someProp'
+ assert decapitalize('DB') == 'DB' // GROOVY-9451
+ assert decapitalize('XML') == 'XML'
+ }
+}
\ No newline at end of file