Skip to content

Commit

Permalink
move check to the start of method
Browse files Browse the repository at this point in the history
  • Loading branch information
albfernandez committed May 31, 2023
1 parent c6c6892 commit 2e4f5e4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/linuxense/javadbf/DBFWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ public void setFields(DBFField[] fields) {
if (this.closed) {
throw new IllegalStateException("You can not set fields to a closed DBFWriter");
}
try {
if (this.raf != null && this.raf.length() > 0) {
throw new DBFException("You can not change fields on an existing file");
}
}
catch (IOException e) {
throw new DBFException("Error accesing file:" + e.getMessage(), e);
}
if (this.header.fieldArray != null) {
throw new DBFException("Fields has already been set");
}
Expand All @@ -194,6 +202,7 @@ public void setFields(DBFField[] fields) {
if (fields.length > 255) {
throw new DBFException("Exceded column limit of 255 (" + fields.length + ")");
}

List<Integer> fieldsWithNull = new ArrayList<Integer>();
for (int i = 0; i < fields.length; i++) {
if (fields[i] == null) {
Expand Down Expand Up @@ -221,9 +230,6 @@ public void setFields(DBFField[] fields) {


try {
if (this.raf != null && this.raf.length() > 0) {
throw new DBFException("You can not change fields on an existing file");
}
if (this.raf != null && this.raf.length() == 0) {
// this is a new/non-existent file. So write header before proceeding
this.header.write(this.raf);
Expand Down

0 comments on commit 2e4f5e4

Please sign in to comment.