A Simple Shell Script to Check the Trap of Case-Insensitive String

In the post of "The Trap of Case-Insensitive String", it is talked about the locale sensitive of String.toUpperCase() or String.toLowerCase(). I wrote a very simple KSH script to check the potential problems in Java source code. The script may be useful to facilitate the checking of the trap.


typeset -i keywords_number=1

# KEYWORDS[0]="toLowerCase\(\).hashCode\(\)"
# KEYWORDS[1]="toUpperCase\(\).hashCode\(\)"
# KEYWORDS[2]="toLowerCase\(\).equals\("
# KEYWORDS[3]="toUpperCase\(\).equals\("
# typeset -i keywords_number=4

EXCLUDE_LINES="\/\/| \* "   # inaccurate filter

typeset -i keywords_i=0
while [ ${keywords_i} -lt ${keywords_number} ]; do
    echo Running "Checking operatoin ${KEYWORDS[${keywords_i}]} ..."

    find ./ -name "*.java" |xargs egrep "${KEYWORDS[${keywords_i}]}" \
        |egrep -v "${EXCLUDE_LINES}"

    echo "    ... DONE with the checking of ${KEYWORDS[${keywords_i}]}"


Please check the output to make sure there is no potential issues with String.toUpperCase() or String.toLowerCase().

Enjoy it!

Popular posts from this blog

Java™ SE 7 Release Security Enhancements - Weak Cryptography Control

TLS Server Name Indication Extension and Unrecognized_name

Browser Opera Preference of TLS Cipher Suites