java.lang.IllegalArgumentException: The field type is required

tip

If you're unit testing, you should instantiate only the service and mock the dependencies. If you're testing integration, you should add all the mocking to the configurations file.

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • Given this code: public class Survey { private Map<Question, Response> responses = new HashMap<Question,Response>(); ... } public class QuestionConverter implements Converter<Integer, Question> { ... } <form:input path="responses[1].value" /> During rendering, the expression "responses[1].value" is processed correctly by Spring EL, which converts the integer 1 to a Question, then does a look up in the responses map, and then converts the "value" field to a String. At this point this should be all that is needed. However, the following exception occurs: java.lang.IllegalArgumentException: The field type is required at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.webflow.mvc.view.ConvertingPropertyEditorAdapter.<init>(ConvertingPropertyEditorAdapter.java:48) at org.springframework.webflow.mvc.view.BindingModel.findSpringConvertingPropertyEditor(BindingModel.java:273) at org.springframework.webflow.mvc.view.BindingModel.findEditor(BindingModel.java:183) at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:125) at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174) Spring MVC's BindStatus tries to find a PropertyEditor but the above expression cannot be processed by the BeanWrapperImpl because it fails to recognize that 1 needs to be converted to a Question. It would be safe if we didn't create a ProperytEditor when the BeanWrapperImpl fails as Spring EL has already formatted the value correctly.
    via by Rossen Stoyanchev,
  • Given this code: public class Survey { private Map<Question, Response> responses = new HashMap<Question,Response>(); ... } public class QuestionConverter implements Converter<Integer, Question> { ... } <form:input path="responses[1].value" /> During rendering, the expression "responses[1].value" is processed correctly by Spring EL, which converts the integer 1 to a Question, then does a look up in the responses map, and then converts the "value" field to a String. At this point this should be all that is needed. However, the following exception occurs: java.lang.IllegalArgumentException: The field type is required at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.webflow.mvc.view.ConvertingPropertyEditorAdapter.<init>(ConvertingPropertyEditorAdapter.java:48) at org.springframework.webflow.mvc.view.BindingModel.findSpringConvertingPropertyEditor(BindingModel.java:273) at org.springframework.webflow.mvc.view.BindingModel.findEditor(BindingModel.java:183) at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:125) at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174) Spring MVC's BindStatus tries to find a PropertyEditor but the above expression cannot be processed by the BeanWrapperImpl because it fails to recognize that 1 needs to be converted to a Question. It would be safe if we didn't create a ProperytEditor when the BeanWrapperImpl fails as Spring EL has already formatted the value correctly.
    via by Rossen Stoyanchev,
  • When I use this tag {noformat} <form:input path="myMap[${entry.key}]..." /> Map<Long, MyViewModel> myMap;{noformat} and entry.key is bigger then an int (ex. 5,000,000,000), I get following error {noformat} org.springframework.expression.spel.SpelParseException: EL1035E:(pos 14): The value '5000000000' cannot be parsed as an int at org.springframework.expression.spel.ast.Literal.getIntLiteral(Literal.java:79) at org.springframework.expression.spel.standard.InternalSpelExpressionParser.maybeEatLiteral(InternalSpelExpressionParser.java:688)...{noformat} In the maybeEatLiteral method it seems that Long should be supported, but int is chosen. {noformat} private boolean maybeEatLiteral() { Token t = peekToken(); if (t == null) { return false; } if (t.kind == TokenKind.LITERAL_INT) push(Literal.getIntLiteral(t.data, toPos(t), 10)); else if (t.kind == TokenKind.LITERAL_LONG) push(Literal.getLongLiteral(t.data, toPos(t), 10)); else if (t.kind == TokenKind.LITERAL_HEXINT) push(Literal.getIntLiteral(t.data, toPos(t), 16)); else if (t.kind == TokenKind.LITERAL_HEXLONG) push(Literal.getLongLiteral(t.data, toPos(t), 16)); else if (t.kind == TokenKind.LITERAL_REAL) push(Literal.getRealLiteral(t.data, toPos(t), false)); else if (t.kind == TokenKind.LITERAL_REAL_FLOAT) push(Literal.getRealLiteral(t.data, toPos(t), true)); else if (peekIdentifierToken("true")) push(new BooleanLiteral(t.data, toPos(t), true)); else if (peekIdentifierToken("false")) push(new BooleanLiteral(t.data, toPos(t), false)); else if (t.kind == TokenKind.LITERAL_STRING) push(new StringLiteral(t.data, toPos(t), t.data)); else { return false; } nextToken(); return true; } {noformat} When I add an L to make it a java Long -> 5000000000L {noformat} <form:input path="myMap[${entry.key}L]..." />{noformat} I got an other error: {noformat} java.lang.IllegalArgumentException: The field type is required at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.webflow.mvc.view.ConvertingPropertyEditorAdapter.<init>(ConvertingPropertyEditorAdapter.java:48) at org.springframework.webflow.mvc.view.BindingModel.findSpringConvertingPropertyEditor(BindingModel.java:277) at org.springframework.webflow.mvc.view.BindingModel.findEditor(BindingModel.java:183) at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:125) at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:179) at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:199)... {noformat}
    via by Sven Smets,
  • When I use this tag {noformat} <form:input path="myMap[${entry.key}]..." /> Map<Long, MyViewModel> myMap;{noformat} and entry.key is bigger then an int (ex. 5,000,000,000), I get following error {noformat} org.springframework.expression.spel.SpelParseException: EL1035E:(pos 14): The value '5000000000' cannot be parsed as an int at org.springframework.expression.spel.ast.Literal.getIntLiteral(Literal.java:79) at org.springframework.expression.spel.standard.InternalSpelExpressionParser.maybeEatLiteral(InternalSpelExpressionParser.java:688)...{noformat} In the maybeEatLiteral method it seems that Long should be supported, but int is chosen. {noformat} private boolean maybeEatLiteral() { Token t = peekToken(); if (t == null) { return false; } if (t.kind == TokenKind.LITERAL_INT) push(Literal.getIntLiteral(t.data, toPos(t), 10)); else if (t.kind == TokenKind.LITERAL_LONG) push(Literal.getLongLiteral(t.data, toPos(t), 10)); else if (t.kind == TokenKind.LITERAL_HEXINT) push(Literal.getIntLiteral(t.data, toPos(t), 16)); else if (t.kind == TokenKind.LITERAL_HEXLONG) push(Literal.getLongLiteral(t.data, toPos(t), 16)); else if (t.kind == TokenKind.LITERAL_REAL) push(Literal.getRealLiteral(t.data, toPos(t), false)); else if (t.kind == TokenKind.LITERAL_REAL_FLOAT) push(Literal.getRealLiteral(t.data, toPos(t), true)); else if (peekIdentifierToken("true")) push(new BooleanLiteral(t.data, toPos(t), true)); else if (peekIdentifierToken("false")) push(new BooleanLiteral(t.data, toPos(t), false)); else if (t.kind == TokenKind.LITERAL_STRING) push(new StringLiteral(t.data, toPos(t), t.data)); else { return false; } nextToken(); return true; } {noformat} When I add an L to make it a java Long -> 5000000000L {noformat} <form:input path="myMap[${entry.key}L]..." />{noformat} I got an other error: {noformat} java.lang.IllegalArgumentException: The field type is required at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.webflow.mvc.view.ConvertingPropertyEditorAdapter.<init>(ConvertingPropertyEditorAdapter.java:48) at org.springframework.webflow.mvc.view.BindingModel.findSpringConvertingPropertyEditor(BindingModel.java:277) at org.springframework.webflow.mvc.view.BindingModel.findEditor(BindingModel.java:183) at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:125) at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:179) at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:199)... {noformat}
    via by Sven Smets,
  • Hashmap in Spring form
    via Stack Overflow by user1128017
    ,
  • Spring Boot test class wont inject beans
    via Stack Overflow by rayman
    ,
  • Spring file upload by ajax
    via Stack Overflow by kris14an
    ,
    • java.lang.IllegalArgumentException: The field type is required at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.webflow.mvc.view.ConvertingPropertyEditorAdapter.<init>(ConvertingPropertyEditorAdapter.java:48) at org.springframework.webflow.mvc.view.BindingModel.findSpringConvertingPropertyEditor(BindingModel.java:273) at org.springframework.webflow.mvc.view.BindingModel.findEditor(BindingModel.java:183) at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:125) at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)

    Users with the same issue

    Unknown visitor1 times, last one,
    osvzs
    osvzs2 times, last one,
    odd
    odd2 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    189 more bugmates