Be explicit when the proper default for a switch is to do nothing

Of course, doing nothing isn't always the right behavior.  Sometimes a
previously-unhandled value is truly unexpected and one should fail by
throwing an exception.  It may not always be clear whether an
exception or doing nothing is the right choice.  For some `switch`
statements affected by this commit, I initially guessed that throwing
an exception was the right default behavior, but was proven wrong when
doing so caused WALA regression test failures.  That's strong evidence
that the unmatched values were not really unexpected, but merely
should have been handled by doing nothing as before.
This commit is contained in:
Ben Liblit 2017-08-06 14:53:08 -05:00 committed by Manu Sridharan
parent ab791f8c41
commit da5f925cab
5 changed files with 12 additions and 8 deletions

View File

@ -816,6 +816,8 @@ public class ClosureExtractor extends CAstRewriterExt {
case CAstNode.CALL:
case CAstNode.NEW:
return false;
default:
// fall through to generic handlers below
}
for(int i=0;i<node.getChildCount();++i)
if(!noJumpsAndNoCalls(node.getChild(i)))

View File

@ -1127,6 +1127,9 @@ public class PDG<T extends InstanceKey> implements NumberedGraph<Statement> {
case HEAP_RET_CALLER:
HeapStatement h = (HeapStatement) N;
createHeapDataDependenceEdges(h.getLocation());
break;
default:
// do nothing
}
}
@ -1147,6 +1150,9 @@ public class PDG<T extends InstanceKey> implements NumberedGraph<Statement> {
case HEAP_RET_CALLER:
HeapStatement h = (HeapStatement) N;
createHeapDataDependenceEdges(h.getLocation());
break;
default:
// do nothing
}
}

View File

@ -107,8 +107,8 @@ public class JavaScriptEclipseProjectPath extends EclipseProjectPath<IIncludePat
case IIncludePathEntry.CPE_SOURCE:
resolveSourcePathEntry(JSLoader.JAVASCRIPT, true, cpeFromMainProject, e.getPath(), null, e.getExclusionPatterns(), "js");
break;
default:
throw new UnsupportedOperationException(String.format("unexpected classpath entry kind %s", entryKind));
default:
// do nothing
}
}

View File

@ -299,12 +299,8 @@ public class OfflineDynamicCallGraph {
case CONSTANT_Class:
entries.put(new CWStringItem(p.getCPClass(i), CONSTANT_Class), i);
break;
case CONSTANT_MethodHandle:
case CONSTANT_MethodType:
case CONSTANT_InvokeDynamic:
break;
default:
throw new UnsupportedOperationException(String.format("unexpected constant-pool item type %s", itemType));
// do nothing
}
}
}

View File

@ -1010,7 +1010,7 @@ public abstract class Compiler implements Constants {
curOffset += 2;
break;
default:
throw new UnsupportedOperationException(String.format("unexpected instruction opcode %s", opcode));
// do nothing
}
} else {
stackLenRef[0] = stackLen;