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

[Painless] Add extensive tests for def to primitive casts #36455

Merged
merged 3 commits into from
Dec 11, 2018

Conversation

jdconrad
Copy link
Contributor

This adds tests for each possible cast of def to a primitive type both implicit and explicit. This also fixes a minor bug where we were only checking the type of a def to be Number in some explicit casts. This does not work because it allows possible unintended casts from BigInteger and BigDecimal to primitive types since they both extend Number but are not included as part of the Painless casting model.

@jdconrad jdconrad added >bug >test Issues or PRs that are addressing/adding tests :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache v7.0.0 v6.6.0 labels Dec 10, 2018
@jdconrad jdconrad requested a review from rjernst December 10, 2018 21:44
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@jdconrad jdconrad mentioned this pull request Dec 10, 2018
23 tasks
Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one question.

return ((Number)value).byteValue();
} else {
throw new ClassCastException("cannot explicitly cast " +
"def [" + PainlessLookupUtility.typeToUnboxedType(value.getClass()).getCanonicalName() + "] to byte");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't all the boxed types handled above? when would we hit this else case? I just wonder about using typoToUnboxedType on a non-boxed type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point :). Will fix.

@jdconrad
Copy link
Contributor Author

@rjernst Thanks for the review! Will commit as soon as CI completes.

@jdconrad jdconrad merged commit 13b1f19 into elastic:master Dec 11, 2018
jdconrad added a commit that referenced this pull request Dec 11, 2018
This adds tests for each possible cast of def to a primitive type both implicit 
and explicit. This also fixes a minor bug where we were only checking the type 
of a def to be Number in some explicit casts. This does not work because it 
allows possible unintended casts from BigInteger and BigDecimal to primitive 
types since they both extend Number but are not included as part of the 
Painless casting model.
jasontedor added a commit to dnhatn/elasticsearch that referenced this pull request Dec 11, 2018
* elastic/master: (36 commits)
  Add check for minimum required Docker version (elastic#36497)
  Minor search controller changes (elastic#36479)
  Add default methods to DocValueFormat (elastic#36480)
  Fix the mixed cluster REST test explain/11_basic_with_types.
  Modify `BigArrays` to take name of circuit breaker (elastic#36461)
  Move LoggedExec to minimumRuntime source set (elastic#36453)
  added 6.5.4 version
  Add test logging for elastic#35644
  Tests- added helper methods to ESRestTestCase for checking warnings (elastic#36443)
  SQL: move requests' parameters to requests JSON body (elastic#36149)
  [Zen2] Respect the no_master_block setting (elastic#36478)
  Require soft-deletes when access changes snapshot (elastic#36446)
  Switch more tests to zen2 (elastic#36367)
  [Painless] Add extensive tests for def to primitive casts (elastic#36455)
  Add setting to bypass Rollover action (elastic#36235)
  Try running CI against Zulu (elastic#36391)
  [DOCS] Reworked the shard allocation filtering info.  (elastic#36456)
  Log [initial_master_nodes] on formation failure (elastic#36466)
  converting ForbiddenPatternsTask to .java (elastic#36194)
  fixed typo
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >test Issues or PRs that are addressing/adding tests v6.6.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants