-
Notifications
You must be signed in to change notification settings - Fork 115
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
DatatypeConverter.parseBoolean converts invalid strings to true #1695
Comments
Hi, @johannesherr: A possible solution:
Regards, |
laurentschoelens
added a commit
to laurentschoelens/jaxb-ri
that referenced
this issue
Sep 6, 2023
laurentschoelens
added a commit
to laurentschoelens/jaxb-ri
that referenced
this issue
Sep 17, 2023
…ue boolean impl now has same results as api but returning null instead of exception according to jakartaee/jaxb-api#240
laurentschoelens
added a commit
to laurentschoelens/jaxb-ri
that referenced
this issue
Sep 17, 2023
…ue boolean impl now has same results as api but returning null instead of exception according to jakartaee/jaxb-api#240
lukasj
pushed a commit
that referenced
this issue
Oct 6, 2023
impl now has same results as api but returning null instead of exception according to jakartaee/jaxb-api#240
lukasj
pushed a commit
to lukasj/jaxb-ri
that referenced
this issue
Oct 9, 2023
…ue boolean impl now has same results as api but returning null instead of exception according to jakartaee/jaxb-api#240 (cherry picked from commit 36eb718)
lukasj
pushed a commit
that referenced
this issue
Oct 13, 2023
impl now has same results as api but returning null instead of exception according to jakartaee/jaxb-api#240 (cherry picked from commit 36eb718)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The method
parseBoolean
injavax.xml.bind.DatatypeConverterImpl
is supposed to convert only the values"true"
and"1"
totrue
(while ignoring leading and trailing whitespace). It, however, converts all strings totrue
that start with"tru"
and are 4-5 characters long. For example:This is caused by these segments in
parseBoolean
:and:
In the first snippet
value
is assignedtrue
also when the loop was left after comparing the third character, because the expressionstrTrue.charAt(strIndex++) == ch
was false (that is when there is as mismatch between 'e' and the current character). strIndex will still be 3 (because it is incremented unconditionally).That explains why
"trux"
is converter totrue
. The second snippet explains why the additional character in"truxx"
is also ignored. If we haven't read the input completely the second input checks if there is whitespace to ignore. However it also uses an unconditional increment of the reading position, which causes the code to skip over the offending last character. Thereforei == len
holds and the previously assignedtrue
is returned.The text was updated successfully, but these errors were encountered: