Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Locale;
import java.util.Map;

public final class JavaBeanSerializeUtil {
Expand Down Expand Up @@ -306,7 +307,7 @@ private static void deserializeInternal(
}

private static Method getSetterMethod(Class<?> cls, String property, Class<?> valueCls) {
String name = "set" + property.substring(0, 1).toUpperCase() + property.substring(1);
String name = "set" + property.substring(0, 1).toUpperCase(Locale.ROOT) + property.substring(1);
Method method = null;
try {
method = cls.getMethod(name, valueCls);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
Expand Down Expand Up @@ -750,7 +751,7 @@ private IllegalStateException findException(String name) {

int i = 1;
for (Map.Entry<String, IllegalStateException> entry : exceptions.entrySet()) {
if (entry.getKey().toLowerCase().startsWith(name.toLowerCase())) {
if (entry.getKey().toLowerCase(Locale.ROOT).startsWith(name.toLowerCase(Locale.ROOT))) {
if (i == 1) {
buf.append(", possible causes: ");
}
Expand Down Expand Up @@ -922,7 +923,7 @@ private void initExtension(T instance) {
*/
private String getSetterProperty(Method method) {
return method.getName().length() > 3
? method.getName().substring(3, 4).toLowerCase()
? method.getName().substring(3, 4).toLowerCase(Locale.ROOT)
+ method.getName().substring(4)
: "";
}
Expand Down Expand Up @@ -1428,7 +1429,7 @@ private String findAnnotationName(Class<?> clazz) {
if (name.endsWith(type.getSimpleName())) {
name = name.substring(0, name.length() - type.getSimpleName().length());
}
return name.toLowerCase();
return name.toLowerCase(Locale.ROOT);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.dubbo.rpc.model.ScopeModelAware;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
Expand Down Expand Up @@ -70,7 +71,7 @@ public Map<String, String> getExtraAttributes(Map<String, String> params) {
String value = ConfigurationUtils.getProperty(applicationModel, key);
if (value != null) {
// since 3.2
parameters.put(key.toLowerCase(), value);
parameters.put(key.toLowerCase(Locale.ROOT), value);
// upper-case key kept for compatibility
parameters.put(key, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.function.Predicate;

Expand Down Expand Up @@ -429,7 +430,7 @@ static String extractFieldName(Method method) {
}

if (StringUtils.isNotEmpty(fieldName)) {
fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);
fieldName = fieldName.substring(0, 1).toLowerCase(Locale.ROOT) + fieldName.substring(1);
}

return fieldName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -267,11 +268,11 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
String methodName = method.getName();
Object value = null;
if (methodName.length() > 3 && methodName.startsWith("get")) {
value = map.get(methodName.substring(3, 4).toLowerCase() + methodName.substring(4));
value = map.get(methodName.substring(3, 4).toLowerCase(Locale.ROOT) + methodName.substring(4));
} else if (methodName.length() > 2 && methodName.startsWith("is")) {
value = map.get(methodName.substring(2, 3).toLowerCase() + methodName.substring(3));
value = map.get(methodName.substring(2, 3).toLowerCase(Locale.ROOT) + methodName.substring(3));
} else {
value = map.get(methodName.substring(0, 1).toLowerCase() + methodName.substring(1));
value = map.get(methodName.substring(0, 1).toLowerCase(Locale.ROOT) + methodName.substring(1));
}
if (value instanceof Map<?, ?> && !Map.class.isAssignableFrom(method.getReturnType())) {
value = realize0(value, method.getReturnType(), null, new IdentityHashMap<>());
Expand Down Expand Up @@ -733,7 +734,7 @@ private static Object getDefaultValue(Class<?> parameterType) {
}

private static Method getSetterMethod(Class<?> cls, String property, Class<?> valueCls) {
String name = "set" + property.substring(0, 1).toUpperCase() + property.substring(1);
String name = "set" + property.substring(0, 1).toUpperCase(Locale.ROOT) + property.substring(1);
Method method = NAME_METHODS_CACHE.get(cls.getName() + "." + name + "(" + valueCls.getName() + ")");
if (method == null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -1102,11 +1103,11 @@ public static boolean isBeanPropertyReadMethod(Method method) {
public static String getPropertyNameFromBeanReadMethod(Method method) {
if (isBeanPropertyReadMethod(method)) {
if (method.getName().startsWith("get")) {
return method.getName().substring(3, 4).toLowerCase()
return method.getName().substring(3, 4).toLowerCase(Locale.ROOT)
+ method.getName().substring(4);
}
if (method.getName().startsWith("is")) {
return method.getName().substring(2, 3).toLowerCase()
return method.getName().substring(2, 3).toLowerCase(Locale.ROOT)
+ method.getName().substring(3);
}
}
Expand All @@ -1125,7 +1126,7 @@ public static boolean isBeanPropertyWriteMethod(Method method) {

public static String getPropertyNameFromBeanWriteMethod(Method method) {
if (isBeanPropertyWriteMethod(method)) {
return method.getName().substring(3, 4).toLowerCase()
return method.getName().substring(3, 4).toLowerCase(Locale.ROOT)
+ method.getName().substring(4);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
Expand Down Expand Up @@ -944,7 +945,7 @@ public static String camelToSplitName(String camelName, String split) {
if (!isWord(camelName)) {
// convert Ab-Cd-Ef to ab-cd-ef
if (isSplitCase(camelName, split.charAt(0))) {
return camelName.toLowerCase();
return camelName.toLowerCase(Locale.ROOT);
}
// not camel case
return camelName;
Expand All @@ -968,7 +969,7 @@ public static String camelToSplitName(String camelName, String split) {
buf.append(ch);
}
}
return buf == null ? camelName.toLowerCase() : buf.toString().toLowerCase();
return buf == null ? camelName.toLowerCase(Locale.ROOT) : buf.toString().toLowerCase(Locale.ROOT);
}

private static boolean isSplitCase(String str, char separator) {
Expand Down Expand Up @@ -1002,15 +1003,17 @@ private static boolean isWord(char ch) {
* @return
*/
public static String snakeToSplitName(String snakeName, String split) {
String lowerCase = snakeName.toLowerCase();
String lowerCase = snakeName.toLowerCase(Locale.ROOT);
if (isSnakeCase(snakeName)) {
return replace(lowerCase, "_", split);
}
return snakeName;
}

protected static boolean isSnakeCase(String str) {
return str.contains("_") || str.equals(str.toLowerCase()) || str.equals(str.toUpperCase());
return str.contains("_")
|| str.equals(str.toLowerCase(Locale.ROOT))
|| str.equals(str.toUpperCase(Locale.ROOT));
}

/**
Expand Down Expand Up @@ -1053,11 +1056,11 @@ public static String trim(String str) {
}

public static String toURLKey(String key) {
return key.toLowerCase().replaceAll(SEPARATOR_REGEX, HIDE_KEY_PREFIX);
return key.toLowerCase(Locale.ROOT).replaceAll(SEPARATOR_REGEX, HIDE_KEY_PREFIX);
}

public static String toOSStyleKey(String key) {
key = key.toUpperCase().replaceAll(DOT_REGEX, UNDERLINE_SEPARATOR);
key = key.toUpperCase(Locale.ROOT).replaceAll(DOT_REGEX, UNDERLINE_SEPARATOR);
if (!key.startsWith("DUBBO_")) {
key = "DUBBO_" + key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -272,26 +273,27 @@ private static void appendParameters0(

protected static String extractPropertyName(String setter) {
String propertyName = setter.substring("set".length());
propertyName = propertyName.substring(0, 1).toLowerCase() + propertyName.substring(1);
propertyName = propertyName.substring(0, 1).toLowerCase(Locale.ROOT) + propertyName.substring(1);
return propertyName;
}

private static String calculatePropertyToGetter(String name) {
return "get" + name.substring(0, 1).toUpperCase() + name.substring(1);
return "get" + name.substring(0, 1).toUpperCase(Locale.ROOT) + name.substring(1);
}

private static String calculatePropertyToSetter(String name) {
return "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
return "set" + name.substring(0, 1).toUpperCase(Locale.ROOT) + name.substring(1);
}

private static String calculatePropertyFromGetter(String name) {
int i = name.startsWith("get") ? 3 : 2;
return StringUtils.camelToSplitName(name.substring(i, i + 1).toLowerCase() + name.substring(i + 1), ".");
return StringUtils.camelToSplitName(
name.substring(i, i + 1).toLowerCase(Locale.ROOT) + name.substring(i + 1), ".");
}

private static String calculateAttributeFromGetter(String getter) {
int i = getter.startsWith("get") ? 3 : 2;
return getter.substring(i, i + 1).toLowerCase() + getter.substring(i + 1);
return getter.substring(i, i + 1).toLowerCase(Locale.ROOT) + getter.substring(i + 1);
}

private static void invokeSetParameters(Class c, Object o, Map map) {
Expand Down Expand Up @@ -979,7 +981,8 @@ private void invokeSetParameters(Map<String, String> values, Object obj) {

private boolean isIgnoredAttribute(Class<?> clazz, String propertyName) {
Method getter = null;
String capitalizePropertyName = propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
String capitalizePropertyName =
propertyName.substring(0, 1).toUpperCase(Locale.ROOT) + propertyName.substring(1);
try {
getter = clazz.getMethod("get" + capitalizePropertyName);
} catch (NoSuchMethodException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -121,7 +122,7 @@ public void initialize() throws IllegalStateException {
String configModeStr = (String) configuration.getProperty(ConfigKeys.DUBBO_CONFIG_MODE);
try {
if (StringUtils.hasText(configModeStr)) {
this.configMode = ConfigMode.valueOf(configModeStr.toUpperCase());
this.configMode = ConfigMode.valueOf(configModeStr.toUpperCase(Locale.ROOT));
}
} catch (Exception e) {
String msg = "Illegal '" + ConfigKeys.DUBBO_CONFIG_MODE + "' config value [" + configModeStr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -56,6 +57,23 @@ void testSerialize_Primitive_NUll() {
Assertions.assertNull(descriptor);
}

// In the Turkish locale "i".toUpperCase() is the dotted "İ", so "setİnfoProfile" was looked up.
@Test
void testDeserializeBeanUnderTurkishLocale() {
PersonInfo personInfo = new PersonInfo();
personInfo.setName("dubbo");
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(BigPerson.class.getName(), JavaBeanDescriptor.TYPE_BEAN);
descriptor.setProperty("infoProfile", personInfo);
Locale defaultLocale = Locale.getDefault();
Locale.setDefault(Locale.forLanguageTag("tr-TR"));
try {
BigPerson person = (BigPerson) JavaBeanSerializeUtil.deserialize(descriptor);
Assertions.assertSame(personInfo, person.getInfoProfile());
} finally {
Locale.setDefault(defaultLocale);
}
}

@Test
void testDeserialize_Primitive() {
JavaBeanDescriptor descriptor = new JavaBeanDescriptor(long.class.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
*/
package org.apache.dubbo.common.utils;

import org.apache.dubbo.rpc.model.person.BigPerson;

import java.lang.reflect.Method;
import java.util.Locale;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -118,6 +121,19 @@ void testExtractFieldName() throws Exception {
Assertions.assertEquals("fieldName3", MethodUtils.extractFieldName(m7));
}

// In the Turkish locale "I".toLowerCase() is the dotless "ı".
@Test
void testExtractFieldNameUnderTurkishLocale() throws Exception {
Locale defaultLocale = Locale.getDefault();
Locale.setDefault(Locale.forLanguageTag("tr-TR"));
try {
Method getter = BigPerson.class.getMethod("getInfoProfile");
Assertions.assertEquals("infoProfile", MethodUtils.extractFieldName(getter));
} finally {
Locale.setDefault(defaultLocale);
}
}

public class MethodFieldTestClazz {
public String is() {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
Expand Down Expand Up @@ -296,6 +297,23 @@ void testMapToInterface() throws Exception {
assertTrue(message.isUrgent());
}

// In the Turkish locale "I".toLowerCase() is the dotless "ı", so getId() looked up "ıd" in the map.
@Test
void testMapToInterfaceUnderTurkishLocale() {
Map<String, Object> map = new HashMap<>();
map.put("id", "T-1");
map.put("important", true);
Locale defaultLocale = Locale.getDefault();
Locale.setDefault(Locale.forLanguageTag("tr-TR"));
try {
Ticket ticket = (Ticket) PojoUtils.realize(map, Ticket.class);
assertThat(ticket.getId(), equalTo("T-1"));
assertTrue(ticket.isImportant());
} finally {
Locale.setDefault(defaultLocale);
}
}

@Test
void testJsonObjectToMap() throws Exception {
Method method = PojoUtilsTest.class.getMethod("setMap", Map.class);
Expand Down Expand Up @@ -1286,4 +1304,10 @@ interface Message {

boolean isUrgent();
}

interface Ticket {
String getId();

boolean isImportant();
}
}
Loading
Loading