JRI: use attribute-name length in rniGetAttrNames#351
Open
r-suzuki wants to merge 1 commit intos-u:masterfrom
Open
JRI: use attribute-name length in rniGetAttrNames#351r-suzuki wants to merge 1 commit intos-u:masterfrom
r-suzuki wants to merge 1 commit intos-u:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you for maintaining rJava/JRI.
This PR proposes a small fix for what appears to be an issue in
rniGetAttrNameson R 4.6.0.In the R 4.6.0 code path, the attribute names are obtained with
R_getAttribNames(o)and stored inans, but the Java array size is currently taken fromXLENGTH(o).Since the length of the target object is independent of the number of attributes, zero-length objects with attributes can return
null.This change uses
XLENGTH(ans)for the Java array size, matching the later loop overans.The minimal failing case is:
This object has length 0, but it has one attribute name,
foo.Test program
Save as
rtest_attrnames.javaand run with:Result with R 4.5.0
The test succeeds.
Result with R 4.6.0 before this change
The first case fails, and the program terminates with a
RuntimeException.Result with R 4.6.0 after this change
The test succeeds.
Thank you for taking a look. Please let me know if I missed anything.