你好,对于org.apache.flink.table.types.extraction.ExtractionUtils的getClassReader方法我有个疑问,为何在打开inputStream后没有进行及时关闭?
源码如下:
    private static ClassReader getClassReader(Class<?> cls) {
        final String className = cls.getName().replaceFirst("^.*\\.", "") + 
".class";
        try {
            return new ClassReader(cls.getResourceAsStream(className));
        } catch (IOException e) {
            throw new IllegalStateException("Could not instantiate 
ClassReader.", e);
        }
    }
这里ClassReader在读取inputStream时是不会对外部inputStream进行关闭处理的,可能会引起文件句柄泄露的问题。我在使用flink测试大量sql代码解析的时候也就遇到了open
 too many files异常,所以是否可以考虑更改为try-with-resource方式,将inputStream在使用后及时关闭,如下


private static ClassReader getClassReader(Class<?> cls) {
final String className = cls.getName().replaceFirst("^.*\\.", "") + ".class";
try(InputStream inputStream = cls.getResourceAsStream(className)) {
return new ClassReader(inputStream);
} catch (IOException e) {
throw new IllegalStateException("Could not instantiate ClassReader.", e);
}
}





回复