fix: handle primitive arrays in 'in' operator and .length field access - #461
Open
chenjunwenhao wants to merge 1 commit into
Open
fix: handle primitive arrays in 'in' operator and .length field access#461chenjunwenhao wants to merge 1 commit into
chenjunwenhao wants to merge 1 commit into
Conversation
The `in` operator (BaseBinaryOperator.inOperator) and array `.length`
field access (ReflectLoader.loadField) both cast arrays to Object[],
which throws ClassCastException for primitive arrays (int[], byte[],
char[], double[], etc.).
While QLExpress's `new int[]{}` syntax creates Integer[] internally
(via BuiltInTypesSet), primitive arrays from Java method returns
(e.g. String.getBytes() → byte[], String.toCharArray() → char[])
or context variables trigger this crash.
Fix: use java.lang.reflect.Array.getLength() and Array.get() instead
of Object[] cast, consistent with other array-handling code in the
codebase (ForEachInstruction, IndexInstruction, SliceInstruction, etc.).
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.
Summary
Fix
ClassCastExceptionwhen theinoperator or.lengthfield access encounters primitive arrays (byte[],int[],char[],double[], etc.) returned by Java methods or passed via execution context.Problem
Two locations in the codebase cast arrays directly to
Object[], which crashes for primitive arrays:BaseBinaryOperator.inOperator()(line 316):ReflectLoader.loadField()(line 85):While QLExpress's
new int[]{}syntax createsInteger[]internally (viaBuiltInTypesSet), primitive arrays from Java method returns (e.g.,String.getBytes()→byte[],String.toCharArray()→char[]) or context variables trigger this crash.Reproduction:
Fix
Use
java.lang.reflect.Array.getLength()andArray.get()instead ofObject[]cast. This is consistent with other array-handling code in the codebase (ForEachInstruction,IndexInstruction,SliceInstruction,SpreadGetFieldInstruction, etc.), all of which correctly usejava.lang.reflect.Arrayfor array operations.Tests
Added two test suite files:
testsuite/java/operator/in_primitive_array.ql— testsinandnot_inwithbyte[]fromString.getBytes()testsuite/java/property/primitive_array_length.ql— tests.lengthwithbyte[]fromString.getBytes()andchar[]fromString.toCharArray()Verified that:
ClassCastExceptionbefore the fix