Better error message when generic types are erased from scala collections.

This commit is contained in:
Khalid Shakir 2012-10-22 16:27:31 -04:00
parent 008df54575
commit fd59e7d5f6
2 changed files with 6 additions and 0 deletions

View File

@ -352,6 +352,9 @@ public class UserException extends ReviewedStingException {
}
public static class CannotExecuteQScript extends UserException {
public CannotExecuteQScript(String message) {
super(String.format("Unable to execute QScript: " + message));
}
public CannotExecuteQScript(String message, Exception e) {
super(String.format("Unable to execute QScript: " + message), e);
}

View File

@ -28,6 +28,7 @@ import collection.JavaConversions._
import org.broadinstitute.sting.queue.QException
import java.lang.Class
import org.broadinstitute.sting.commandline.{ArgumentMatches, ArgumentSource, ArgumentTypeDescriptor, ParsingEngine}
import org.broadinstitute.sting.utils.exceptions.UserException
import java.lang.reflect.Type
/**
@ -75,6 +76,8 @@ class ScalaCompoundArgumentTypeDescriptor extends ArgumentTypeDescriptor {
def parse(parsingEngine: ParsingEngine, source: ArgumentSource, classType: Class[_], argumentMatches: ArgumentMatches) = {
val componentType = ReflectionUtils.getCollectionType(source.field)
if (componentType == classOf[java.lang.Object])
throw new UserException.CannotExecuteQScript("Please also include a @ClassType(classOf[<primitive type>]) annotation on field: " + source.field + ". Example: @ClassType(classOf[Double]). The scala generic type for the field was subjected to java/scala type erasure and is not available via reflection.")
val componentArgumentParser = parsingEngine.selectBestTypeDescriptor(componentType)
if (classOf[Seq[_]].isAssignableFrom(classType)) {