Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw exception instead of assert(false) #1195

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cdm/core/src/main/java/ucar/nc2/EnumTypedef.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected void writeCDL(Formatter out, Indent indent, boolean strict) {
basetype = "";
break;
default:
assert false : "Internal error";
throw new IllegalStateException("Unexpected basetype = " + basetype);
}
out.format("%s%senum %s { ", indent, basetype, name);
int count = 0;
Expand Down
2 changes: 1 addition & 1 deletion cdm/core/src/main/java/ucar/nc2/write/CDLWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private void writeCDL(EnumTypedef e, Indent indent) {
basetype = "";
break;
default:
assert false : "Internal error";
throw new IllegalStateException("Unexpected basetype = " + e.getBaseType());
}
out.format("%s%senum %s { ", indent, basetype, name);
int count = 0;
Expand Down
4 changes: 2 additions & 2 deletions dap4/src/main/java/dap4/core/ce/CECompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected void compileAST(CEAST ast) throws DapException {
dimredef(ast);
break;
default:
assert false : "uknown CEAST node type";
throw new IllegalStateException("unknown CEAST node type = " + ast.sort);
}
}

Expand Down Expand Up @@ -118,7 +118,7 @@ protected DapVariable compilesegment(CEAST ast) throws DapException {
node = seq.findByName(ast.name);
break;
default:
assert false : "Container cannot be atomic variable";
throw new DapException("Container cannot be atomic variable, sort = " + parent.getSort());
}
default:
throw new DapException("relative names must be WRT to structure|dataset object: " + parent.getFQN());
Expand Down
2 changes: 1 addition & 1 deletion dap4/src/main/java/dap4/core/ce/parser/CEParserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Slice subslice(int state, String sfirst, String send, String sstride) throws Par
case 5: // [f:s:]
break;
default:
assert false : "Illegal slice case";
throw new ParseException("Illegal slice case, state = " + state);
}
} catch (DapException de) {
throw new ParseException(de);
Expand Down
5 changes: 2 additions & 3 deletions dap4/src/main/java/dap4/core/dmr/DMRPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,11 @@ public boolean printNode(DapNode node) throws IOException {
printer.outdent();
printer.marginPrint("</" + type.getTypeSort().name() + ">");
} else
assert false : "Illegal variable base type";
throw new IllegalStateException("Illegal variable base type");
break;

default:
assert (false) : "Unexpected sort: " + sort.name();
break;
throw new IllegalStateException("Unexpected sort: " + sort.name());
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion dap4/src/main/java/dap4/core/dmr/DapGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void updateGroups(List<DapGroup> groups) {
assert (groups.size() == this.groups.size()) : "Update groups: not same size";
for (DapGroup g : groups) {
if (!this.groups.contains(g))
assert (false) : "Update groups: attempt to add new group";
throw new IllegalStateException("Update groups: attempt to add new group");
}
}

Expand Down
2 changes: 1 addition & 1 deletion dap4/src/main/java/dap4/core/dmr/DapNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ else if (this instanceof DapEnumConst)
else if (this instanceof DapMap)
this.sort = DapSort.MAP;
else
assert (false) : "Internal error";
throw new IllegalStateException("Unexpected type = " + this.getClass());
}

public DapNode(String shortname) {
Expand Down
2 changes: 1 addition & 1 deletion dap4/src/main/java/dap4/core/dmr/parser/DOM4Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ protected void addField(DapType t, DapVariable field) throws DapException {
field.setParent(t);
break;
default:
assert false : "Container must be struct or seq";
throw new IllegalStateException("Container must be struct or seq, sort = " + t.getTypeSort());
}
}

Expand Down
2 changes: 1 addition & 1 deletion dap4/src/main/java/dap4/core/util/DapUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ static public List<DapVariable> getStructurePath(DapVariable var) {
structpath.add((DapVariable) node);
break;
default:
assert false : "Internal error";
throw new IllegalStateException("Internal error, sort = " + node.getSort());
}
}
return structpath;
Expand Down
2 changes: 1 addition & 1 deletion dap4/src/main/java/dap4/dap4lib/D4DataCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public Array createArray(DapVariable var, Object storage) {
case STRUCTURE:
case SEQUENCE:
default:
assert false;
throw new IllegalStateException("Unexpected scheme = " + schemeFor(var));
}
return array;
}
Expand Down
5 changes: 3 additions & 2 deletions dap4/src/main/java/dap4/dap4lib/cdm/nc2/DMRToCDM.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ protected void createVar(DapVariable dapvar, NetcdfFile ncfile, Group cdmgroup,
cdmvar.addAttribute(warning);
}

} else
assert (false) : "Unknown variable sort: " + dapvar.getSort();
} else {
throw new IllegalStateException("Unknown variable sort: " + dapvar.getSort());
}
int rank = dapvar.getRank();
List<Dimension> cdmdims = new ArrayList<Dimension>(rank + 1); // +1 for vlen
for (int i = 0; i < rank; i++) {
Expand Down