Looly 6 years ago
parent
commit
e754ec3e86
45 changed files with 172 additions and 179 deletions
  1. 1 1
      hutool-cache/src/main/java/cn/hutool/cache/file/LFUFileCache.java
  2. 1 1
      hutool-cache/src/main/java/cn/hutool/cache/file/LRUFileCache.java
  3. 1 1
      hutool-core/src/main/java/cn/hutool/core/builder/HashCodeBuilder.java
  4. 5 2
      hutool-core/src/main/java/cn/hutool/core/codec/Base32.java
  5. 5 4
      hutool-core/src/main/java/cn/hutool/core/comparator/ComparatorChain.java
  6. 2 1
      hutool-core/src/main/java/cn/hutool/core/comparator/VersionComparator.java
  7. 12 11
      hutool-core/src/main/java/cn/hutool/core/convert/NumberWordFormater.java
  8. 1 1
      hutool-core/src/main/java/cn/hutool/core/convert/impl/ArrayConverter.java
  9. 1 1
      hutool-core/src/main/java/cn/hutool/core/convert/impl/CollectionConverter.java
  10. 10 10
      hutool-core/src/main/java/cn/hutool/core/convert/impl/NumberConverter.java
  11. 4 2
      hutool-core/src/main/java/cn/hutool/core/date/BetweenFormater.java
  12. 1 1
      hutool-core/src/main/java/cn/hutool/core/date/format/FastDatePrinter.java
  13. 1 1
      hutool-core/src/main/java/cn/hutool/core/io/file/Tailer.java
  14. 2 4
      hutool-core/src/main/java/cn/hutool/core/lang/ObjectId.java
  15. 2 2
      hutool-core/src/main/java/cn/hutool/core/lang/PatternPool.java
  16. 3 2
      hutool-core/src/main/java/cn/hutool/core/lang/Range.java
  17. 1 1
      hutool-core/src/main/java/cn/hutool/core/lang/caller/CallerUtil.java
  18. 5 1
      hutool-core/src/main/java/cn/hutool/core/map/TableMap.java
  19. 16 17
      hutool-core/src/main/java/cn/hutool/core/text/UnicodeUtil.java
  20. 1 0
      hutool-core/src/main/java/cn/hutool/core/text/csv/CsvRow.java
  21. 3 2
      hutool-core/src/main/java/cn/hutool/core/util/EscapeUtil.java
  22. 4 4
      hutool-core/src/main/java/cn/hutool/core/util/HashUtil.java
  23. 39 37
      hutool-core/src/main/java/cn/hutool/core/util/HexUtil.java
  24. 1 2
      hutool-core/src/main/java/cn/hutool/core/util/PageUtil.java
  25. 1 0
      hutool-core/src/main/java/cn/hutool/core/util/TypeUtil.java
  26. 1 1
      hutool-core/src/test/java/cn/hutool/core/annotation/AnnotationForTest.java
  27. 1 1
      hutool-core/src/test/java/cn/hutool/core/annotation/AnnotationUtilTest.java
  28. 1 1
      hutool-core/src/test/java/cn/hutool/core/util/ClassUtilTest.java
  29. 1 1
      hutool-cron/src/main/java/cn/hutool/cron/pattern/parser/DayOfWeekValueParser.java
  30. 1 1
      hutool-cron/src/main/java/cn/hutool/cron/pattern/parser/MonthValueParser.java
  31. 1 1
      hutool-crypto/src/main/java/cn/hutool/crypto/digest/mac/DefaultHMacEngine.java
  32. 1 1
      hutool-db/src/main/java/cn/hutool/db/dialect/DialectFactory.java
  33. 2 2
      hutool-db/src/main/java/cn/hutool/db/dialect/DriverUtil.java
  34. 1 1
      hutool-db/src/main/java/cn/hutool/db/ds/GlobalDSFactory.java
  35. 1 1
      hutool-db/src/test/java/cn/hutool/db/ConcurentTest.java
  36. 8 12
      hutool-db/src/test/java/cn/hutool/db/MySQLTest.java
  37. 2 5
      hutool-db/src/test/java/cn/hutool/db/UpdateTest.java
  38. 10 23
      hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java
  39. 1 4
      hutool-extra/src/main/java/cn/hutool/extra/template/engine/thymeleaf/ThymeleafEngine.java
  40. 3 3
      hutool-extra/src/main/java/cn/hutool/extra/template/engine/velocity/VelocityUtil.java
  41. 1 1
      hutool-extra/src/main/java/cn/hutool/extra/tokenizer/engine/ikanalyzer/IKAnalyzerResult.java
  42. 1 1
      hutool-extra/src/main/java/cn/hutool/extra/tokenizer/engine/jcseg/JcsegResult.java
  43. 1 1
      hutool-extra/src/main/java/cn/hutool/extra/tokenizer/engine/mmseg/MmsegResult.java
  44. 1 1
      hutool-http/src/main/java/cn/hutool/http/webservice/SoapUtil.java
  45. 10 8
      hutool-json/src/main/java/cn/hutool/json/XML.java

+ 1 - 1
hutool-cache/src/main/java/cn/hutool/cache/file/LFUFileCache.java

@@ -46,7 +46,7 @@ public class LFUFileCache extends AbstractFileCache{
 	@Override
 	protected Cache<File, byte[]> initCache() {
 		return new LFUCache<File, byte[]>(LFUFileCache.this.capacity, LFUFileCache.this.timeout) {
-			private static final long serialVersionUID1 = 1L;
+			private static final long serialVersionUID = 1L;
 
 			@Override
 			public boolean isFull() {

+ 1 - 1
hutool-cache/src/main/java/cn/hutool/cache/file/LRUFileCache.java

@@ -46,7 +46,7 @@ public class LRUFileCache extends AbstractFileCache{
 	@Override
 	protected Cache<File, byte[]> initCache() {
 		return new LRUCache<File, byte[]>(LRUFileCache.this.capacity, super.timeout) {
-			private static final long serialVersionUID1 = 1L;
+			private static final long serialVersionUID = 1L;
 
 			@Override
 			public boolean isFull() {

+ 1 - 1
hutool-core/src/main/java/cn/hutool/core/builder/HashCodeBuilder.java

@@ -512,7 +512,7 @@ public class HashCodeBuilder implements Builder<Integer> {
     /**
      * Running total of the hashCode.
      */
-    private int iTotal = 0;
+    private int iTotal;
 
     /**
      * <p>

+ 5 - 2
hutool-core/src/main/java/cn/hutool/core/codec/Base32.java

@@ -38,8 +38,11 @@ public class Base32 {
 	 * @return base32
 	 */
 	public static String encode(final byte[] bytes) {
-		int i = 0, index = 0, digit = 0;
-		int currByte, nextByte;
+		int i = 0;
+		int index = 0;
+		int digit;
+		int currByte;
+		int nextByte;
 		StringBuilder base32 = new StringBuilder((bytes.length + 7) * 8 / 5);
 
 		while (i < bytes.length) {

+ 5 - 4
hutool-core/src/main/java/cn/hutool/core/comparator/ComparatorChain.java

@@ -6,6 +6,7 @@ import java.util.BitSet;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Objects;
 
 import cn.hutool.core.lang.Chain;
 
@@ -23,7 +24,7 @@ public class ComparatorChain<E> implements Chain<Comparator<E>, ComparatorChain<
 	/** 比较器链. */
 	private final List<Comparator<E>> chain;
 	/** 对应比较器位置是否反序. */
-	private BitSet orderingBits = null;
+	private BitSet orderingBits;
 	/** 比较器是否被锁定。锁定的比较器链不能再添加新的比较器。比较器会在开始比较时开始加锁。 */
 	private boolean lock = false;
 
@@ -31,7 +32,7 @@ public class ComparatorChain<E> implements Chain<Comparator<E>, ComparatorChain<
 	 * 构造空的比较器链,必须至少有一个比较器,否则会在compare时抛出{@link UnsupportedOperationException}
 	 */
 	public ComparatorChain() {
-		this(new ArrayList<Comparator<E>>(), new BitSet());
+		this(new ArrayList<>(), new BitSet());
 	}
 
 	/**
@@ -50,7 +51,7 @@ public class ComparatorChain<E> implements Chain<Comparator<E>, ComparatorChain<
 	 * @param reverse 是否反序,true表示反序,false正序
 	 */
 	public ComparatorChain(final Comparator<E> comparator, final boolean reverse) {
-		chain = new ArrayList<Comparator<E>>(1);
+		chain = new ArrayList<>(1);
 		chain.add(comparator);
 		orderingBits = new BitSet(1);
 		if (reverse == true) {
@@ -248,7 +249,7 @@ public class ComparatorChain<E> implements Chain<Comparator<E>, ComparatorChain<
 		}
 		if (object.getClass().equals(this.getClass())) {
 			final ComparatorChain<?> otherChain = (ComparatorChain<?>) object;
-			return (null == orderingBits ? null == otherChain.orderingBits : this.orderingBits.equals(otherChain.orderingBits)) //
+			return (Objects.equals(this.orderingBits, otherChain.orderingBits)) //
 					&& (null == otherChain ? null == otherChain.chain : this.chain.equals(otherChain.chain));
 		}
 		return false;

+ 2 - 1
hutool-core/src/main/java/cn/hutool/core/comparator/VersionComparator.java

@@ -5,6 +5,7 @@ import java.util.Comparator;
 import java.util.List;
 
 import cn.hutool.core.util.CharUtil;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 
 /**
@@ -49,7 +50,7 @@ public class VersionComparator implements Comparator<String>, Serializable {
 	 */
 	@Override
 	public int compare(String version1, String version2) {
-		if(version1 == version2) {
+		if(ObjectUtil.equal(version1, version2)) {
 			return 0;
 		}
 		if (version1 == null && version2 == null) {

+ 12 - 11
hutool-core/src/main/java/cn/hutool/core/convert/NumberWordFormater.java

@@ -45,7 +45,7 @@ public class NumberWordFormater {
 	 */
 	private static String format(String x) {
 		int z = x.indexOf("."); // 取小数点位置
-		String lstr = "", rstr = "";
+		String lstr, rstr = "";
 		if (z > -1) { // 看是否有小数,如果有,则分别取左边和右边
 			lstr = x.substring(0, z);
 			rstr = x.substring(z + 1);
@@ -65,19 +65,20 @@ public class NumberWordFormater {
 			lstrrev += "0";
 			break;
 		}
-		String lm = ""; // 用来存放转换後的整数部分
+		StringBuilder lm = new StringBuilder(); // 用来存放转换後的整数部分
 		for (int i = 0; i < lstrrev.length() / 3; i++) {
 			a[i] = StrUtil.reverse(lstrrev.substring(3 * i, 3 * i + 3)); // 截取第一个叁位
 			if (!a[i].equals("000")) { // 用来避免这种情况:1000000 = one million
 										// thousand only
 				if (i != 0) {
-					lm = transThree(a[i]) + " " + parseMore(String.valueOf(i)) + " " + lm; // 加:
-																							// thousand、million、billion
+					lm.insert(0, transThree(a[i]) + " " + parseMore(i) + " "); // 加:
+					// thousand、million、billion
 				} else {
-					lm = transThree(a[i]); // 防止i=0时, 在多加两个空格.
+					// 防止i=0时, 在多加两个空格.
+					lm = new StringBuilder(transThree(a[i]));
 				}
 			} else {
-				lm += transThree(a[i]);
+				lm.append(transThree(a[i]));
 			}
 		}
 
@@ -86,7 +87,7 @@ public class NumberWordFormater {
 			xs = "AND CENTS " + transTwo(rstr) + " "; // 小数部分存在时转换小数
 		}
 
-		return lm.trim() + " " + xs + "ONLY";
+		return lm.toString().trim() + " " + xs + "ONLY";
 	}
 
 	private static String parseFirst(String s) {
@@ -101,13 +102,13 @@ public class NumberWordFormater {
 		return NUMBER_TEN[Integer.parseInt(s.substring(0, 1)) - 1];
 	}
 
-	private static String parseMore(String s) {
-		return NUMBER_MORE[Integer.parseInt(s)];
+	private static String parseMore(int i) {
+		return NUMBER_MORE[i];
 	}
 
 	// 两位
 	private static String transTwo(String s) {
-		String value = "";
+		String value;
 		// 判断位数
 		if (s.length() > 2) {
 			s = s.substring(0, 2);
@@ -130,7 +131,7 @@ public class NumberWordFormater {
 	// 制作叁位的数
 	// s.length = 3
 	private static String transThree(String s) {
-		String value = "";
+		String value;
 		if (s.startsWith("0")) {// 是否小於100
 			value = transTwo(s.substring(1));
 		} else if (s.substring(1).equals("00")) {// 是否被100整除

+ 1 - 1
hutool-core/src/main/java/cn/hutool/core/convert/impl/ArrayConverter.java

@@ -97,7 +97,7 @@ public class ArrayConverter extends AbstractConverter<Object> {
 		}
 
 		final ConverterRegistry converter = ConverterRegistry.getInstance();
-		Object result = null;
+		Object result;
 		if (value instanceof List) {
 			// List转数组
 			final List<?> list = (List<?>) value;

+ 1 - 1
hutool-core/src/main/java/cn/hutool/core/convert/impl/CollectionConverter.java

@@ -61,7 +61,7 @@ public class CollectionConverter implements Converter<Collection<?>> {
 
 	@Override
 	public Collection<?> convert(Object value, Collection<?> defaultValue) throws IllegalArgumentException {
-		Collection<?> result = null;
+		Collection<?> result;
 		try {
 			result = convertInternal(value);
 		} catch (RuntimeException e) {

+ 10 - 10
hutool-core/src/main/java/cn/hutool/core/convert/impl/NumberConverter.java

@@ -76,18 +76,18 @@ public class NumberConverter extends AbstractConverter<Number> {
 			return StrUtil.isBlank(valueStr) ? null : Integer.valueOf(NumberUtil.parseInt(valueStr));
 			
 		} else if (AtomicInteger.class == targetType) {
-			int intValue;
+			final AtomicInteger intValue = new AtomicInteger();
 			if (value instanceof Number) {
-				intValue = ((Number) value).intValue();
+				intValue.set(((Number) value).intValue());
 			} else if(value instanceof Boolean) {
-				intValue = BooleanUtil.toInt((Boolean)value);
+				intValue.set(BooleanUtil.toInt((Boolean) value));
 			}
 			final String valueStr = convertToStr(value);
 			if (StrUtil.isBlank(valueStr)) {
 				return null;
 			}
-			intValue = NumberUtil.parseInt(valueStr);
-			return new AtomicInteger(intValue);
+			intValue.set(NumberUtil.parseInt(valueStr));
+			return intValue;
 		} else if (Long.class == targetType) {
 			if (value instanceof Number) {
 				return Long.valueOf(((Number) value).longValue());
@@ -98,18 +98,18 @@ public class NumberConverter extends AbstractConverter<Number> {
 			return StrUtil.isBlank(valueStr) ? null : Long.valueOf(NumberUtil.parseLong(valueStr));
 
 		} else if (AtomicLong.class == targetType) {
-			long longValue;
+			final AtomicLong longValue = new AtomicLong();
 			if (value instanceof Number) {
-				longValue = ((Number) value).longValue();
+				longValue.set(((Number) value).longValue());
 			} else if(value instanceof Boolean) {
-				longValue = BooleanUtil.toLong((Boolean)value);
+				longValue.set(BooleanUtil.toLong((Boolean) value));
 			}
 			final String valueStr = convertToStr(value);
 			if (StrUtil.isBlank(valueStr)) {
 				return null;
 			}
-			longValue = NumberUtil.parseLong(valueStr);
-			return new AtomicLong(longValue);
+			longValue.set(NumberUtil.parseLong(valueStr));
+			return longValue;
 			
 		} else if (Float.class == targetType) {
 			if (value instanceof Number) {

+ 4 - 2
hutool-core/src/main/java/cn/hutool/core/date/BetweenFormater.java

@@ -51,8 +51,10 @@ public class BetweenFormater implements Serializable{
 			long day = betweenMs / DateUnit.DAY.getMillis();
 			long hour = betweenMs / DateUnit.HOUR.getMillis() - day * 24;
 			long minute = betweenMs / DateUnit.MINUTE.getMillis() - day * 24 * 60 - hour * 60;
-			long second = betweenMs / DateUnit.SECOND.getMillis() - ((day * 24 + hour) * 60 + minute) * 60;
-			long millisecond = betweenMs - (((day * 24 + hour) * 60 + minute) * 60 + second) * 1000;
+
+			final long BetweenOfSecond = ((day * 24 + hour) * 60 + minute) * 60;
+			long second = betweenMs / DateUnit.SECOND.getMillis() - BetweenOfSecond;
+			long millisecond = betweenMs - (BetweenOfSecond + second) * 1000;
 			
 			final int level = this.level.ordinal();
 			int levelCount = 0;

+ 1 - 1
hutool-core/src/main/java/cn/hutool/core/date/format/FastDatePrinter.java

@@ -104,7 +104,7 @@ class FastDatePrinter extends AbstractDateBasic implements DatePrinter {
 					if (tokenLen == 2) {
 						rule = TwoDigitYearField.INSTANCE;
 					} else {
-						rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen);
+						rule = selectNumberRule(Calendar.YEAR, Math.max(tokenLen, 4));
 					}
 					if (c == 'Y') {
 						rule = new WeekYear((NumberRule) rule);

+ 1 - 1
hutool-core/src/main/java/cn/hutool/core/io/file/Tailer.java

@@ -137,7 +137,7 @@ public class Tailer implements Serializable {
 	/**
 	 * 预读取行
 	 * 
-	 * @throws IOException
+	 * @throws IOException IO异常
 	 */
 	private void readTail() throws IOException {
 		final long len = this.randomAccessFile.length();

+ 2 - 4
hutool-core/src/main/java/cn/hutool/core/lang/ObjectId.java

@@ -173,11 +173,9 @@ public class ObjectId {
 		int loaderId = (loader != null) ? System.identityHashCode(loader) : 0;
 
 		// 进程ID + 对象加载ID
-		StringBuilder processSb = new StringBuilder();
-		processSb.append(Integer.toHexString(processId));
-		processSb.append(Integer.toHexString(loaderId));
 		// 保留前2位
-		processPiece = processSb.toString().hashCode() & 0xFFFF;
+		final String processSb = Integer.toHexString(processId) + Integer.toHexString(loaderId);
+		processPiece = processSb.hashCode() & 0xFFFF;
 
 		return processPiece;
 	}

File diff suppressed because it is too large
+ 2 - 2
hutool-core/src/main/java/cn/hutool/core/lang/PatternPool.java


+ 3 - 2
hutool-core/src/main/java/cn/hutool/core/lang/Range.java

@@ -39,9 +39,9 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
 	/** 索引 */
 	private int index = 0;
 	/** 是否包含第一个元素 */
-	private boolean includeStart = true;
+	private boolean includeStart;
 	/** 是否包含最后一个元素 */
-	private boolean includeEnd = true;
+	private boolean includeEnd;
 
 	/**
 	 * 构造
@@ -80,6 +80,7 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
 		this.steper = steper;
 		this.next = safeStep(this.current);
 		this.includeStart = isIncludeStart;
+		includeEnd = true;
 		this.includeEnd = isIncludeEnd;
 	}
 

+ 1 - 1
hutool-core/src/main/java/cn/hutool/core/lang/caller/CallerUtil.java

@@ -64,7 +64,7 @@ public class CallerUtil {
 	 * @return {@link Caller}实现
 	 */
 	private static Caller tryCreateCaller() {
-		Caller caller = null;
+		Caller caller;
 		try {
 			caller = new SecurityManagerCaller();
 			if(null != caller.getCaller() && null != caller.getCallerCaller()) {

+ 5 - 1
hutool-core/src/main/java/cn/hutool/core/map/TableMap.java

@@ -58,16 +58,19 @@ public class TableMap<K, V> implements Map<K, V>, Serializable {
 
 	@Override
 	public boolean containsKey(Object key) {
+		//noinspection SuspiciousMethodCalls
 		return keys.contains(key);
 	}
 
 	@Override
 	public boolean containsValue(Object value) {
+		//noinspection SuspiciousMethodCalls
 		return values.contains(value);
 	}
 
 	@Override
 	public V get(Object key) {
+		//noinspection SuspiciousMethodCalls
 		final int index = keys.indexOf(key);
 		if (index > -1 && index < values.size()) {
 			return values.get(index);
@@ -84,6 +87,7 @@ public class TableMap<K, V> implements Map<K, V>, Serializable {
 
 	@Override
 	public V remove(Object key) {
+		//noinspection SuspiciousMethodCalls
 		int index = keys.indexOf(key);
 		if (index > -1) {
 			keys.remove(index);
@@ -121,7 +125,7 @@ public class TableMap<K, V> implements Map<K, V>, Serializable {
 	public Set<Map.Entry<K, V>> entrySet() {
 		HashSet<Map.Entry<K, V>> hashSet = new HashSet<>();
 		for (int i = 0; i < size(); i++) {
-			hashSet.add(new Entry<K, V>(keys.get(i), values.get(i)));
+			hashSet.add(new Entry<>(keys.get(i), values.get(i)));
 		}
 		return hashSet;
 	}

+ 16 - 17
hutool-core/src/main/java/cn/hutool/core/text/UnicodeUtil.java

@@ -6,17 +6,16 @@ import cn.hutool.core.util.StrUtil;
 
 /**
  * 提供Unicode字符串和普通字符串之间的转换
- * 
+ *
  * @author 兜兜毛毛, looly
  * @since 4.0.0
- *
  */
 public class UnicodeUtil {
 
 	/**
 	 * Unicode字符串转为普通字符串<br>
 	 * Unicode字符串的表现方式为:\\uXXXX
-	 * 
+	 *
 	 * @param unicode Unicode字符串
 	 * @return 普通字符串
 	 */
@@ -27,37 +26,37 @@ public class UnicodeUtil {
 
 		final int len = unicode.length();
 		StrBuilder sb = StrBuilder.create(len);
-		int i = -1;
+		int i;
 		int pos = 0;
 		while ((i = StrUtil.indexOfIgnoreCase(unicode, "\\u", pos)) != -1) {
 			sb.append(unicode, pos, i);//写入Unicode符之前的部分
-			pos  = i;
+			pos = i;
 			if (i + 5 < len) {
-				char c = 0;
+				char c;
 				try {
 					c = (char) Integer.parseInt(unicode.substring(i + 2, i + 6), 16);
 					sb.append(c);
 					pos = i + 6;//跳过整个Unicode符
 				} catch (NumberFormatException e) {
 					//非法Unicode符,跳过
-					sb.append(unicode, pos, i+2);//写入"\\u"
+					sb.append(unicode, pos, i + 2);//写入"\\u"
 					pos = i + 2;
 				}
-			}else {
+			} else {
 				pos = i;//非Unicode符,结束
 				break;
 			}
 		}
-		
-		if(pos < len) {
-			sb.append(unicode,pos, len);
+
+		if (pos < len) {
+			sb.append(unicode, pos, len);
 		}
 		return sb.toString();
 	}
-	
+
 	/**
 	 * 字符串编码为Unicode形式
-	 * 
+	 *
 	 * @param str 被编码的字符串
 	 * @return Unicode字符串
 	 */
@@ -67,8 +66,8 @@ public class UnicodeUtil {
 
 	/**
 	 * 字符串编码为Unicode形式
-	 * 
-	 * @param str 被编码的字符串
+	 *
+	 * @param str         被编码的字符串
 	 * @param isSkipAscii 是否跳过ASCII字符(只跳过可见字符)
 	 * @return Unicode字符串
 	 */
@@ -82,9 +81,9 @@ public class UnicodeUtil {
 		char c;
 		for (int i = 0; i < len; i++) {
 			c = str.charAt(i);
-			if(isSkipAscii && CharUtil.isAsciiPrintable(c) ) {
+			if (isSkipAscii && CharUtil.isAsciiPrintable(c)) {
 				unicode.append(c);
-			}else {
+			} else {
 				unicode.append(HexUtil.toUnicodeHex(c));
 			}
 		}

+ 1 - 0
hutool-core/src/main/java/cn/hutool/core/text/csv/CsvRow.java

@@ -132,6 +132,7 @@ public final class CsvRow implements List<String> {
 
 	@Override
 	public <T> T[] toArray(T[] a) {
+		//noinspection SuspiciousToArrayCall
 		return this.fields.toArray(a);
 	}
 

+ 3 - 2
hutool-core/src/main/java/cn/hutool/core/util/EscapeUtil.java

@@ -85,7 +85,8 @@ public class EscapeUtil {
 		}
 
 		StringBuilder tmp = new StringBuilder(content.length());
-		int lastPos = 0, pos = 0;
+		int lastPos = 0;
+		int pos;
 		char ch;
 		while (lastPos < content.length()) {
 			pos = content.indexOf("%", lastPos);
@@ -104,7 +105,7 @@ public class EscapeUtil {
 					tmp.append(content.substring(lastPos));
 					lastPos = content.length();
 				} else {
-					tmp.append(content.substring(lastPos, pos));
+					tmp.append(content, lastPos, pos);
 					lastPos = pos;
 				}
 			}

+ 4 - 4
hutool-core/src/main/java/cn/hutool/core/util/HashUtil.java

@@ -92,7 +92,7 @@ public class HashUtil {
 		for (i = 0; i < (len << 3); i += 8) {
 			char k = key[i >> 3];
 			if ((k & 0x01) == 0) {
-				hash ^= tab[i + 0];
+				hash ^= tab[i];
 			}
 			if ((k & 0x02) == 0) {
 				hash ^= tab[i + 1];
@@ -238,7 +238,7 @@ public class HashUtil {
 		int oneEighth = bitsInUnsignedInt / 8;
 		int highBits = 0xFFFFFFFF << (bitsInUnsignedInt - oneEighth);
 		int hash = 0;
-		int test = 0;
+		int test;
 
 		for (int i = 0; i < str.length(); i++) {
 			hash = (hash << oneEighth) + str.charAt(i);
@@ -259,7 +259,7 @@ public class HashUtil {
 	 */
 	public static int elfHash(String str) {
 		int hash = 0;
-		int x = 0;
+		int x;
 
 		for (int i = 0; i < str.length(); i++) {
 			hash = (hash << 4) + str.charAt(i);
@@ -361,7 +361,7 @@ public class HashUtil {
 	 * @return Hash值
 	 */
 	public static long tianlHash(String str) {
-		long hash = 0;
+		long hash;
 
 		int iLength = str.length();
 		if (iLength == 0) {

+ 39 - 37
hutool-core/src/main/java/cn/hutool/core/util/HexUtil.java

@@ -7,28 +7,27 @@ import java.nio.charset.Charset;
  * 十六进制(简写为hex或下标16)在数学中是一种逢16进1的进位制,一般用数字0到9和字母A到F表示(其中:A~F即10~15)。<br>
  * 例如十进制数57,在二进制写作111001,在16进制写作39。<br>
  * 像java,c这样的语言为了区分十六进制和十进制数值,会在十六进制数的前面加上 0x,比如0x20是十进制的32,而不是十进制的20<br>
- * 
+ * <p>
  * 参考:https://my.oschina.net/xinxingegeya/blog/287476
- * 
- * @author Looly
  *
+ * @author Looly
  */
 public class HexUtil {
 
 	/**
 	 * 用于建立十六进制字符的输出的小写字符数组
 	 */
-	private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+	private static final char[] DIGITS_LOWER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
 	/**
 	 * 用于建立十六进制字符的输出的大写字符数组
 	 */
-	private static final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+	private static final char[] DIGITS_UPPER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
 
 	/**
 	 * 判断给定字符串是否为16进制数<br>
 	 * 如果是,需要使用对应数字类型对象的<code>decode</code>方法解码<br>
 	 * 例如:{@code Integer.decode}方法解码int类型的16进制数字
-	 * 
+	 *
 	 * @param value 值
 	 * @return 是否为16进制
 	 */
@@ -41,12 +40,13 @@ public class HexUtil {
 				return false;
 			}
 			return true;
-		}else {
+		} else {
 			return false;
 		}
 	}
 
 	// ---------------------------------------------------------------------------------------------------- encode
+
 	/**
 	 * 将字节数组转换为十六进制字符数组
 	 *
@@ -60,7 +60,7 @@ public class HexUtil {
 	/**
 	 * 将字节数组转换为十六进制字符数组
 	 *
-	 * @param str 字符串
+	 * @param str     字符串
 	 * @param charset 编码
 	 * @return 十六进制char[]
 	 */
@@ -71,7 +71,7 @@ public class HexUtil {
 	/**
 	 * 将字节数组转换为十六进制字符数组
 	 *
-	 * @param data byte[]
+	 * @param data        byte[]
 	 * @param toLowerCase <code>true</code> 传换成小写格式 , <code>false</code> 传换成大写格式
 	 * @return 十六进制char[]
 	 */
@@ -92,7 +92,7 @@ public class HexUtil {
 	/**
 	 * 将字节数组转换为十六进制字符串,结果为小写
 	 *
-	 * @param data 被编码的字符串
+	 * @param data    被编码的字符串
 	 * @param charset 编码
 	 * @return 十六进制String
 	 */
@@ -113,7 +113,7 @@ public class HexUtil {
 	/**
 	 * 将字节数组转换为十六进制字符串
 	 *
-	 * @param data byte[]
+	 * @param data        byte[]
 	 * @param toLowerCase <code>true</code> 传换成小写格式 , <code>false</code> 传换成大写格式
 	 * @return 十六进制String
 	 */
@@ -122,6 +122,7 @@ public class HexUtil {
 	}
 
 	// ---------------------------------------------------------------------------------------------------- decode
+
 	/**
 	 * 将十六进制字符数组转换为字符串,默认编码UTF-8
 	 *
@@ -135,7 +136,7 @@ public class HexUtil {
 	/**
 	 * 将十六进制字符数组转换为字符串
 	 *
-	 * @param hexStr 十六进制String
+	 * @param hexStr  十六进制String
 	 * @param charset 编码
 	 * @return 字符串
 	 */
@@ -200,9 +201,10 @@ public class HexUtil {
 	}
 
 	// ---------------------------------------------------------------------------------------- Color
+
 	/**
 	 * 将{@link Color}编码为Hex形式
-	 * 
+	 *
 	 * @param color {@link Color}
 	 * @return Hex字符串
 	 * @since 3.0.8
@@ -213,14 +215,14 @@ public class HexUtil {
 
 	/**
 	 * 将{@link Color}编码为Hex形式
-	 * 
-	 * @param color {@link Color}
+	 *
+	 * @param color  {@link Color}
 	 * @param prefix 前缀字符串,可以是#、0x等
 	 * @return Hex字符串
 	 * @since 3.0.8
 	 */
 	public static String encodeColor(Color color, String prefix) {
-		final StringBuffer builder = new StringBuffer(prefix);
+		final StringBuilder builder = new StringBuilder(prefix);
 		String colorHex;
 		colorHex = Integer.toHexString(color.getRed());
 		if (1 == colorHex.length()) {
@@ -242,7 +244,7 @@ public class HexUtil {
 
 	/**
 	 * 将Hex颜色值转为
-	 * 
+	 *
 	 * @param hexColor 16进制颜色值,可以以#开头,也可以用0x开头
 	 * @return {@link Color}
 	 * @since 3.0.8
@@ -254,11 +256,11 @@ public class HexUtil {
 	/**
 	 * 将指定int值转换为Unicode字符串形式,常用于特殊字符(例如汉字)转Unicode形式<br>
 	 * 转换的字符串如果u后不足4位,则前面用0填充,例如:
-	 * 
+	 *
 	 * <pre>
 	 * '我' =》\u4f60
 	 * </pre>
-	 * 
+	 *
 	 * @param value int值,也可以是char
 	 * @return Unicode表现形式
 	 */
@@ -279,28 +281,26 @@ public class HexUtil {
 	/**
 	 * 将指定char值转换为Unicode字符串形式,常用于特殊字符(例如汉字)转Unicode形式<br>
 	 * 转换的字符串如果u后不足4位,则前面用0填充,例如:
-	 * 
+	 *
 	 * <pre>
 	 * '我' =》\u4f60
 	 * </pre>
-	 * 
+	 *
 	 * @param ch char值
 	 * @return Unicode表现形式
 	 * @since 4.0.1
 	 */
 	public static String toUnicodeHex(char ch) {
-		StringBuilder sb = new StringBuilder(6);
-		sb.append("\\u");
-		sb.append(DIGITS_LOWER[(ch >> 12) & 15]);
-		sb.append(DIGITS_LOWER[(ch >> 8) & 15]);
-		sb.append(DIGITS_LOWER[(ch >> 4) & 15]);
-		sb.append(DIGITS_LOWER[(ch) & 15]);
-		return sb.toString();
+		return "\\u" +//
+				DIGITS_LOWER[(ch >> 12) & 15] +//
+				DIGITS_LOWER[(ch >> 8) & 15] +//
+				DIGITS_LOWER[(ch >> 4) & 15] +//
+				DIGITS_LOWER[(ch) & 15];
 	}
 
 	/**
 	 * 转为16进制字符串
-	 * 
+	 *
 	 * @param value int值
 	 * @return 16进制字符串
 	 * @since 4.4.1
@@ -311,7 +311,7 @@ public class HexUtil {
 
 	/**
 	 * 转为16进制字符串
-	 * 
+	 *
 	 * @param value int值
 	 * @return 16进制字符串
 	 * @since 4.4.1
@@ -319,17 +319,18 @@ public class HexUtil {
 	public static String toHex(long value) {
 		return Long.toHexString(value);
 	}
-	
+
 	/**
 	 * 将byte值转为16进制并添加到{@link StringBuilder}中
-	 * @param builder {@link StringBuilder}
-	 * @param b byte
+	 *
+	 * @param builder     {@link StringBuilder}
+	 * @param b           byte
 	 * @param toLowerCase 是否使用小写
 	 * @since 4.4.1
 	 */
 	public static void appendHex(StringBuilder builder, byte b, boolean toLowerCase) {
 		final char[] toDigits = toLowerCase ? DIGITS_LOWER : DIGITS_UPPER;
-		
+
 		int high = (b & 0xf0) >>> 4;//高位
 		int low = b & 0x0f;//低位
 		builder.append(toDigits[high]);
@@ -337,10 +338,11 @@ public class HexUtil {
 	}
 
 	// ---------------------------------------------------------------------------------------- Private method start
+
 	/**
 	 * 将字节数组转换为十六进制字符串
 	 *
-	 * @param data byte[]
+	 * @param data     byte[]
 	 * @param toDigits 用于控制输出的char[]
 	 * @return 十六进制String
 	 */
@@ -351,7 +353,7 @@ public class HexUtil {
 	/**
 	 * 将字节数组转换为十六进制字符数组
 	 *
-	 * @param data byte[]
+	 * @param data     byte[]
 	 * @param toDigits 用于控制输出的char[]
 	 * @return 十六进制char[]
 	 */
@@ -369,7 +371,7 @@ public class HexUtil {
 	/**
 	 * 将十六进制字符转换成一个整数
 	 *
-	 * @param ch 十六进制char
+	 * @param ch    十六进制char
 	 * @param index 十六进制字符在字符数组中的位置
 	 * @return 一个整数
 	 * @throws RuntimeException 当ch不是一个合法的十六进制字符时,抛出运行时异常

+ 1 - 2
hutool-core/src/main/java/cn/hutool/core/util/PageUtil.java

@@ -85,8 +85,7 @@ public class PageUtil {
 	 * @return 分页条
 	 */
 	public static int[] rainbow(int currentPage, int pageCount, int displayCount) {
-		boolean isEven = true;
-		isEven = displayCount % 2 == 0;
+		boolean isEven = displayCount % 2 == 0;
 		int left = displayCount / 2;
 		int right = displayCount / 2;
 

+ 1 - 0
hutool-core/src/main/java/cn/hutool/core/util/TypeUtil.java

@@ -300,6 +300,7 @@ public class TypeUtil {
 		// 查找方法定义所在类或接口中此泛型参数的位置
 		final Type[] result = new Type[size];
 		for(int i = 0; i < typeVariables.length; i++) {
+			//noinspection SuspiciousMethodCalls
 			result[i] = (typeVariables[i] instanceof TypeVariable) ? tableMap.get(typeVariables[i]) : typeVariables[i];
 		}
 		return result;

+ 1 - 1
hutool-core/src/test/java/cn/hutool/core/annotation/AnnotationForTest.java

@@ -21,7 +21,7 @@ public @interface AnnotationForTest {
 	/**
 	 * 注解的默认属性值
 	 * 
-	 * @return
+	 * @return 属性值
 	 */
 	String value();
 }

+ 1 - 1
hutool-core/src/test/java/cn/hutool/core/annotation/AnnotationUtilTest.java

@@ -12,7 +12,7 @@ public class AnnotationUtilTest {
 	}
 	
 	@AnnotationForTest("测试")
-	class ClassWithAnnotation{
+	static class ClassWithAnnotation{
 		
 	}
 }

+ 1 - 1
hutool-core/src/test/java/cn/hutool/core/util/ClassUtilTest.java

@@ -24,7 +24,7 @@ public class ClassUtilTest {
 	}
 
 	@SuppressWarnings("unused")
-	class TestClass {
+	static class TestClass {
 		private String privateField;
 		protected String field;
 

+ 1 - 1
hutool-cron/src/main/java/cn/hutool/cron/pattern/parser/DayOfWeekValueParser.java

@@ -35,7 +35,7 @@ public class DayOfWeekValueParser extends SimpleValueParser {
 	 * 解析别名
 	 * @param value 别名值
 	 * @return 月份int值
-	 * @throws CronException
+	 * @throws CronException 无效别名抛出此异常
 	 */
 	private int parseAlias(String value) throws CronException {
 		if(value.equalsIgnoreCase("L")){

+ 1 - 1
hutool-cron/src/main/java/cn/hutool/cron/pattern/parser/MonthValueParser.java

@@ -30,7 +30,7 @@ public class MonthValueParser extends SimpleValueParser {
 	 * 解析别名
 	 * @param value 别名值
 	 * @return 月份int值
-	 * @throws CronException
+	 * @throws CronException 无效月别名抛出此异常
 	 */
 	private int parseAlias(String value) throws CronException {
 		for (int i = 0; i < ALIASES.length; i++) {

+ 1 - 1
hutool-crypto/src/main/java/cn/hutool/crypto/digest/mac/DefaultHMacEngine.java

@@ -81,7 +81,7 @@ public class DefaultHMacEngine implements MacEngine {
 		}
 		byte[] buffer = new byte[bufferLength];
 
-		byte[] result = null;
+		byte[] result;
 		try {
 			int read = data.read(buffer, 0, bufferLength);
 

+ 1 - 1
hutool-db/src/main/java/cn/hutool/db/dialect/DialectFactory.java

@@ -55,7 +55,7 @@ public class DialectFactory {
 	public final static String DRIVER_DM7 = "dm.jdbc.driver.DmDriver";
 	
 	private static Map<DataSource, Dialect> dialectPool = new ConcurrentHashMap<>();
-	private static Object lock = new Object();
+	private static final Object lock = new Object();
 
 	private DialectFactory() {
 	}

+ 2 - 2
hutool-db/src/main/java/cn/hutool/db/dialect/DriverUtil.java

@@ -44,7 +44,7 @@ public class DriverUtil {
 		}
 		
 		Connection conn = null;
-		String driver = null;
+		String driver;
 		try {
 			try {
 				conn = ds.getConnection();
@@ -69,7 +69,7 @@ public class DriverUtil {
 	 * @throws DbRuntimeException SQL异常包装,获取元数据信息失败
 	 */
 	public static String identifyDriver(Connection conn) throws DbRuntimeException {
-		String driver = null;
+		String driver;
 		DatabaseMetaData meta;
 		try {
 			meta = conn.getMetaData();

+ 1 - 1
hutool-db/src/main/java/cn/hutool/db/ds/GlobalDSFactory.java

@@ -12,7 +12,7 @@ import cn.hutool.log.StaticLog;
 public class GlobalDSFactory {
 
 	private static volatile DSFactory factory;
-	private static Object lock = new Object();
+	private static final Object lock = new Object();
 
 	/*
 	 * 设置在JVM关闭时关闭所有数据库连接

+ 1 - 1
hutool-db/src/test/java/cn/hutool/db/ConcurentTest.java

@@ -37,7 +37,7 @@ public class ConcurentTest {
 			ThreadUtil.execute(new Runnable() {
 				@Override
 				public void run() {
-					List<Entity> find = null;
+					List<Entity> find;
 					try {
 						find = db.find(CollectionUtil.newArrayList("name AS name2"), Entity.create("user"), new EntityListHandler());
 					} catch (SQLException e) {

+ 8 - 12
hutool-db/src/test/java/cn/hutool/db/MySQLTest.java

@@ -33,23 +33,19 @@ public class MySQLTest {
 	 * 事务测试<br>
 	 * 更新三条信息,低2条后抛出异常,正常情况下三条都应该不变
 	 * 
-	 * @throws SQLException
+	 * @throws SQLException SQL异常
 	 */
 	@Test(expected=SQLException.class)
 	@Ignore
 	public void txTest() throws SQLException {
-		Db.use("mysql").tx(new VoidFunc1<Db>() {
-			
-			@Override
-			public void call(Db db) throws Exception {
-				int update = db.update(Entity.create("user").set("text", "描述100"), Entity.create().set("id", 100));
-				db.update(Entity.create("user").set("text", "描述101"), Entity.create().set("id", 101));
-				if(1 == update) {
-					// 手动指定异常,然后测试回滚触发
-					throw new RuntimeException("Error");
-				}
-				db.update(Entity.create("user").set("text", "描述102"), Entity.create().set("id", 102));
+		Db.use("mysql").tx(db -> {
+			int update = db.update(Entity.create("user").set("text", "描述100"), Entity.create().set("id", 100));
+			db.update(Entity.create("user").set("text", "描述101"), Entity.create().set("id", 101));
+			if(1 == update) {
+				// 手动指定异常,然后测试回滚触发
+				throw new RuntimeException("Error");
 			}
+			db.update(Entity.create("user").set("text", "描述102"), Entity.create().set("id", 102));
 		});
 	}
 

+ 2 - 5
hutool-db/src/test/java/cn/hutool/db/UpdateTest.java

@@ -1,14 +1,11 @@
 package cn.hutool.db;
 
-import java.sql.SQLException;
-
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import cn.hutool.db.Db;
-import cn.hutool.db.Entity;
+import java.sql.SQLException;
 
 public class UpdateTest {
 	
@@ -22,7 +19,7 @@ public class UpdateTest {
 	/**
 	 * 对更新做单元测试
 	 * 
-	 * @throws SQLException
+	 * @throws SQLException SQL异常
 	 */
 	@Test
 	@Ignore

+ 10 - 23
hutool-extra/src/main/java/cn/hutool/extra/ssh/Sftp.java

@@ -205,12 +205,7 @@ public class Sftp extends AbstractFtp {
 	 * @since 4.0.5
 	 */
 	public List<String> lsDirs(String path) {
-		return ls(path, new Filter<LsEntry>() {
-			@Override
-			public boolean accept(LsEntry t) {
-				return t.getAttrs().isDir();
-			}
-		});
+		return ls(path, t -> t.getAttrs().isDir());
 	}
 
 	/**
@@ -221,12 +216,7 @@ public class Sftp extends AbstractFtp {
 	 * @since 4.0.5
 	 */
 	public List<String> lsFiles(String path) {
-		return ls(path, new Filter<LsEntry>() {
-			@Override
-			public boolean accept(LsEntry t) {
-				return false == t.getAttrs().isDir();
-			}
-		});
+		return ls(path, t -> false == t.getAttrs().isDir());
 	}
 
 	/**
@@ -240,17 +230,14 @@ public class Sftp extends AbstractFtp {
 	public List<String> ls(String path, final Filter<LsEntry> filter) {
 		final List<String> fileNames = new ArrayList<>();
 		try {
-			channel.ls(path, new LsEntrySelector() {
-				@Override
-				public int select(LsEntry entry) {
-					String fileName = entry.getFilename();
-					if (false == StrUtil.equals(".", fileName) && false == StrUtil.equals("..", fileName)) {
-						if (null == filter || filter.accept(entry)) {
-							fileNames.add(entry.getFilename());
-						}
+			channel.ls(path, entry -> {
+				String fileName = entry.getFilename();
+				if (false == StrUtil.equals(".", fileName) && false == StrUtil.equals("..", fileName)) {
+					if (null == filter || filter.accept(entry)) {
+						fileNames.add(entry.getFilename());
 					}
-					return CONTINUE;
 				}
+				return LsEntrySelector.CONTINUE;
 			});
 		} catch (SftpException e) {
 			throw new JschRuntimeException(e);
@@ -316,7 +303,7 @@ public class Sftp extends AbstractFtp {
 			return false;
 		}
 
-		Vector<LsEntry> list = null;
+		Vector<LsEntry> list;
 		try {
 			list = channel.ls(channel.pwd());
 		} catch (SftpException e) {
@@ -418,7 +405,7 @@ public class Sftp extends AbstractFtp {
 	}
 
 	@Override
-	public void close() throws IOException {
+	public void close() {
 		JschUtil.close(this.channel);
 		JschUtil.close(this.session);
 	}

+ 1 - 4
hutool-extra/src/main/java/cn/hutool/extra/template/engine/thymeleaf/ThymeleafEngine.java

@@ -68,7 +68,7 @@ public class ThymeleafEngine implements TemplateEngine {
 			config = new TemplateConfig();
 		}
 		
-		ITemplateResolver resolver = null;
+		ITemplateResolver resolver;
 		switch (config.getResourceMode()) {
 		case CLASSPATH:
 			final ClassLoaderTemplateResolver classLoaderResolver = new ClassLoaderTemplateResolver();
@@ -94,9 +94,6 @@ public class ThymeleafEngine implements TemplateEngine {
 		case STRING:
 			resolver = new StringTemplateResolver();
 			break;
-		case COMPOSITE:
-			resolver = new DefaultTemplateResolver();
-			break;
 		default:
 			resolver = new DefaultTemplateResolver();
 			break;

+ 3 - 3
hutool-extra/src/main/java/cn/hutool/extra/template/engine/velocity/VelocityUtil.java

@@ -33,7 +33,7 @@ public class VelocityUtil {
 	/** 是否初始化了默认引擎 */
 	private static boolean isInited;
 	/** 全局上下文,当设定值时,对于每个模板都有效 */
-	private static Map<String, Object> globalContext = new HashMap<String, Object>();
+	private static Map<String, Object> globalContext = new HashMap<>();
 
 	/**
 	 * 设置Velocity全局上下文<br>
@@ -278,7 +278,7 @@ public class VelocityUtil {
 	public static VelocityContext parseRequest(VelocityContext context, javax.servlet.http.HttpServletRequest request) {
 		final Enumeration<String> attrs = request.getAttributeNames();
 		if (attrs != null) {
-			String attrName = null;
+			String attrName;
 			while (attrs.hasMoreElements()) {
 				attrName = attrs.nextElement();
 				context.put(attrName, request.getAttribute(attrName));
@@ -298,7 +298,7 @@ public class VelocityUtil {
 		if (null != session) {
 			final Enumeration<String> sessionAttrs = session.getAttributeNames();
 			if (sessionAttrs != null) {
-				String attrName = null;
+				String attrName;
 				while (sessionAttrs.hasMoreElements()) {
 					attrName = sessionAttrs.nextElement();
 					context.put(attrName, session.getAttribute(attrName));

+ 1 - 1
hutool-extra/src/main/java/cn/hutool/extra/tokenizer/engine/ikanalyzer/IKAnalyzerResult.java

@@ -31,7 +31,7 @@ public class IKAnalyzerResult extends AbstractResult {
 
 	@Override
 	protected Word nextWord() {
-		Lexeme next = null;
+		Lexeme next;
 		try {
 			next = this.seg.next();
 		} catch (IOException e) {

+ 1 - 1
hutool-extra/src/main/java/cn/hutool/extra/tokenizer/engine/jcseg/JcsegResult.java

@@ -36,7 +36,7 @@ public class JcsegResult implements Result{
 		if (this.cachedWord != null) {
 			return true;
 		}
-		IWord next = null;
+		IWord next;
 		try {
 			next = this.result.next();
 		} catch (IOException e) {

+ 1 - 1
hutool-extra/src/main/java/cn/hutool/extra/tokenizer/engine/mmseg/MmsegResult.java

@@ -30,7 +30,7 @@ public class MmsegResult extends AbstractResult {
 
 	@Override
 	protected Word nextWord() {
-		com.chenlb.mmseg4j.Word next = null;
+		com.chenlb.mmseg4j.Word next;
 		try {
 			next = this.mmSeg.next();
 		} catch (IOException e) {

+ 1 - 1
hutool-http/src/main/java/cn/hutool/http/webservice/SoapUtil.java

@@ -81,7 +81,7 @@ public class SoapUtil {
 		} catch (SOAPException | IOException e) {
 			throw new SoapRuntimeException(e);
 		}
-		String messageToString = null;
+		String messageToString;
 		try {
 			messageToString = out.toString(charset.toString());
 		} catch (UnsupportedEncodingException e) {

+ 10 - 8
hutool-json/src/main/java/cn/hutool/json/XML.java

@@ -2,7 +2,9 @@ package cn.hutool.json;
 
 import java.util.Iterator;
 
+import cn.hutool.core.util.ArrayUtil;
 import cn.hutool.core.util.CharUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.XmlUtil;
 
 /**
@@ -46,12 +48,12 @@ public class XML {
 	 * @param context The JSONObject that will include the new material.
 	 * @param name The tag name.
 	 * @return true if the close tag is processed.
-	 * @throws JSONException
+	 * @throws JSONException JSON异常
 	 */
 	private static boolean parse(XMLTokener x, JSONObject context, String name, boolean keepStrings) throws JSONException {
 		char c;
 		int i;
-		JSONObject jsonobject = null;
+		JSONObject jsonobject;
 		String string;
 		String tagName;
 		Object token;
@@ -265,7 +267,6 @@ public class XML {
 		JSONObject jo;
 		String key;
 		Iterator<String> keys;
-		String string;
 		Object value;
 
 		if (object instanceof JSONObject) {
@@ -284,11 +285,10 @@ public class XML {
 				key = keys.next();
 				value = jo.get(key);
 				if (value == null) {
-					value = "";
-				} else if (value.getClass().isArray()) {
+					value = StrUtil.EMPTY;
+				} else if (ArrayUtil.isArray(value)) {
 					value = new JSONArray(value);
 				}
-				string = value instanceof String ? (String) value : null;
 
 				// Emit content in body
 				if ("content".equals(key)) {
@@ -362,8 +362,10 @@ public class XML {
 			}
 		}
 
-		string = (object == null) ? "null" : XmlUtil.escape(object.toString());
-		return (tagName == null) ? "\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>" : "<" + tagName + ">" + string + "</" + tagName + ">";
+		String string = (object == null) ? StrUtil.NULL : XmlUtil.escape(object.toString());
+		return (tagName == null) ?
+				"\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>"
+				: "<" + tagName + ">" + string + "</" + tagName + ">";
 
 	}
 }