Skip to content

Commit

Permalink
fix(rf2): validate line vs header length differences
Browse files Browse the repository at this point in the history
  • Loading branch information
cmark committed May 1, 2024
1 parent 70b6a06 commit 6c615e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<setEntry value="org.hamcrest@default:default"/>
<setEntry value="org.hdrhistogram.HdrHistogram@default:default"/>
<setEntry value="org.jetbrains.kotlin.osgi-bundle@default:default"/>
<setEntry value="org.jsr-305@default:default"/>
<setEntry value="org.junit@default:default"/>
<setEntry value="org.mockito.mockito-core@default:default"/>
<setEntry value="org.objectweb.asm.commons@default:default"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;

import org.mapdb.DB;
import org.mapdb.DBMaker;
import org.mapdb.DBMaker.Maker;
Expand Down Expand Up @@ -101,6 +97,10 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;

/**
* @since 6.0.0
*/
Expand Down Expand Up @@ -383,14 +383,14 @@ private void readFile(ZipEntry entry, final InputStream in, final ObjectReader o
header = false;
} else {
final ImportDefectBuilder defectBuilder = defectAcceptor.on(Integer.toString(lineNumber));
if (line.length > 1) {
if (line.length == 0) {
// line is empty, skip it (TODO do we need a warning here?)
} else if (line.length == resolver.getHeaderColumns().length) {
final String effectiveTimeKey = getEffectiveTimeKey(line[1]);
resolver.register(line, effectiveTimeSlices.getOrCreate(effectiveTimeKey), defectBuilder);
} else if (line.length == 1) {
// report error if line is not empty but there is no effective time column present
defectBuilder.error("Incorrect/broken RF2 line detected");
} else {
// line is empty, skip it (TODO do we need a warning here?)
// report error if line has column number differences compared to the expected number of header columns
defectBuilder.error("RF2 line has different number of values (%s) than the expected number of header columns (%s)", line.length, resolver.getHeaderColumns().length);
}
}

Expand Down

0 comments on commit 6c615e8

Please sign in to comment.