mirror of
https://gitee.com/dromara/hutool.git
synced 2025-10-07 23:24:43 +08:00
fix:添加判空处理
This commit is contained in:
@@ -104,7 +104,7 @@ public class PinyinUtil {
|
||||
* @return 汉字返回拼音,非汉字原样返回
|
||||
*/
|
||||
public static String getFirstLetter(String str, String separator) {
|
||||
return getEngine().getFirstLetter(str, separator);
|
||||
return (str == null) ? null : getEngine().getFirstLetter(str, separator);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -22,4 +22,10 @@ public class PinyinUtilTest {
|
||||
final String result = PinyinUtil.getFirstLetter("崞阳", ", ");
|
||||
assertEquals("g, y", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstLetterTest3(){
|
||||
final String result = PinyinUtil.getFirstLetter(null, ", ");
|
||||
assertNull(result);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user