Skip to content

Commit

Permalink
Fix MySqlUtils NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
ruansheng8 committed Jan 22, 2024
1 parent b1ac216 commit c34a7c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/com/alibaba/druid/util/MySqlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ public static java.util.Date parseDate(String str, TimeZone timeZone) {

public static long parseMillis(byte[] str, TimeZone timeZone) {
if (str == null) {
throw new IllegalArgumentException(new String(str, UTF8));
throw new IllegalArgumentException("str not be null");
}

return parseMillis(str, 0, str.length, timeZone);
Expand All @@ -1435,7 +1435,7 @@ public static long parseMillis(final byte[] str, final int off, final int len, f

public static ZonedDateTime parseDateTime(final byte[] str, final int off, final int len, ZoneId zoneId) {
if (str == null) {
throw new IllegalArgumentException(new String(str, UTF8));
throw new IllegalArgumentException("str not be null");
}

if (len < 8) {
Expand Down
24 changes: 24 additions & 0 deletions core/src/test/java/com/alibaba/druid/util/MySqlUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.alibaba.druid.util;

import junit.framework.TestCase;
import org.junit.Assert;

import java.time.ZoneId;
import java.util.TimeZone;

/**
* @author: ruansheng
* @date: 2024-01-22
*/
public class MySqlUtilsTest extends TestCase {

public void testParseMillis() {
Assert.assertThrows(IllegalArgumentException.class,
() -> MySqlUtils.parseMillis(null, TimeZone.getTimeZone("GMT+8")));
}

public void testParseDateTime() {
Assert.assertThrows(IllegalArgumentException.class,
() -> MySqlUtils.parseDateTime(null, 0, 0, ZoneId.systemDefault()));
}
}

0 comments on commit c34a7c0

Please sign in to comment.