uschindler commented on pull request #567: URL: https://github.com/apache/lucene/pull/567#issuecomment-1003134186
> Browsing through this issue, I am wondering if it'd be helpful that we have entries to forbid ~Class#getClassLoader()~ ClassLoadr#getResourceAsStream() (and so on) by default. When it is really needed (for example, on tests), we can suppress the linter by `@SuppressForbidden`. > > Correction: not all methods in ClassLoader are caller sensitive (returns null when the package is not opened). getClassLoader() call itself may not be a problem. > > ``` > lucene $ git diff > diff --git a/gradle/validation/forbidden-apis/defaults.all.txt b/gradle/validation/forbidden-apis/defaults.all.txt > index 6c6e0296cc5..62b1e8fa6e8 100644 > --- a/gradle/validation/forbidden-apis/defaults.all.txt > +++ b/gradle/validation/forbidden-apis/defaults.all.txt > @@ -66,3 +66,6 @@ java.io.ObjectOutputStream > @defaultMessage Don't set a dictionary on a Deflater using a method that takes an offset or ByteBuffer (JDK-8252739) > java.util.zip.Deflater#setDictionary(byte[],int,int) > java.util.zip.Deflater#setDictionary(java.nio.ByteBuffer) > + > +@defaultMessage caller sensitive method callq > +java.lang.ClassLoader#getResourceAsStream(java.lang.String) > ``` > > ``` > # on main branch > lucene $ ./gradlew -p lucene/analysis/kuromoji/ forbiddenApi > > Task :lucene:analysis:kuromoji:forbiddenApisMain FAILED > Forbidden method invocation: java.lang.ClassLoader#getResourceAsStream(java.lang.String) [caller sensitive method callq] > in org.apache.lucene.analysis.ja.dict.BinaryDictionary (BinaryDictionary.java:207) > ``` The Classloader one should be forbidden, but `Class#getResourceAsStream()` should always be preferred, but we should make sure that we do not use it in public utility methods that can be called from foreign code. The code in dictionary loading should be fixed and we should completely get rid of those setting/enum classpath/file loading. Just add a method/ctor that takes an InputStream and done. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
