Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 335149 - NPE from unitialised IResourceServiceProvider.Registry
Summary: NPE from unitialised IResourceServiceProvider.Registry
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.0   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: M5   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-24 01:47 EST by Ed Willink CLA
Modified: 2017-09-19 17:59 EDT (History)
1 user (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 Ed Willink CLA 2011-01-24 01:47:59 EST
I am seeing the following NPE in Xtext 2.0M4 and a half.

NamesAreUniqueValidator.doCheckUniqueNames(Resource, CancelIndicator) line: 66	
NamesAreUniqueValidator.checkUniqueNamesInResourceOf(EObject) line: 62	
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25	
Method.invoke(Object, Object...) line: 592	
AbstractDeclarativeValidator$MethodWrapper.invoke(AbstractDeclarativeValidator$State) line: 111	
OCLinEcoreJavaValidator(AbstractDeclarativeValidator).internalValidate(EClass, EObject, DiagnosticChain, Map<Object,Object>) line: 297	

because resourceServiceProviderRegistry is null.

It would appear that

a) there is no underlying deefault for the injection mechanism

b) there is a missing null test
Comment 1 Sven Efftinge CLA 2011-01-24 03:41:51 EST
The class is not designed to be used without an injector.
I've initialized the field with a default, but you shouldn't expect every Xtext class to work outside of Guice generally.
Comment 2 Sven Efftinge CLA 2011-01-24 03:43:20 EST
To put it more accurately: 
Shouldn't expect any class to work without its mandatory dependencies (i.e. any @Inject members without (optional=true)
Comment 3 Ed Willink CLA 2011-01-24 05:20:56 EST
I don't understand. I'm not aware that I'm deliberately using this class; I think the Xtext framework has provided it for me, although perhaps it was the Xtext 1.0 framework and I've neglected to (re-)align something for 2.0. The invocation was within Eclipse (rather than standalone Junit) so injection should be full configured.
Comment 4 Sven Efftinge CLA 2011-01-24 06:08:57 EST
Sorry, it looked like you were instantiating the instance yourself.
Comment 5 Sven Efftinge CLA 2011-01-24 07:25:54 EST
Could it be that you instantiated OCLinEcoreJavaValidator using the constructor?
Comment 6 Ed Willink CLA 2011-01-24 12:55:50 EST
No. The class is actually an empty inheritance of the auto-generated AbstractOCLinEcoreJavaValidator instantiated by:


	// contributed by org.eclipse.xtext.generator.validation.JavaValidatorFragment
	@org.eclipse.xtext.service.SingletonBinding(eager=true)	public Class<? extends org.eclipse.ocl.examples.xtext.oclinecore.validation.OCLinEcoreJavaValidator> bindOCLinEcoreJavaValidator() {
		return org.eclipse.ocl.examples.xtext.oclinecore.validation.OCLinEcoreJavaValidator.class;
	}

No other references.

I've been finding my M4.5 workspace unsatisfactory for MWE scripts, MWE2 editor comes and goes, ... so perhaps some strange hybrid 1.0/2.0 has occurred.

For Xtext 2.0 I had to remove 				registerForImportedPackages = false 
from
fragment = validation.JavaValidatorFragment
No idea why, or what the impact might be.
Comment 7 Sven Efftinge CLA 2011-01-24 15:55:38 EST
The line is:

final IResourceServiceProvider resourceServiceProvider = resourceServiceProviderRegistry.getResourceServiceProvider(resource.getURI());

Are you sure the registry and not the resource was null?

I've added a null check for the resource.
Comment 8 Ed Willink CLA 2011-01-24 16:36:15 EST
The debugger showed a null resourceServiceProviderRegistry, but the debugger is not always truthful. I didn't switch views to force a refresh so it is perhaps possible that is was a null resource.
Comment 9 Ed Willink CLA 2011-01-25 01:40:13 EST
I can reproduce the problem by a dummy edit in the following OCLinEcore file:

module _'My.ecore'
package  ; 

for which the empty package name is a problem.

Refreshing the Variables View confirms that resourceServiceProviderRegistry really is null. The fuller stack trace is:

NamesAreUniqueValidator.doCheckUniqueNames(Resource, CancelIndicator) line: 66	
NamesAreUniqueValidator.checkUniqueNamesInResourceOf(EObject) line: 62	
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25	
Method.invoke(Object, Object...) line: 592	
AbstractDeclarativeValidator$MethodWrapper.invoke(AbstractDeclarativeValidator$State) line: 111	
OCLinEcoreJavaValidator(AbstractDeclarativeValidator).internalValidate(EClass, EObject, DiagnosticChain, Map<Object,Object>) line: 297	
OCLinEcoreJavaValidator(AbstractInjectableValidator).validate(EClass, EObject, DiagnosticChain, Map<Object,Object>) line: 62	
NoEObjectCompositeEValidator(CompositeEValidator).validate(EClass, EObject, DiagnosticChain, Map<Object,Object>) line: 119	
CancelableDiagnostician(Diagnostician).validate(EClass, EObject, DiagnosticChain, Map<Object,Object>) line: 165	
CancelableDiagnostician(Diagnostician).validate(EObject, DiagnosticChain, Map<Object,Object>) line: 143	
CancelableDiagnostician.validate(EObject, DiagnosticChain, Map<Object,Object>) line: 36	
CancelableDiagnostician(Diagnostician).validate(EObject, Map<?,?>) line: 126	
ResourceValidatorImpl.validate(Resource, CheckMode, CancelIndicator) line: 107	
ValidationJob$1.exec(XtextResource) line: 79	
ValidationJob$1.exec(Object) line: 1	
XtextDocument$XtextDocumentLocker(AbstractReadWriteAcces<P>).readOnly(IUnitOfWork<T,P>) line: 32	
OCLinEcoreDocument(XtextDocument).readOnly(IUnitOfWork<T,XtextResource>) line: 86	
ValidationJob.createIssues(IProgressMonitor) line: 75	
ValidationJob.run(IProgressMonitor) line: 64	
Worker.run() line: 54	

of which perhaps only NoEObjectCompositeEValidator is unusual. It is my workaround for Bug 322639.

public class NoEObjectCompositeEValidator extends CompositeEValidator
{
	public NoEObjectCompositeEValidator() {
		setUseEObjectValidator(false);		// FIXME Find out how to inject at USE_EOBJECT_VALIDATOR
	}
}

[Perhaps you can solve my FIXME for me.]
Comment 10 Sven Efftinge CLA 2011-01-25 07:38:59 EST
There was some strange "robustness" code, which might have caused the situation.
I've changed the implementation so that it fails earlier with better information.

Could you do me a favor and retry tomorrow with the latest builds. Unfortunately I'm not able to reproduce your problem.
Comment 11 Ed Willink CLA 2011-01-29 07:07:41 EST
(In reply to comment #10)
> Could you do me a favor and retry tomorrow with the latest builds.
> Unfortunately I'm not able to reproduce your problem.

Installations are pretty difficult at present. EMF M5 has no Ecore, Xtext nightlies are not self-contained, Itemis nightlies have a dependency on a missing XSD typesystem...

Eventually found a selective Itemis update that P2 liked.

NPE does not appear, and editor seems sensible, but suddenly there is 

log4j:WARN No appenders could be found for logger (org.eclipse.xtext.ui.internal.Activator).
log4j:WARN Please initialize the log4j system properly.

in the Console.
Comment 12 Sven Efftinge CLA 2011-02-01 04:20:18 EST
fixed
Comment 13 Karsten Thoms CLA 2017-09-19 17:48:59 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 14 Karsten Thoms CLA 2017-09-19 17:59:50 EDT
Closing all bugs that were set to RESOLVED before Neon.0