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

Already on GitHub? Sign in to your account

custom error message for missing default constructor #29

Closed
stephanos opened this Issue Jul 14, 2011 · 1 comment

Comments

Projects
None yet
2 participants

I recently forgot to define a default constructor (when using reflection) and had a hard time discovering what I did wrong. The error message was "next on empty iterator" coming from:

def newInstance[T](clazz: Class[T])(op: T => Unit): T = {
    val constructor =
      clazz.getDeclaredConstructors.filter(_.getParameterTypes.length == 0).head

Maybe you could turn it into something like:

def newInstance[T](clazz: Class[T])(op: T => Unit): T = {
    val constructor =
            clazz.getDeclaredConstructors.filter(_.getParameterTypes.length == 0)
                    .headOption.getOrElse(sys.error("no default constructor found on " + clazz))

This way it would be much easier to find the reason for the exception!

Cheers!

@debasishg debasishg closed this in e7bd99e Aug 1, 2011

Owner

debasishg commented Aug 1, 2011

Fixed on master ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment