Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Quickfix NullPointerException in PartialSerializer
Quickfix NullPointerException in PartialSerializer [message #1779172] Wed, 03 January 2018 13:51 Go to next message
Sergio Otero is currently offline Sergio OteroFriend
Messages: 31
Registered: June 2012

I'm having problems in Xtext 2.13 with quickfixes that i didn't have in 2.12, i suppose related to the changes applied to support multiple quickfix resolutions.

The problem appears when a node A is added to the AST tree and then another node is added as a child of A

	at org.eclipse.xtext.ide.serializer.impl.PartialSerializer$SerializeRecursiveStrategy.serialize(
	at org.eclipse.xtext.ide.serializer.impl.PartialSerializer.serializeChanges(
	at org.eclipse.xtext.ide.serializer.impl.RecordingXtextResourceUpdater.applyChange(
	at org.eclipse.xtext.ide.serializer.impl.ChangeSerializer.endRecordChanges(
	at org.eclipse.xtext.ide.serializer.impl.ChangeSerializer.applyModifications(
	at org.eclipse.xtext.ui.editor.model.edit.BatchModification.applyInWorkspace(

The problem happens with a single quickfix, but it can be avoided somehow waiting to add the node A until it's fully set.
The problem is much more difficult to solve if several quickfixes are applied together and the business rules are complex

As an example, i've made a simple test case

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl ""

	classes+=Class* statements+=Statement+;
	'class' name=ID '{' vars+=Variable+ '}';
Variable: name=ID;
Statement: var=[Variable|VariableQN] '=' INT;	

VariableQN hidden(): ID '.' ID;

	def void fixMissingEntity(Issue issue, IssueResolutionAcceptor acceptor) {
		if (issue.message.contains("Variable")) {
			fixMissingVariable(issue, acceptor);

	private def fixMissingVariable(Issue issue, IssueResolutionAcceptor acceptor) {
			"Create missing variable definition",
			"Create missing variable definition",
			[ Statement element, ICompositeModificationContext<Statement> context |
				val fullReferenceName = getIssueMissingReferenceName(context.issue)
				val nameArray = fullReferenceName.split("\\.")
				val className = nameArray.get(0)
				val fieldName = nameArray.get(1)
				val root = element.eContainer as Model
				context.addModification(root, [ctx |
					var cl = root.classes.findFirst[ == className]
					if (cl === null) {
						// The class didn't exist
						cl =  MyDslFactory::eINSTANCE.createClass() => [
							name = className
						// before adding the class, we can add the field
						addVariable(cl, fieldName)

						// after adding the class, adding the field will cause NullPointerException in Serialization
						// addVariable(cl, fieldName)
					} else {
						// The class existed (maybe created in a previous multiquickfix)
						// NullPointerException if 2 fixs are applied together and the parent class was added in the first fix
						addVariable(cl, fieldName)
	protected def boolean addVariable(Class cl, String fieldName) {
		val atr = MyDslFactory::eINSTANCE.createVariable() => [
			name = fieldName
	private def String getIssueMissingReferenceName(Issue issue) {
		// Not the best way ...
		val issueMessage = issue.message
		val j = issueMessage.lastIndexOf("'")
		val i = issueMessage.lastIndexOf("'", j - 1)
		issueMessage.substring(i+1, j)

Example code:

// aplying the fix to this 2 problems together works because they create their own classes
Class1.test1 = 1 
Class2.test2 = 1

// aplying the fix to this 2 problems together don't work because the first adds the class plus field and the second adds another field to the new class
Class3.test3 = 1 
Class3.test4 = 1
Re: Quickfix NullPointerException in PartialSerializer [message #1779192 is a reply to message #1779172] Wed, 03 January 2018 17:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11819
Registered: July 2009
Senior Member
did you opt in to used the new serializer? seems so since you use the multi quickfix.
can you please create a issue at

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Re: Quickfix NullPointerException in PartialSerializer [message #1779226 is a reply to message #1779192] Thu, 04 January 2018 08:06 Go to previous message
Sergio Otero is currently offline Sergio OteroFriend
Messages: 31
Registered: June 2012

I have a grammar used with legacy code and clients always send code with missing parts, so it's very useful to be able to apply massive quickfixes.
I kind of implemented a menu option to apply single quickfixes one after another project-wide (only aplied to a few specific custom quickfixes) and it worked pretty well in 2.12
After changing to 2.13, the output of the multiple single-quickfixes was corrupted, so i changed it to multiquickfixes and then i faced with the nullPointers

As a side question, if a quickfix has to modify a referenced resource (for example, add a field to a class in other source file), can it be done as if it were in the same source file or it needs additional steps?

Previous Topic:TypeReference for nested annotations class
Next Topic:How to parse a normal text file for unit test
Goto Forum:

Current Time: Wed Mar 21 03:23:23 GMT 2018

Powered by FUDForum. Page generated in 0.01502 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software