You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flink.apache.org by "mytang0 (Jira)" <ji...@apache.org> on 2020/09/29 03:57:00 UTC

[jira] [Created] (FLINK-19443) runtime function 'splitIndex'

mytang0 created FLINK-19443:
-------------------------------

             Summary: runtime function 'splitIndex'
                 Key: FLINK-19443
                 URL: https://issues.apache.org/jira/browse/FLINK-19443
             Project: Flink
          Issue Type: Bug
          Components: Table SQL / Runtime
            Reporter: mytang0


runtime function 'splitIndex' has NPE problem (located in the SqlFunctionUtils class)

 

*NPE version:*

public static String splitIndex(String str, String separator, int index) {
    if (index < 0) {
        return null;
    }
    String[] values = StringUtils.splitByWholeSeparatorPreserveAllTokens(str, separator);
    if (index >= values.length) {
        return null;
    } else {
        return values[index];
    }
}

public static String splitIndex(String str, int character, int index) {
    if (character > 255 || character < 1 || index < 0) {
        return null;
    }
    String[] values = StringUtils.splitPreserveAllTokens(str, (char) character);
    if (index >= values.length) {
        return null;
    } else {
        return values[index];
    }
}

 

*Fix version:*

public static String splitIndex(String str, String separator, int index) {
    if (index < 0) {
        return null;
    }
    String[] values = StringUtils.splitByWholeSeparatorPreserveAllTokens(str, separator);
    if ({color:#FF0000}values == null ||{color} index >= values.length) {
        return null;
    } else {
        return values[index];
    }
}

public static String splitIndex(String str, int character, int index) {
    if (character > 255 || character < 1 || index < 0) {
        return null;
    }
    String[] values = StringUtils.splitPreserveAllTokens(str, (char) character);
    if ({color:#FF0000}values == null ||{color} index >= values.length) {
        return null;
    } else {
        return values[index];
    }
}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)