I just realized that exceptions thrown by Spark subsystem must be SparkException. So instead of assert, it should throw SparkException. So it may be better to have a method in broadcast called verify() which throws the exception, and everything (subclasses and all) calls that method.