Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException when settings set to [] during index creation #45126

Closed
thewunder opened this issue Aug 2, 2019 · 6 comments · Fixed by #45588
Closed

ClassCastException when settings set to [] during index creation #45126

thewunder opened this issue Aug 2, 2019 · 6 comments · Fixed by #45588
Labels
:Core/Infra/Settings Settings infrastructure and APIs feedback_needed

Comments

@thewunder
Copy link

Elasticsearch version: 6.8.2

Plugins installed: repository-s3

JVM version:
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~16.04.1-b10)

OS version:
Linux ip-172-31-37-249 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Description of the problem including expected versus actual behavior:
Passing an a

Steps to reproduce:

curl -X PUT "localhost:9200/myindex" -H 'Content-Type: application/json' -d'
{
   "settings" : []
}                  
'

Stack Trace:

java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map
        at org.elasticsearch.action.admin.indices.create.CreateIndexRequest.source(CreateIndexRequest.java:386) ~[elasticsearch-6.8.2.jar:6.8.2]
        at org.elasticsearch.rest.action.admin.indices.RestCreateIndexAction.prepareRequest(RestCreateIndexAction.java:71) ~[elasticsearch-6.8.2.jar:6.8.2]
        at org.elasticsearch.rest.BaseRestHandler.handleRequest(BaseRestHandler.java:91) ~[elasticsearch-6.8.2.jar:6.8.2]
        at org.elasticsearch.xpack.security.rest.SecurityRestFilter.handleRequest(SecurityRestFilter.java:87) ~[?:?]
        at org.elasticsearch.rest.RestController.dispatchRequest(RestController.java:240) [elasticsearch-6.8.2.jar:6.8.2]
        at org.elasticsearch.rest.RestController.tryAllHandlers(RestController.java:336) [elasticsearch-6.8.2.jar:6.8.2]
        at org.elasticsearch.rest.RestController.dispatchRequest(RestController.java:174) [elasticsearch-6.8.2.jar:6.8.2]
        at org.elasticsearch.http.netty4.Netty4HttpServerTransport.dispatchRequest(Netty4HttpServerTransport.java:551) [transport-netty4-client-6.8.2.jar:6.8.2]

@DaveCTurner DaveCTurner added :Core/Infra/Settings Settings infrastructure and APIs feedback_needed labels Aug 2, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@DaveCTurner
Copy link
Contributor

What exactly do you think is wrong with this behaviour @thewunder? The request isn't valid so throwing some kind of exception is the right thing to do.

@DaveCTurner
Copy link
Contributor

Closing this for want of feedback. We can always reopen it if we hear back from @thewunder.

@thewunder
Copy link
Author

@DaveCTurner

org.elasticsearch.ElasticsearchParseException or org.elasticsearch.action.ActionRequestValidationException?

To me as a user, if I am passing invalid input I would expect to see something Validation or parse related and tell me the error made. Internal java exceptions are the least informative type of error.

rjernst added a commit to rjernst/elasticsearch that referenced this issue Aug 14, 2019
This commit adds an explicit error message when a create index request
contains a settings key that is not a json object. Prior to this change
the user would be given a ClassCastException with no explanation of what
went wrong.

closes elastic#45126
@rjernst
Copy link
Member

rjernst commented Aug 14, 2019

@thewunder I agree with you, a ClassCastException can be confusing for users that don't understand the connection between Map in the sent request needing to contain a json object, nor where the error occurred within the request body. I've opened #45588 to address this.

@rjernst rjernst reopened this Aug 14, 2019
rjernst added a commit that referenced this issue Aug 16, 2019
This commit adds an explicit error message when a create index request
contains a settings key that is not a json object. Prior to this change
the user would be given a ClassCastException with no explanation of what
went wrong.

closes #45126
rjernst added a commit that referenced this issue Aug 16, 2019
This commit adds an explicit error message when a create index request
contains a settings key that is not a json object. Prior to this change
the user would be given a ClassCastException with no explanation of what
went wrong.

closes #45126
@thewunder
Copy link
Author

Thanks @rjernst looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Settings Settings infrastructure and APIs feedback_needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants