In AEM 6.5 we see "Operands are not of the same type: comparison is supported for Number types only. at org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperator.leq(BinaryOperator.java:214)" but not in AEM 6.4 servers.
The value of that object is an integer.
Thanks
Views
Replies
Total Likes
Hi @chinmayis865517 ,
The error message "Operands are not of the same type: comparison is supported for Number types only" in AEM 6.5 indicates that there is a type mismatch during a comparison operation in your HTL (Sightly) script. This issue wasn't present in AEM 6.4, which suggests there might have been a change in how AEM handles type conversions or comparisons in HTL.
Here’s how you can troubleshoot and resolve this issue:
Review the HTL script where the comparison is happening. Ensure that both operands in the comparison are of the same type. HTL is strongly typed, so even if the value looks like a number, it might be treated as a string.
To ensure both operands are of the number type, you can explicitly convert the values to numbers in HTL. You can use the Number object in HTL for this purpose.
Here’s an example:
<!-- Assuming data.value is an integer stored as a string -->
<!-- Correct way to ensure both are numbers -->
${Number @val = data.value} <!-- Convert data.value to a number -->
${Number @val = 10} <!-- Example comparison value -->
${data.value <= 10} <!-- Perform the comparison -->
If the value transformation is more complex, consider using the JavaScript Use-API to prepare the values before rendering them in HTL.
Here’s an example JavaScript Use-API:
/apps/myproject/components/content/mycomponent/mycomponent.js
use(function () {
var dataValue = parseInt(this.data.value, 10);
return {
dataValue: dataValue
};
});
In your HTL script:
<!-- Use the converted number from the JS Use-API -->
${model.dataValue <= 10}
To help with debugging, you can print the types of the variables being compared:
${data.value} (${data.value.class}) <!-- This will print the value and its type -->
Ensure the data you’re comparing is consistent. For instance, if data.value sometimes comes as a string and other times as a number, it can lead to such issues.
Assuming you have a property data.value which might be a string or number, you should ensure it's consistently treated as a number:
<!-- Correct way to compare a string number and an integer -->
${Number @val=data.value} <= 10
Applying these steps should help resolve the type mismatch issue in AEM 6.5
Views
Replies
Total Likes
Hi @HrishikeshKa
Thank you for your reply.
The comparison logic is already written with >0. It's working on 6.4 and not on 6.5 servers.
can you post a minimal HTL scriptlet with hardcoded values, which demonstrates this behavior?
Hi @chinmayis865517 , similar kind of issue addressed here
if this is not helpful can you please share complete error log and the sling model you are trying to inject the object.
Hi @chinmayis865517
Please check the operands value, try to print in HTL, seems like the operand values are null.
@chinmayis865517 Did you find the suggestions from users helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies