kamaci kamaci - 1 year ago 108
Java Question

Using toUpperCase with Correct Locale

I'm trying to fix errors which are reported by forbiddenapis. I had that line:

paramMap.put(Config.TITLEBOOST.toUpperCase(), titleBoost);

So, its been reported as error as usual. I've tried that:

paramMap.put(Config.TITLEBOOST.toUpperCase(Locale.getDefault()), titleBoost);

and that:

paramMap.put(Config.TITLEBOOST.toUpperCase(Locale.ROOT), titleBoost);

also that:

paramMap.put(Config.TITLEBOOST.toUpperCase(Locale.ENGLISH), titleBoost);

However none of them fixed the error:

[forbiddenapis] Forbidden method invocation:
java.lang.String#toUpperCase() [Uses default locale]

What I miss?

cxw cxw
Answer Source

Double-check that the bytecode you are analyzing is actually your most recent build output, and that you're looking at the same line forbiddenapis is :) . This looks to me like your source/bytecode/analysis are falling out of sync — the relevant rule shouldn't flag an error on String.toUpperCase(Locale).

Disclaimer: I haven't used forbiddenapis myself --- I wrote this answer based on the repo and on a blog post I found.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download