Compiler crash (& first draft of a Regex patch)

Brian Goetz brian.goetz at oracle.com
Thu Feb 14 08:56:01 PST 2013


On our list to fix :)  It happens when you try and capture local 
classes.  The workaround is to refactor the local class to a private 
class outside the method.

On 2/14/2013 11:29 AM, Ben Evans wrote:
> Hi,
>
> This block of code, when added to java.util.regex.Pattern, causes an
> NPE in the compiler:
>
>      public Predicate<String> asPredicate(){
>          return s -> this.matcher(s).find();
>      }
>
>      public <T extends CharSequence> Stream<CharSequence>
> splitAsStream(T input) {
> 		class CharSeqIterator implements Iterator<CharSequence> {
> 			int cur = 0; // Position in the input string
> 			Matcher curMatcher = null;
>
> 	        public boolean hasNext() {
> 				// true iff we match on the remaining substring
> 				if (curMatcher == null)
> 					curMatcher = Pattern.this.matcher(input.subSequence(cur, input.length()));
> 				return curMatcher.find();
> 	        }
>
> 	        public CharSequence next() {
> 	            if (hasNext()) {
> 					CharSequence tmpCs = input.subSequence(cur, curMatcher.start() - 1);
> 					cur = curMatcher.end();
> 					curMatcher = null;
> 	                return tmpCs;
> 				} else {
> 	                throw new NoSuchElementException();		
> 				}
> 	        }
>
> 	        public void forEach(java.util.function.Block<? super
> CharSequence> block) {
> 				while (cur < input.length()) {
> 	                block.accept(next());
> 	            }
> 	        }
> 		}
> 	
> 		return Streams.stream(() -> Streams.spliteratorUnknownSize(new
> CharSeqIterator()), StreamOpFlag.IS_ORDERED);
>      }
>
> An exception has occurred in the compiler (1.8.0-internal). Please
> file a bug at the Java Developer Connection
> (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade
> for duplicates. Include your program and the following diagnostic in
> your report.  Thank you.
> java.lang.NullPointerException
> 	at com.sun.tools.javac.jvm.Code.emitop0(Code.java:540)
> 	at com.sun.tools.javac.jvm.Items$LocalItem.load(Items.java:397)
> 	at com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:911)
> 	at com.sun.tools.javac.jvm.Gen.visitNewClass(Gen.java:1788)
> 	at com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1462)
> 	at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:892)
> 	at com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:911)
> 	at com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1745)
> 	at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1410)
> 	at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:892)
> 	at com.sun.tools.javac.jvm.Gen.visitReturn(Gen.java:1714)
> 	at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1328)
> 	at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:682)
> 	at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:717)
> 	at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:703)
> 	at com.sun.tools.javac.jvm.Gen.genStats(Gen.java:754)
> 	at com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1089)
> 	at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:852)
> 	at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:682)
> 	at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:717)
> 	at com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:967)
> 	at com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:940)
> 	at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:736)
> 	at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:682)
> 	at com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2309)
> 	at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:752)
> 	at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1522)
> 	at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1486)
> 	at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:908)
> 	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:867)
> 	at com.sun.tools.javac.main.Main.compile(Main.java:482)
> 	at com.sun.tools.javac.main.Main.compile(Main.java:363)
> 	at com.sun.tools.javac.main.Main.compile(Main.java:352)
> 	at com.sun.tools.javac.main.Main.compile(Main.java:343)
> 	at com.sun.tools.javac.Main.compile(Main.java:76)
> 	at com.sun.tools.javac.Main.main(Main.java:61)
>
> Comments on the approach I'm taking in the patch also very welcome. I
> haven't actually got this to build successfully yet, so haven't been
> able to test it.
>
> Thanks,
>
> Ben
>


More information about the lambda-dev mailing list