OverZealous 的解决方案因 NPE 而失败。
Exception in thread "Basic L&F File Loading Thread" java.lang.NullPointerException
at java.util.regex.Matcher.getTextLength(Unknown Source)
at java.util.regex.Matcher.reset(Unknown Source)
at java.util.regex.Matcher.<init>(Unknown Source)
at java.util.regex.Pattern.matcher(Unknown Source)
at org.codehaus.groovy.runtime.InvokerHelper.matchRegex(InvokerHelper.java:335)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.matchRegex(ScriptBytecodeAdapter.java:722)
at ExcelChooser2$_run_closure2.doCall(ExcelChooser2.groovy:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at FileFilter_groovyProxy.accept(Script1.groovy:7)
at javax.swing.JFileChooser.accept(Unknown Source)
at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run0(Unknown Source)
at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run(Unknown Source)
解决方案:
老的:fileFilter: [getDescription: {-> "*.xls"}, accept:{file -> file ==~ /.*?\.xls/ || file.isDirectory() }] as FileFilter
新的:fileFilter: [getDescription: {-> "*.xls"}, accept:{file -> file.toString() ==~ /.*?\.xls/ || file.isDirectory() }] as FileFilter
[ Win7(x64)Groovy 版本:1.8.3 JVM:1.6.0_29)]