Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

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)

Avatar

Level 4

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

6 Replies

Avatar

Level 9

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:

1. Check Your HTL Script

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.

2. Use Number Conversion Functions

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 -->

 

3. JavaScript Use-API

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}

 

4. Debugging

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 -->

 

5. Double-Check Data Sources

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.

Example Scenario:

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

 

 

  1. Ensure both operands in comparisons are of the same type.
  2. Explicitly convert values to numbers using Number.
  3. Use JavaScript Use-API for complex transformations.
  4. Debug by printing variable types.
  5. Ensure data consistency from the source.

Applying these steps should help resolve the type mismatch issue in AEM 6.5

Avatar

Level 4

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.

Avatar

Employee Advisor

can you post a minimal HTL scriptlet with hardcoded values, which demonstrates this behavior?

Avatar

Level 9

Hi @chinmayis865517 , similar kind of issue addressed here

 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/operands-are-not-of-the-sa...

 

if this is not helpful can you please share complete error log and the sling model you are trying to inject the object.

Avatar

Community Advisor

Hi @chinmayis865517 
Please check the operands value, try to print in HTL, seems like the operand values are null.



Arun Patidar

Avatar

Administrator

@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.



Kautuk Sahni