my2iu / Jinq

LINQ-style queries for Java 8
Other
659 stars 71 forks source link

[BUG]: The concatenation of strings was not as expected #115

Closed zdu-strong closed 7 months ago

zdu-strong commented 7 months ago

The concatenation of strings was not as expected.

Expected: "a" + "b" + "c" = "abc"

Actual: "a" + "b" + "c" = "cba"

image image

My Repository: https://github.com/zdu-strong/Temp_Test_Of_Jinq Require Enviroment: java v21 Run Command: ./mvn clean test

my2iu commented 7 months ago

I'll take a look. On some of the compilers of newer JDKs, Java generates code that uses a lot of runtime code generation for string concatenation, and this code generation isn't documented too well, so it's been hard to get the code analysis for that stuff to work right.

my2iu commented 7 months ago

Concatenation of 2 things probably works fine, so if you need a workaround while I figure out what's going on, you could try something like:

select((s) -> {
   String temp = s.getName() + "a";
  return temp + "b";
}
zdu-strong commented 7 months ago

Thank you so much.

my2iu commented 7 months ago

It turns out, I simply wasn't handling string literals that were more than one character long. When I was trying to figure out the lambda stuff, I kept reversing and unreversing the passed in values to make things consistent, but as a result, I ended up reversing string literals that were longer than a single character.

Maven should now have a version 2.02 and 1.8.37 that should fix this issue.