Skip to content
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

ArrayIndexOutOfBoundsException - Type Inference #826

Closed
shawnweeks opened this issue Feb 26, 2019 · 8 comments
Closed

ArrayIndexOutOfBoundsException - Type Inference #826

shawnweeks opened this issue Feb 26, 2019 · 8 comments
Assignees
Labels
Milestone

Comments

@shawnweeks
Copy link

shawnweeks commented Feb 26, 2019

This looks similar to #808 but when trying to auto complete org.apache.avro.SchemaBuilder you get the following exception. I'm running Eclipse 4.10 latest and Eclipse Groovy Development Tools 3.3.0.xx-201902260000-e48. You can take a look at the groovy script at shawnweeks/nifi-groovy-testing on github.

java.lang.RuntimeException: Failed to initialize members for type org.apache.avro.SchemaBuilder
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNode.initializeMembers(JDTClassNode.java:306)
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNode.initialize(JDTClassNode.java:202)
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNode.lazyClassInit(JDTClassNode.java:169)
	at org.codehaus.groovy.ast.ClassNode.getAnnotations(ClassNode.java:1607)
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNode.getAnnotations(JDTClassNode.java:501)
	at org.codehaus.groovy.transform.trait.Traits.isAnnotatedWithTrait(Traits.java:177)
	at org.codehaus.groovy.transform.trait.Traits.isTrait(Traits.java:158)
	at org.eclipse.jdt.groovy.core.util.GroovyUtils.lambda$6(GroovyUtils.java:467)
	at java.util.Map.computeIfAbsent(Unknown Source)
	at org.codehaus.groovy.ast.ASTNode.getNodeMetaData(ASTNode.java:157)
	at org.eclipse.jdt.groovy.core.util.GroovyUtils.implementsTrait(GroovyUtils.java:464)
	at org.eclipse.jdt.groovy.search.SimpleTypeLookup.findMethodDeclaration(SimpleTypeLookup.java:664)
	at org.eclipse.jdt.groovy.search.SimpleTypeLookup.findDeclaration(SimpleTypeLookup.java:590)
	at org.eclipse.jdt.groovy.search.SimpleTypeLookup.findTypeForNameWithKnownObjectExpression(SimpleTypeLookup.java:363)
	at org.eclipse.jdt.groovy.search.SimpleTypeLookup.findTypeForNameWithKnownObjectExpression(SimpleTypeLookup.java:443)
	at org.eclipse.jdt.groovy.search.SimpleTypeLookup.findType(SimpleTypeLookup.java:222)
	at org.eclipse.jdt.groovy.search.SimpleTypeLookup.lookupType(SimpleTypeLookup.java:85)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.lookupExpressionType(TypeInferencingVisitorWithRequestor.java:2353)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.handleSimpleExpression(TypeInferencingVisitorWithRequestor.java:1801)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitConstantExpression(TypeInferencingVisitorWithRequestor.java:956)
	at org.codehaus.groovy.ast.expr.ConstantExpression.visit(ConstantExpression.java:85)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitMethodCallExpression(TypeInferencingVisitorWithRequestor.java:1373)
	at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:70)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitMethodCallExpression(TypeInferencingVisitorWithRequestor.java:1357)
	at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:70)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitMethodCallExpression(TypeInferencingVisitorWithRequestor.java:1357)
	at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:70)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitMethodCallExpression(TypeInferencingVisitorWithRequestor.java:1357)
	at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:70)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitMethodCallExpression(TypeInferencingVisitorWithRequestor.java:1357)
	at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:70)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitMethodCallExpression(TypeInferencingVisitorWithRequestor.java:1357)
	at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:70)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitMethodCallExpression(TypeInferencingVisitorWithRequestor.java:1357)
	at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:70)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitBinaryExpression(TypeInferencingVisitorWithRequestor.java:745)
	at org.codehaus.groovy.ast.CodeVisitorSupport.visitDeclarationExpression(CodeVisitorSupport.java:298)
	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitDeclarationExpression(ClassCodeVisitorSupport.java:150)
	at org.codehaus.groovy.ast.expr.DeclarationExpression.visit(DeclarationExpression.java:89)
	at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:122)
	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:263)
	at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42)
	at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:88)
	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:233)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitBlockStatement(TypeInferencingVisitorWithRequestor.java:820)
	at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:71)
	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:145)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitConstructorOrMethod(TypeInferencingVisitorWithRequestor.java:1051)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitMethodInternal(TypeInferencingVisitorWithRequestor.java:616)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitJDT(TypeInferencingVisitorWithRequestor.java:454)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitJDT(TypeInferencingVisitorWithRequestor.java:345)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitCompilationUnit(TypeInferencingVisitorWithRequestor.java:251)
	at org.codehaus.groovy.eclipse.codebrowsing.requestor.CodeSelectHelper.selectASTNode(CodeSelectHelper.java:127)
	at org.codehaus.groovy.eclipse.search.GroovyOccurrencesFinder.initialize(GroovyOccurrencesFinder.java:167)
	at org.codehaus.groovy.eclipse.search.GroovyOccurrencesFinder.findOccurrences(GroovyOccurrencesFinder.java:196)
	at org.codehaus.groovy.eclipse.editor.GroovyEditor.updateOccurrenceAnnotations(GroovyEditor.java:1309)
	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor$6.selectionChanged(JavaEditor.java:3392)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:182)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$3.run(SelectionListenerWithASTManager.java:158)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.IllegalStateException: Failed to resolve method node for org.apache.avro.SchemaBuilder.array
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNode.methodBindingToMethodNode(JDTClassNode.java:337)
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNode.initializeMembers(JDTClassNode.java:247)
	... 59 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 281
	at org.eclipse.jdt.internal.compiler.lookup.TypeSystem.getUnannotatedType(TypeSystem.java:227)
	at org.eclipse.jdt.internal.compiler.lookup.TypeSystem.getRawType(TypeSystem.java:346)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createRawType(LookupEnvironment.java:1411)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.convertToRawType(LookupEnvironment.java:888)
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNodeBuilder.toRawType(JDTClassNodeBuilder.java:351)
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNodeBuilder.configureParameterizedType(JDTClassNodeBuilder.java:227)
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNodeBuilder.configureType(JDTClassNodeBuilder.java:85)
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTResolver.createJDTClassNode(JDTResolver.java:488)
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTResolver.convertToClassNode(JDTResolver.java:457)
	at org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNode.methodBindingToMethodNode(JDTClassNode.java:317)
@eric-milles
Copy link
Member

Do you have any stack frames for the ArrayIndexOutOfBoundsException? Where were you engaging content assist?

@shawnweeks
Copy link
Author

This happens if I just type the name of the class and then a period. Once it starts, autocomplete starts breaking for everything in the script. I'm just seeing the error in the workspace log so I'm not sure how to get a stack frame.

@eric-milles
Copy link
Member

Okay, can you exit your eclipse, open eclipse.ini and add "-XX:-OmitStackTraceInFastThrow" as the last line? This will disable "fast throw" mode which can leave off stack trace information for common exceptions.

Are you typing "SchemaBuilder." and then content assist opens?

@shawnweeks
Copy link
Author

shawnweeks commented Feb 26, 2019

Yes I'm typing "SchemaBuilder." and then content assist opens.

@eric-milles
Copy link
Member

So the LookupEnvironment/TypeSystem is being reset. And so the types array is reduced in length back to 256 each time. The return type of SchemaBuilder.array() is given the type id 281 and so that is OOB for a length 256 array.

I'm investigating if the reset is by design or if the source of the issue is performing this reset with active type bindings out there.

@eric-milles
Copy link
Member

eric-milles commented Feb 26, 2019

Your groovy script is located within src/test/resources, so the Maven configurator did not get triggered to add the Groovy nature to your project. Then when you open a groovy source in the groovy editor, it runs through this code in CompilationUnitProblemFinder:

		// GROOVY add
		boolean reset = true;
		// GROOVY end
		try {
			environment = new CancelableNameEnvironment(project, workingCopyOwner, monitor, !isTestSource(unitElement.getJavaProject(), unitElement));
			problemFactory = new CancelableProblemFactory(monitor);
			CompilerOptions compilerOptions = getCompilerOptions(project.getOptions(true), creatingAST, ((reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0));
			boolean ignoreMethodBodies = (reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
			compilerOptions.ignoreMethodBodies = ignoreMethodBodies;
			// GROOVY add
			// options fetched prior to building problem finder then configured based on project
			CompilerUtils.configureOptionsBasedOnNature(compilerOptions, project);
			if (!creatingAST) {
				compilerOptions.groovyCompilerConfigScript = null;
			}
			if (compilerOptions.buildGroovyFiles == 2) {
				reset = false;
			}
			// GROOVY end
			...
		} finally {
			...
			// GROOVY edit -- reset() can cause OOB exceptions in TypeSystem
			//if (problemFinder != null && !creatingAST)
			if (problemFinder != null && !creatingAST && reset)
			// GROOVY end
				problemFinder.lookupEnvironment.reset();
		}

The reset flag is set to false when buildGroovyFiles is "yes". In your project, it is "no" and so the lookup environment and type system are reset.

You can right-click on your project and select Configure > Convert to Groovy Project to add the nature and stop the OOB exceptions. I am working on a better overall solution, but you can stop the exceptions immediately with the workaround.

@eric-milles
Copy link
Member

Ready to test

@shawnweeks
Copy link
Author

Installed the latest snapshot and the errors are gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants