Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 351034 - Potential NPE in mwe.Validator#groupByURI()
Summary: Potential NPE in mwe.Validator#groupByURI()
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: M4   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-03 17:25 EDT by Karsten Thoms CLA
Modified: 2017-10-31 11:25 EDT (History)
0 users

See Also:
sven.efftinge: kepler+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karsten Thoms CLA 2011-07-03 17:25:19 EDT
When the function Validator#groupByURI() that computes the multimap's key returns null, which it potentially does, a NPE is caused in a later step. 
--------------------
		result.putAll(Multimaps.index(Arrays.asList(diagnostic), new Function<MWEDiagnostic, URI>() {
			public URI apply(MWEDiagnostic from) {
				Issue issue = (Issue) from.getElement();
				URI uriToProblem = issue.getUriToProblem();
				return uriToProblem != null ? uriToProblem.trimFragment() : null <-- this will cause a NPE;
			}
		}));
--------------------

This situation should be handled better, maybe by throwing an exception in apply() with a meaningful text.


Error stack: 

Thread [main] (Suspended (exception NullPointerException))	
	Preconditions.checkNotNull(T) line: 180	
	ImmutableListMultimap$Builder<K,V>(ImmutableMultimap$Builder<K,V>).put(K, V) line: 149	
	ImmutableListMultimap$Builder<K,V>.put(K, V) line: 161	
	Multimaps.index(Iterable<V>, Function<? super V,K>) line: 1223	
	Validator.groupByURI(MWEDiagnostic[]) line: 148	
	Validator.appendMessages(StringBuilder, MWEDiagnostic[]) line: 121	
	Validator.toString(Issues) line: 104	
	Validator.validate(ResourceSet, IResourceServiceProvider$Registry, Issues) line: 88	
	Reader.invokeInternal(WorkflowContext, ProgressMonitor, Issues) line: 165	
	Reader(AbstractWorkflowComponent).invoke(WorkflowContext, ProgressMonitor, Issues) line: 126	
	Mwe2Bridge.invoke(IWorkflowContext) line: 34	
	Reader(AbstractWorkflowComponent).invoke(IWorkflowContext) line: 201	
	Workflow(AbstractCompositeWorkflowComponent).invoke(IWorkflowContext) line: 35	
	Workflow.run(IWorkflowContext) line: 19	
	Mwe2Runner.run(String, Map<String,String>, IWorkflowContext) line: 97	
	Mwe2Runner.run(String, Map<String,String>) line: 73	
	Mwe2Runner.run(URI, Map<String,String>, IWorkflowContext) line: 64	
	Mwe2Runner.run(URI, Map<String,String>) line: 55	
	Mwe2Launcher.run(String[]) line: 74	
	Mwe2Launcher.main(String[]) line: 35
Comment 1 Sven Efftinge CLA 2012-11-21 10:04:10 EST
pushed
Comment 2 Eclipse Webmaster CLA 2017-10-31 11:25:49 EDT
Requested via bug 522520.

-M.