-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
About java.lang.String#format(java.lang.String,java.lang.Object[])
#119
Comments
Hi, At the moment, I am not sure how the best way is to make this smarter. Currently you can use As forbiddenapis is only a static checker, there is no way to check for string contents (this is more something for tools like PMD). So I don't think that automatic exclusion here is fine. Especially, as One possibility would be some "exclusion" pattern (something like a negative signatures file) so you can slecetively revert patterns. For now, your only chance is to fork the signatures file into your project. BTW: You can also publish it on Maven Central or your local Artifactory repo and refer to it from your project's plugin and reuse it somewhere else! |
|
@trejkaz interesting :). That'd be an argument for adding @uschindler apologies for not responding to your comment (also very busy here ;) ). I think adding support for exclusions would be a nice to have. When I get back to reviewing this plugin (could be weeks/months) I might look into contributing such support. Indeed, until that time I could fork the signatures file. |
That is one problem that impossible to solve (very similar to the formatter problem). You cannot do that with static code analysis, because the runtime type is unknown at compile time (in most cases). In Lucene we had the same problem: As we wanted to use BCP47 language tags everywhere we tried to forbid So I have no idea how to fix the underlying issue. An "exclusion" is just a workaround! |
All those methods on invokedynamic adds a bunch of extra fun for APIs all over the place too. Now you pretty much have to ban methods just by name, right? :) |
See also #123 for an explanation why that's not possible to detect with a static byte code analysis tool. So I will close this as wont fix. |
Having evaluated this plugin against our code base, I can say this is a job very well done. Kudos!
One issue I hit while using the bundled
jdk-unsafe
signatures is this violation:Indeed, this method can produce locale-dependent results. But in our code base I found over 400 calls to this method where the format pattern only contains
%s
format specifiers. As best as I can tell we never pass in objects which implementjava.util.Formattable
. So the results should be locale-independent; to vacuously addLocale.ROOT
in hundreds of places seems overkill.I guess making the plugin smart enough to detect this kind of safe method usage is out of scope. So my question is whether there is some way to exclude just this signature. If at all possible I'd like to avoid having to maintain a modified copy of the
jdk-unsafe
signature list.The text was updated successfully, but these errors were encountered: