Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 334863

Summary: NPE in JdtBasedTypeFactory
Product: [Modeling] TMF Reporter: Nicolas Cabanis <dev>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow
Version: 1.0.1Flags: sebastian.zarnekow: helios+
sebastian.zarnekow: indigo+
Target Milestone: M5   
Hardware: All   
OS: All   
Whiteboard:

Description Nicolas Cabanis CLA 2011-01-20 04:03:39 EST
A NPE raises while creating types. There seems to be a problem with the annotation processing. The member value is null, even though a default is specified. It works with annotations from the javax.annotation package but not with own annotations (maybe a difference between compiled and source?).

The NPE raises as it is assumed that the value is never null.


java.lang.NullPointerException
	at org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.createAnnotationValue(JdtBasedTypeFactory.java:239)
	at org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.createAnnotationReference(JdtBasedTypeFactory.java:154)
	at org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.createAnnotationValues(JdtBasedTypeFactory.java:136)
	at org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.createOperation(JdtBasedTypeFactory.java:529)
	at org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.createMethods(JdtBasedTypeFactory.java:314)
	at org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.createType(JdtBasedTypeFactory.java:111)
	at org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.createType(JdtBasedTypeFactory.java:90)
	at org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.createType(JdtBasedTypeFactory.java:1)
	at org.eclipse.xtext.common.types.access.jdt.JdtTypeMirror.initialize(JdtTypeMirror.java:41)
	at org.eclipse.xtext.common.types.access.TypeResource.doLoad(TypeResource.java:86)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1494)
	at org.eclipse.xtext.common.types.access.TypeResource.load(TypeResource.java:74)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:255)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:270)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
	at org.eclipse.xtext.common.types.access.jdt.JdtTypeProvider.findTypeByName(JdtTypeProvider.java:62)
	at org.eclipse.xtext.common.types.xtext.AbstractTypeScope.getContentByName(AbstractTypeScope.java:42)
Comment 1 Sebastian Zarnekow CLA 2011-01-20 04:23:09 EST
Please provide the source for the class and and the annotations that are present on the class. Do you try to create the JvmType for the compiled class or for the source class? Does the error occur in the runtime mode, too?
Comment 2 Nicolas Cabanis CLA 2011-01-20 04:34:02 EST
This works for me. Now the type can be created (the annotations are not relevant).

if (value == null) {
	return result;
}


The default values do not work for the annotations from the own source code.

---
package com.xxx.annotations
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Im Gegensatz zu der @Generated aus der JDK kann diese Annotation auch zur Laufzeit ausgewertet werden.
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Generated
{
   /** Der Name der Resource, aus der diese Datei generiert wurde. */
   String source() default "";
}

---

@javax.annotation.Generated("something")
@com.xxx.annotations.Generated
public interface YY {}

---

The javax.annotation.Generated has 'String comments() default "";' which works. The com.xxx.annotations.Generated has 'String source() default "";' which does not work.
Comment 3 Sebastian Zarnekow CLA 2011-01-20 15:20:28 EST
Pushed fix to master.
Comment 4 Sebastian Zarnekow CLA 2011-01-20 19:16:20 EST
This one will tackle to causer for the NPE:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=334943
Comment 5 Sebastian Zarnekow CLA 2011-01-20 19:17:09 EST
As stated in comment #3, a workaround was pushed to master.
Comment 6 Sebastian Zarnekow CLA 2011-02-09 04:46:03 EST
Pushed to Helios maintenance.
Comment 7 Karsten Thoms CLA 2017-09-19 16:52:19 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 8 Karsten Thoms CLA 2017-09-19 17:03:31 EDT
Closing all bugs that were set to RESOLVED before Neon.0