Language: Java
Label: safe
CWE: NVD-CWE-noinfo \u2014 

Code:
    public static String removeMatrixVariables(String path) {
        int semicolonIndex = path.indexOf(';');
        if (semicolonIndex < 0) {
            return path;
        }
        if (semicolonIndex == 0 || path.charAt(semicolonIndex - 1) == '/') {
            // Invalid matrix variable e.g. /;a=b/foo
            return null;
        }
        int subStringStartIndex = 0;
        try (TemporaryThreadLocals threadLocals = TemporaryThreadLocals.acquire()) {
            final StringBuilder sb = threadLocals.stringBuilder();
            for (;;) {
                sb.append(path, subStringStartIndex, semicolonIndex);
                final int slashIndex = path.indexOf('/', semicolonIndex + 1);
                if (slashIndex < 0) {
                    return sb.toString();
                }
                subStringStartIndex = slashIndex;
                semicolonIndex = path.indexOf(';', subStringStartIndex + 1);
                if (semicolonIndex < 0) {
                    sb.append(path, subStringStartIndex, path.length());
                    return sb.toString();
                }
                if (path.charAt(semicolonIndex - 1) == '/') {
                    // Invalid matrix variable e.g. /prefix/;a=b/foo
                    return null;
                }
            }
        }
    }