I have a code fragment like the following:
List<EmailTemplate> langTemplates = emailTemplateMap.get(categoryId+"_"+languageId);
while (langTemplates.isEmpty() && altLanguageId <= Language.ALL.length)
{
langTemplates = emailTemplateMap.get(categoryId+"_"+altLanguageId);
altLanguageId++;
}
which doesn't work as expected. I found (decompiling the .class file), that the compiler obviously changed this to something like:
List langTemplates;
for(langTemplates = (List)emailTemplateMap.get((new StringBuilder(String.valueOf(categoryId))).append("_").append(languageId).toString()); langTemplates.isEmpty() && altLanguageId <= Language.ALL.length; altLanguageId++)
{
langTemplates = (List)emailTemplateMap.get((new StringBuilder(String.valueOf(categoryId))).append("_").append(altLanguageId).toString());
}
which is not the same. It just replaced my running escape variable (luckily I got a second one, otherwise this would become an endless loop!) with what it was defined as before the loop and thus checks always the same value and doesn't take into account the updates/re-reference to the local variable inside the loop.
Does this make any sense? Or can this be considered a bug in the compiler? If not, is my original code wrong?
Thanks for any insight.
Marc