Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-35234][hotfix][cdc-common] Fix NullPointerException of org.apache.flink.cdc.common.configuration.ConfigurationUtils#convertToString #3255

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class ConfigurationUtils {
*/
@SuppressWarnings("unchecked")
public static <T> T convertValue(Object rawValue, Class<?> clazz) {
if (rawValue == null) {
return null;
}
if (Integer.class.equals(clazz)) {
return (T) convertToInt(rawValue);
} else if (Long.class.equals(clazz)) {
Expand All @@ -70,7 +73,9 @@ public static <T> T convertValue(Object rawValue, Class<?> clazz) {

@SuppressWarnings("unchecked")
static <T> T convertToList(Object rawValue, Class<?> atomicClass) {
if (rawValue instanceof List) {
if (rawValue == null) {
return null;
} else if (rawValue instanceof List) {
return (T) rawValue;
} else {
return (T)
Expand All @@ -82,7 +87,9 @@ static <T> T convertToList(Object rawValue, Class<?> atomicClass) {

@SuppressWarnings("unchecked")
static Map<String, String> convertToProperties(Object o) {
if (o instanceof Map) {
if (o == null) {
return null;
} else if (o instanceof Map) {
return (Map<String, String>) o;
} else {
List<String> listOfRawProperties =
Expand All @@ -102,7 +109,9 @@ static Map<String, String> convertToProperties(Object o) {

@SuppressWarnings("unchecked")
public static <E extends Enum<?>> E convertToEnum(Object o, Class<E> clazz) {
if (o.getClass().equals(clazz)) {
if (o == null) {
return null;
} else if (o.getClass().equals(clazz)) {
return (E) o;
}

Expand All @@ -122,15 +131,19 @@ public static <E extends Enum<?>> E convertToEnum(Object o, Class<E> clazz) {
}

static Duration convertToDuration(Object o) {
if (o.getClass() == Duration.class) {
if (o == null) {
return null;
} else if (o.getClass() == Duration.class) {
return (Duration) o;
}

return TimeUtils.parseDuration(o.toString());
}

static String convertToString(Object o) {
if (o.getClass() == String.class) {
if (o == null) {
Copy link
Contributor

@yuxiqian yuxiqian Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can bring the check to convertValue function? Seems other convertToXXX functions also have this problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, just done it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inner null check seems redundant now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inner null check seems redundant now.

@loserwang1024 WDYT?

return null;
} else if (o.getClass() == String.class) {
return (String) o;
} else if (o.getClass() == Duration.class) {
Duration duration = (Duration) o;
Expand Down Expand Up @@ -165,7 +178,9 @@ static String convertToString(Object o) {
}

static Integer convertToInt(Object o) {
if (o.getClass() == Integer.class) {
if (o == null) {
return null;
} else if (o.getClass() == Integer.class) {
return (Integer) o;
} else if (o.getClass() == Long.class) {
long value = (Long) o;
Expand All @@ -183,7 +198,9 @@ static Integer convertToInt(Object o) {
}

static Long convertToLong(Object o) {
if (o.getClass() == Long.class) {
if (o == null) {
return null;
} else if (o.getClass() == Long.class) {
return (Long) o;
} else if (o.getClass() == Integer.class) {
return ((Integer) o).longValue();
Expand All @@ -193,7 +210,9 @@ static Long convertToLong(Object o) {
}

static Boolean convertToBoolean(Object o) {
if (o.getClass() == Boolean.class) {
if (o == null) {
return null;
} else if (o.getClass() == Boolean.class) {
return (Boolean) o;
}

Expand All @@ -211,6 +230,9 @@ static Boolean convertToBoolean(Object o) {
}

static Float convertToFloat(Object o) {
if (o == null) {
return null;
}
if (o.getClass() == Float.class) {
return (Float) o;
} else if (o.getClass() == Double.class) {
Expand All @@ -231,6 +253,9 @@ static Float convertToFloat(Object o) {
}

static Double convertToDouble(Object o) {
if (o == null) {
return null;
}
if (o.getClass() == Double.class) {
return (Double) o;
} else if (o.getClass() == Float.class) {
Expand Down