Total Pageviews

2017/11/11

[Fortify] Fix Locale Dependent Comparison

Problem


Before
The original code snippet is the following:
1
2
3
    if (value.toUpperCase().equals("TRUE")) {
        return true;
    }


After
Add dependency in your pom.xml
1
2
3
4
5
6
    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.0</version>
    </dependency>


The updated code snippet are as bellows:
1
2
3
4
    String valueUpperCase = StringUtils.upperCase(value, Locale.ENGLISH);
    if(valueUpperCase.equals("TRUE")) {
        return true;
    }



No comments: