Fixed a bug introduced with StringUtils#split

- ConfigReader relied on empty Strings when splitting lines,
  StringUtils removed empty strings from the split array.
This commit is contained in:
Rsl1122 2019-08-30 15:37:58 +03:00
parent 4547272783
commit 6ff04d3bdf
4 changed files with 7 additions and 5 deletions

View File

@ -79,7 +79,7 @@ public class ConfigNode {
}
private String[] splitPathInTwo(String path) {
String[] split = StringUtils.split(path, "\\.", 2);
String[] split = StringUtils.split(path, ".", 2);
if (split.length <= 1) {
return new String[]{split[0], ""};
}

View File

@ -17,13 +17,13 @@
package com.djrapitops.plan.system.settings.config;
import com.djrapitops.plugin.utilities.Verify;
import org.apache.commons.lang3.StringUtils;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
@ -145,7 +145,9 @@ public class ConfigReader implements Closeable {
private ConfigNode parseNode(String line) {
// Parse a node "Key: value"
String[] keyAndValue = StringUtils.split(line, ":", 2);
// Can not use StringUtils.split(line, ":", 2) - Relies on 2nd empty String for parent node parsing
String[] keyAndValue = line.split(":", 2);
System.out.println(Arrays.toString(keyAndValue));
if (keyAndValue.length <= 1) {
return handleMultiline(line);
}

View File

@ -162,7 +162,7 @@ public interface ConfigValueParser<T> {
@Override
public List<String> compose(String fromValue) {
List<String> values = new ArrayList<>();
for (String line : StringUtils.split(fromValue, "\\n")) {
for (String line : StringUtils.split(fromValue, "\n")) {
if (line.trim().isEmpty()) {
continue;
}

View File

@ -114,7 +114,7 @@ public class ConfigWriter {
} else if (StringUtils.contains(value, "\n")) {
// List values include newline characters,
// see ConfigValueParser.StringListParser
addListValue(key, StringUtils.split(value, "\\n"), lines);
addListValue(key, StringUtils.split(value, "\n"), lines);
} else {
addNormalValue(key, value, lines);
}