samskivert
samskivert » “Duplicate field expected”

January 24, 2010

“Duplicate field expected”

In my recent programming adventures, I separately encountered two perplexing error messages:

  • RuntimeException: Variable is used without definition!
  • IllegalArgumentException: Duplicate field expected

Inspection of the underlying code brought clarity:

  • throw new RuntimeException("Variable " + m + " used without definition!");
  • throw new IllegalArgumentException("Duplicate field " + fieldName);

The former was reporting a problem with a variable declared as InputStream is, the latter a problem with JUnit’s @Test annotation which defines a parameter java.lang.Class<? extends java.lang.Throwable> expected.

Tip from the pros: always wrap identifiers in quotes when including them in error messages.

Posted to code by mdb at 4:33 pm | Comments (1)       

One Response to ““Duplicate field expected””

  1. paulp says:

    For some reason (maybe the early hour) I found those examples hysterical. There is a related issue which comes up in scala all the time when people do something like shadow a type parameter: “Error: type ‘T’ expected but type ‘T’ found.” “WTF” people say, but it’s super noisy to fully qualify everything all the time, and the errors emerge from all kinds of different places, so now some places selectively expand but it’s a mixed bag.

    P.S. Don’t name your variables “is”.

Leave a Reply

You must be logged in to post a comment.

MDB

Bits
Ludography
Reviewlets
Camera Wrestling
Archives:

samskivert.com ©2001 - 2009 Michael Bayne <mdb@samskivert.com>