Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 357230 - NPE in Xtend2Compiler
Summary: NPE in Xtend2Compiler
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: SR2   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-09 09:17 EDT by Andreas Muelder CLA
Modified: 2017-09-19 17:56 EDT (History)
3 users (show)

See Also:
sven.efftinge: indigo+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Muelder CLA 2011-09-09 09:17:14 EDT
Build Identifier: 20110615-0604

If a dispatch function name starts with an underscore, the Xtend2Compiler throws an NPE and does not generate java classes. 

class Example {
  def dispatch _test(Object e) {}
  def dispatch _test(String f){}
}

java.lang.NullPointerException
	at org.eclipse.xtext.xtend2.compiler.Xtend2Compiler.generateDispatchMethod(Xtend2Compiler.java:200)
	at org.eclipse.xtext.xtend2.compiler.Xtend2Compiler.generateDispatchMethods(Xtend2Compiler.java:193)
	at org.eclipse.xtext.xtend2.compiler.Xtend2Compiler.compile(Xtend2Compiler.java:166)
	at org.eclipse.xtext.xtend2.compiler.Xtend2Compiler.compile(Xtend2Compiler.java:114)
	at org.eclipse.xtext.xtend2.ui.builder.Xtend2BuilderParticipant.compile(Xtend2BuilderParticipant.java:146)
	at org.eclipse.xtext.xtend2.ui.builder.Xtend2BuilderParticipant.processDelta(Xtend2BuilderParticipant.java:115)
	at org.eclipse.xtext.xtend2.ui.builder.Xtend2BuilderParticipant.build(Xtend2BuilderParticipant.java:75)
	at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:60)
	at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:160)
	at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:141)
	at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:91)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)




Reproducible: Always
Comment 1 Andreas Muelder CLA 2011-09-12 05:15:37 EDT
This does not only happen for dispatch functions.
I think it also breaks the operator overloading feature of xtend.
Comment 2 Jan Koehnlein CLA 2011-09-12 11:26:31 EDT
We should not allow such function names, as the "_" namespace should be preserved for generated Xtend stuff.
Comment 3 Sebastian Zarnekow CLA 2011-09-12 11:30:19 EDT
(In reply to comment #1)
> This does not only happen for dispatch functions.
> I think it also breaks the operator overloading feature of xtend.

Andreas, could you please elaborate on this comment? What does break the operator overloading and how does that happen?(In reply to comment #2)

> We should not allow such function names, as the "_" namespace should be
> preserved for generated Xtend stuff.

This arises the question on how we want to implement e.g. the LabelProvider with Xtend which dispatches by means of a polymorphic dispatcher in its super type?
Comment 4 Andreas Muelder CLA 2011-09-12 11:48:40 EDT
Sebastian,

maybe I am wrong but refering to the eclipse help, the method signature to overload an operator starts with an underscore, i.E:

e1 += e2 e1._operator_add(e2) 

Defining such a method in xtend leads to the same NullPointerException.
Comment 5 Sebastian Zarnekow CLA 2011-09-12 11:57:44 EDT
(In reply to comment #4)
> Sebastian,
> 
> maybe I am wrong but refering to the eclipse help, the method signature to
> overload an operator starts with an underscore, i.E:

It's actually the documentation which is wrong. The method signature has to be 

#operator_add or #operator_plus.

See org.eclipse.xtext.xbase.scoping.featurecalls.OperatorMapping.OP_PREFIX

Thanks for the hint.
Comment 6 Sven Efftinge CLA 2011-09-19 06:29:52 EDT
I've added a validation for dispatch functions not allowing names starting with an underscore.
Also made sure that non-dispatch method names can start with an underscore.
Comment 7 Karsten Thoms CLA 2017-09-19 17:45:26 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 8 Karsten Thoms CLA 2017-09-19 17:56:28 EDT
Closing all bugs that were set to RESOLVED before Neon.0