Skip to content

Commit

Permalink
[rf2] report incorrect number of columns during transform
Browse files Browse the repository at this point in the history
Make sure values are never written out as `null` (will be converted to
empty string) in transform command.
  • Loading branch information
cmark committed Jun 3, 2019
1 parent 7d3df29 commit 633aa31
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/java/com/b2international/rf2/model/RF2ContentFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,19 @@ public void transform(RF2TransformContext context) throws IOException {
params.put("_file", this);

final String[] header = getHeader();
if (header.length != line.length) {
context.warn("Incorrect number of columns in line: %s", Arrays.toString(line));
try {
// just write the line back as is
writer.write(newLine(line));
} catch (IOException e) {
throw new RuntimeException(e);
}
continue;
}

for (int i = 0; i < line.length; i++) {
params.put(header[i], line[i]);
params.put(header[i], line[i]);
}

final Binding binding = new Binding(params);
Expand All @@ -215,7 +226,8 @@ public void transform(RF2TransformContext context) throws IOException {

final String[] newDataLine = new String[header.length];
for (int i = 0; i < header.length; i++) {
newDataLine[i] = String.valueOf(params.get(header[i]));
Object newValue = params.get(header[i]);
newDataLine[i] = newValue == null ? "" : String.valueOf(newValue);
}
if (!Arrays.equals(newDataLine, line)) {
numberOfModifiedRows++;
Expand Down

0 comments on commit 633aa31

Please sign in to comment.