Avoid unintended control fall-through in case of weird enum value
This `switch` statement currently covers all possible values of the `enum` it is testing. However, if a new value were introduced in the future, the `switch` would have allowed control-flow to fall through by default instead of throwing an exception as is done in all of the other cases. Better to throw *some* kind of exception in the default case too.
This commit is contained in:
parent
7dc71151d1
commit
ce335f495d
|
@ -17,6 +17,8 @@
|
|||
|
||||
package com.ibm.wala.sourcepos;
|
||||
|
||||
import com.ibm.wala.sourcepos.InvalidRangeException.Cause;
|
||||
|
||||
/**
|
||||
* This class represents an entry in the CharacterRangeTable.
|
||||
*
|
||||
|
@ -117,13 +119,16 @@ public final class CRTData {
|
|||
try {
|
||||
range = new Range(source_start, source_end);
|
||||
} catch (InvalidRangeException e) {
|
||||
switch (e.getThisCause()) {
|
||||
final Cause cause = e.getThisCause();
|
||||
switch (cause) {
|
||||
case END_BEFORE_START:
|
||||
throw new InvalidCRTDataException(WARN_END_BEFORE_START, source_start.toString(), source_end.toString());
|
||||
case START_UNDEFINED:
|
||||
throw new InvalidCRTDataException(WARN_START_UNDEFINED);
|
||||
case END_UNDEFINED:
|
||||
throw new InvalidCRTDataException(WARN_END_UNDEFINED);
|
||||
default:
|
||||
throw new UnsupportedOperationException(String.format("cannot convert %s into an InvalidCRTDataException", cause));
|
||||
}
|
||||
} finally {
|
||||
this.source_positions = range;
|
||||
|
|
Loading…
Reference in New Issue