Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » NPE during Batch Validation
NPE during Batch Validation [message #414274] Mon, 29 October 2007 12:51 Go to next message
Lars Heinemann is currently offline Lars HeinemannFriend
Messages: 37
Registered: July 2009
Member
Hi,

occasionally I get the following exception in a JUnit-Test:


java.lang.NullPointerException
at
org.eclipse.emf.validation.internal.service.AbstractValidati onContext$ConstraintFilter.accept(AbstractValidationContext. java:84)

at
org.eclipse.emf.validation.util.FilteredCollection$Iter.hasN ext(FilteredCollection.java:103)

at
org.eclipse.emf.validation.util.FilteredCollection.size(Filt eredCollection.java:170)

at
org.eclipse.emf.validation.internal.service.ClientContextMan ager.getBindings(ClientContextManager.java:213)

at
org.eclipse.emf.validation.internal.service.AbstractValidati onContext.getConstraints(AbstractValidationContext.java:482)

at
org.eclipse.emf.validation.internal.service.AbstractValidato r.evaluateConstraints(AbstractValidator.java:219)

at
org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:238)

at
org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:192)

at
org.eclipse.emf.validation.internal.service.BatchValidator.d oValidate(BatchValidator.java:137)

at
org.eclipse.emf.validation.internal.service.AbstractValidato r.validate(AbstractValidator.java:136)

at
org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:121)

In our case the BatchValidator is triggered by a command stack changed
event. It is also run from a builder on saving resources.
Do I need a form of synchronisation here or is this a bug?

Cheers,
Lars
Re: NPE during Batch Validation [message #414275 is a reply to message #414274] Mon, 29 October 2007 13:10 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Lars,

I guess it's dying here because the descriptor is null:

public boolean accept(Object constraint) {
IConstraintDescriptor desc =
((IModelConstraint)constraint).getDescriptor();

return (desc.isEnabled() && !isIgnored(desc));
}

It doesn't seem right that the descriptor should ever be null. Maybe
Christian will have some theory as to why it might be null...


Lars Heinemann wrote:
> Hi,
>
> occasionally I get the following exception in a JUnit-Test:
>
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.validation.internal.service.AbstractValidati onContext$ConstraintFilter.accept(AbstractValidationContext. java:84)
>
> at
> org.eclipse.emf.validation.util.FilteredCollection$Iter.hasN ext(FilteredCollection.java:103)
>
> at
> org.eclipse.emf.validation.util.FilteredCollection.size(Filt eredCollection.java:170)
>
> at
> org.eclipse.emf.validation.internal.service.ClientContextMan ager.getBindings(ClientContextManager.java:213)
>
> at
> org.eclipse.emf.validation.internal.service.AbstractValidati onContext.getConstraints(AbstractValidationContext.java:482)
>
> at
> org.eclipse.emf.validation.internal.service.AbstractValidato r.evaluateConstraints(AbstractValidator.java:219)
>
> at
> org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:238)
>
> at
> org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:192)
>
> at
> org.eclipse.emf.validation.internal.service.BatchValidator.d oValidate(BatchValidator.java:137)
>
> at
> org.eclipse.emf.validation.internal.service.AbstractValidato r.validate(AbstractValidator.java:136)
>
> at
> org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:121)
>
>
> In our case the BatchValidator is triggered by a command stack changed
> event. It is also run from a builder on saving resources.
> Do I need a form of synchronisation here or is this a bug?
>
> Cheers,
> Lars


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: NPE during Batch Validation [message #414276 is a reply to message #414275] Mon, 29 October 2007 13:16 Go to previous messageGo to next message
Lars Heinemann is currently offline Lars HeinemannFriend
Messages: 37
Registered: July 2009
Member
I just found another stacktrace in the Error-Log, only milliseconds
before the NPE:

java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractLi st.java:449)
at java.util.AbstractList$Itr.next(AbstractList.java:420)
at
org.eclipse.emf.validation.xml.XmlConstraintProvider.getBatc hConstraints(XmlConstraintProvider.java:272)
at
org.eclipse.emf.validation.internal.service.GetBatchConstrai ntsOperation.executeImpl(GetBatchConstraintsOperation.java:5 6)
at
org.eclipse.emf.validation.internal.service.AbstractGetConst raintsOperation.execute(AbstractGetConstraintsOperation.java :129)
at
org.eclipse.emf.validation.internal.service.ConstraintCache. execute(ConstraintCache.java:284)
at
org.eclipse.emf.validation.internal.service.ConstraintCache. getBatchConstraints(ConstraintCache.java:384)
at
org.eclipse.emf.validation.internal.service.GetBatchConstrai ntsOperation.executeImpl(GetBatchConstraintsOperation.java:5 6)
at
org.eclipse.emf.validation.internal.service.AbstractGetConst raintsOperation.execute(AbstractGetConstraintsOperation.java :129)
at
org.eclipse.emf.validation.service.ModelValidationService.ex ecute(ModelValidationService.java:356)
at
org.eclipse.emf.validation.service.ModelValidationService.ac cess$2(ModelValidationService.java:350)
at
org.eclipse.emf.validation.service.ModelValidationService$1. execute(ModelValidationService.java:121)
at
org.eclipse.emf.validation.internal.service.AbstractValidato r.execute(AbstractValidator.java:268)
at
org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:236)
at
org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:192)
at
org.eclipse.emf.validation.internal.service.BatchValidator.d oValidate(BatchValidator.java:137)
at
org.eclipse.emf.validation.internal.service.AbstractValidato r.validate(AbstractValidator.java:136)
at
org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:121)

Ed Merks schrieb:
> Lars,
>
> I guess it's dying here because the descriptor is null:
>
> public boolean accept(Object constraint) {
> IConstraintDescriptor desc =
> ((IModelConstraint)constraint).getDescriptor();
> return (desc.isEnabled() && !isIgnored(desc));
> }
>
> It doesn't seem right that the descriptor should ever be null. Maybe
> Christian will have some theory as to why it might be null...
>
>
> Lars Heinemann wrote:
>> Hi,
>>
>> occasionally I get the following exception in a JUnit-Test:
>>
>>
>> java.lang.NullPointerException
>> at
>> org.eclipse.emf.validation.internal.service.AbstractValidati onContext$ConstraintFilter.accept(AbstractValidationContext. java:84)
>>
>> at
>> org.eclipse.emf.validation.util.FilteredCollection$Iter.hasN ext(FilteredCollection.java:103)
>>
>> at
>> org.eclipse.emf.validation.util.FilteredCollection.size(Filt eredCollection.java:170)
>>
>> at
>> org.eclipse.emf.validation.internal.service.ClientContextMan ager.getBindings(ClientContextManager.java:213)
>>
>> at
>> org.eclipse.emf.validation.internal.service.AbstractValidati onContext.getConstraints(AbstractValidationContext.java:482)
>>
>> at
>> org.eclipse.emf.validation.internal.service.AbstractValidato r.evaluateConstraints(AbstractValidator.java:219)
>>
>> at
>> org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:238)
>>
>> at
>> org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:192)
>>
>> at
>> org.eclipse.emf.validation.internal.service.BatchValidator.d oValidate(BatchValidator.java:137)
>>
>> at
>> org.eclipse.emf.validation.internal.service.AbstractValidato r.validate(AbstractValidator.java:136)
>>
>> at
>> org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:121)
>>
>>
>> In our case the BatchValidator is triggered by a command stack changed
>> event. It is also run from a builder on saving resources.
>> Do I need a form of synchronisation here or is this a bug?
>>
>> Cheers,
>> Lars
Re: NPE during Batch Validation [message #414277 is a reply to message #414275] Mon, 29 October 2007 13:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Ed, Lars,

An IModelConstraint is required to provide a descriptor -- it must never be
null.

If this problem happens only occasionally, then perhaps some synchronization
is required on the initialization of constraints in this application? In
general, the EMF Validation Framework is not thread-safe (as with the rest
of EMF) so the onus is on clients to provide concurrency controls.

Cheers,

Christian


Ed Merks wrote:

> Lars,
>
> I guess it's dying here because the descriptor is null:
>
> public boolean accept(Object constraint) {
> IConstraintDescriptor desc =
> ((IModelConstraint)constraint).getDescriptor();
>
> return (desc.isEnabled() && !isIgnored(desc));
> }
>
> It doesn't seem right that the descriptor should ever be null. Maybe
> Christian will have some theory as to why it might be null...
>
>

-----8<-----
Re: NPE during Batch Validation [message #414278 is a reply to message #414276] Mon, 29 October 2007 13:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Lars,

I don't think there's anything that your application could do to cause this
concurrent modification except actually running validation on multiple
concurrent threads, which isn't supported. Is that what you're doing?
Perhaps we could investigate the possibility of protecting the
initialization of constraints in the stock XML-based provider from
concurrent access. Care to raise an enhancement request? Attaching a
reproducible use case to it would help a lot. Even more helpful, of
course, would be a patch :-)

Cheers,

Christian


Lars Heinemann wrote:

> I just found another stacktrace in the Error-Log, only milliseconds
> before the NPE:
>
> java.util.ConcurrentModificationException
> at
> java.util.AbstractList$Itr.checkForComodification(AbstractLi st.java:449)
> at java.util.AbstractList$Itr.next(AbstractList.java:420) at
>
org.eclipse.emf.validation.xml.XmlConstraintProvider.getBatc hConstraints(XmlConstraintProvider.java:272)
> at
>
org.eclipse.emf.validation.internal.service.GetBatchConstrai ntsOperation.executeImpl(GetBatchConstraintsOperation.java:5 6)
> at
>
org.eclipse.emf.validation.internal.service.AbstractGetConst raintsOperation.execute(AbstractGetConstraintsOperation.java :129)
> at
>
org.eclipse.emf.validation.internal.service.ConstraintCache. execute(ConstraintCache.java:284)
> at
>
org.eclipse.emf.validation.internal.service.ConstraintCache. getBatchConstraints(ConstraintCache.java:384)
> at
>
org.eclipse.emf.validation.internal.service.GetBatchConstrai ntsOperation.executeImpl(GetBatchConstraintsOperation.java:5 6)
> at
>
org.eclipse.emf.validation.internal.service.AbstractGetConst raintsOperation.execute(AbstractGetConstraintsOperation.java :129)
> at
>
org.eclipse.emf.validation.service.ModelValidationService.ex ecute(ModelValidationService.java:356)
> at
>
org.eclipse.emf.validation.service.ModelValidationService.ac cess$2(ModelValidationService.java:350)
> at
>
org.eclipse.emf.validation.service.ModelValidationService$1. execute(ModelValidationService.java:121)
> at
>
org.eclipse.emf.validation.internal.service.AbstractValidato r.execute(AbstractValidator.java:268)
> at
>
org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:236)
> at
>
org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:192)
> at
>
org.eclipse.emf.validation.internal.service.BatchValidator.d oValidate(BatchValidator.java:137)
> at
>
org.eclipse.emf.validation.internal.service.AbstractValidato r.validate(AbstractValidator.java:136)
> at
>
org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:121)
>

-----8<-----
Re: NPE during Batch Validation [message #414279 is a reply to message #414278] Mon, 29 October 2007 13:51 Go to previous messageGo to next message
Lars Heinemann is currently offline Lars HeinemannFriend
Messages: 37
Registered: July 2009
Member
Hi Christian,

yes we do call the BatchValidator from two different threads.
First it is called from within a builder, which runs quite a while for
large models and the second one is from a command stack listener to
provide some instant validation while editing.
At present I can't think of anything else but wrapping the call to
IBatchValidator.validate with a lock to prevent the problem. But this
would mean that the command stack could have to wait for the builder,
which would be unacceptable.
I will open an enhancement request, however I have to find a solution
based on the release that 'fits' Eclipse 3.2/EMF 2.2.

Cheers,
Lars

Christian W. Damus schrieb:
> Hi, Lars,
>
> I don't think there's anything that your application could do to cause this
> concurrent modification except actually running validation on multiple
> concurrent threads, which isn't supported. Is that what you're doing?
> Perhaps we could investigate the possibility of protecting the
> initialization of constraints in the stock XML-based provider from
> concurrent access. Care to raise an enhancement request? Attaching a
> reproducible use case to it would help a lot. Even more helpful, of
> course, would be a patch :-)
>
> Cheers,
>
> Christian
>
>
> Lars Heinemann wrote:
>
>> I just found another stacktrace in the Error-Log, only milliseconds
>> before the NPE:
>>
>> java.util.ConcurrentModificationException
>> at
>> java.util.AbstractList$Itr.checkForComodification(AbstractLi st.java:449)
>> at java.util.AbstractList$Itr.next(AbstractList.java:420) at
>>
> org.eclipse.emf.validation.xml.XmlConstraintProvider.getBatc hConstraints(XmlConstraintProvider.java:272)
>> at
>>
> org.eclipse.emf.validation.internal.service.GetBatchConstrai ntsOperation.executeImpl(GetBatchConstraintsOperation.java:5 6)
>> at
>>
> org.eclipse.emf.validation.internal.service.AbstractGetConst raintsOperation.execute(AbstractGetConstraintsOperation.java :129)
>> at
>>
> org.eclipse.emf.validation.internal.service.ConstraintCache. execute(ConstraintCache.java:284)
>> at
>>
> org.eclipse.emf.validation.internal.service.ConstraintCache. getBatchConstraints(ConstraintCache.java:384)
>> at
>>
> org.eclipse.emf.validation.internal.service.GetBatchConstrai ntsOperation.executeImpl(GetBatchConstraintsOperation.java:5 6)
>> at
>>
> org.eclipse.emf.validation.internal.service.AbstractGetConst raintsOperation.execute(AbstractGetConstraintsOperation.java :129)
>> at
>>
> org.eclipse.emf.validation.service.ModelValidationService.ex ecute(ModelValidationService.java:356)
>> at
>>
> org.eclipse.emf.validation.service.ModelValidationService.ac cess$2(ModelValidationService.java:350)
>> at
>>
> org.eclipse.emf.validation.service.ModelValidationService$1. execute(ModelValidationService.java:121)
>> at
>>
> org.eclipse.emf.validation.internal.service.AbstractValidato r.execute(AbstractValidator.java:268)
>> at
>>
> org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:236)
>> at
>>
> org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:192)
>> at
>>
> org.eclipse.emf.validation.internal.service.BatchValidator.d oValidate(BatchValidator.java:137)
>> at
>>
> org.eclipse.emf.validation.internal.service.AbstractValidato r.validate(AbstractValidator.java:136)
>> at
>>
> org.eclipse.emf.validation.internal.service.BatchValidator.v alidate(BatchValidator.java:121)
>
> -----8<-----
Re: NPE during Batch Validation [message #414281 is a reply to message #414279] Mon, 29 October 2007 15:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Lars,

For version 1.0 of the validation component (which is what you need for
Eclipse 3.2), you may be able to work around this problem if you don't mind
using internal API.

The XmlConstraintProvider that you see in your stack traces is simply the
default constraint provider when none is specified in the
<constraintProvider> element in the plugin.xml. You can identify a custom
provider using the "class" attribute. To continue using the plugin.xml
method of declaring constraints, you could specify a subclass (defined by
you) of the XmlConstraintProvider and implement the synchronization, there.

HTH,

Christian


Lars Heinemann wrote:

> Hi Christian,
>
> yes we do call the BatchValidator from two different threads.
> First it is called from within a builder, which runs quite a while for
> large models and the second one is from a command stack listener to
> provide some instant validation while editing.
> At present I can't think of anything else but wrapping the call to
> IBatchValidator.validate with a lock to prevent the problem. But this
> would mean that the command stack could have to wait for the builder,
> which would be unacceptable.
> I will open an enhancement request, however I have to find a solution
> based on the release that 'fits' Eclipse 3.2/EMF 2.2.
>
> Cheers,
> Lars

-----8<-----
Re: NPE during Batch Validation [message #415961 is a reply to message #414281] Mon, 14 January 2008 10:02 Go to previous messageGo to next message
Lars Heinemann is currently offline Lars HeinemannFriend
Messages: 37
Registered: July 2009
Member
Christian,

thanks for the hint. Can you think of a solution without using EMF
internal code?

Cheers,
Lars

Christian W. Damus schrieb:
> Hi, Lars,
>
> For version 1.0 of the validation component (which is what you need for
> Eclipse 3.2), you may be able to work around this problem if you don't mind
> using internal API.
>
> The XmlConstraintProvider that you see in your stack traces is simply the
> default constraint provider when none is specified in the
> <constraintProvider> element in the plugin.xml. You can identify a custom
> provider using the "class" attribute. To continue using the plugin.xml
> method of declaring constraints, you could specify a subclass (defined by
> you) of the XmlConstraintProvider and implement the synchronization, there.
>
> HTH,
>
> Christian
>
>
> Lars Heinemann wrote:
>
>> Hi Christian,
>>
>> yes we do call the BatchValidator from two different threads.
>> First it is called from within a builder, which runs quite a while for
>> large models and the second one is from a command stack listener to
>> provide some instant validation while editing.
>> At present I can't think of anything else but wrapping the call to
>> IBatchValidator.validate with a lock to prevent the problem. But this
>> would mean that the command stack could have to wait for the builder,
>> which would be unacceptable.
>> I will open an enhancement request, however I have to find a solution
>> based on the release that 'fits' Eclipse 3.2/EMF 2.2.
>>
>> Cheers,
>> Lars
>
> -----8<-----
Re: NPE during Batch Validation [message #415965 is a reply to message #415961] Mon, 14 January 2008 15:38 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Lars,

The only other approach that I could suggest would be to define your own
constraint provider "from scratch" (implementing IModelConstraintProvider)
that doesn't declare the constraints in the plugin.xml. This gives you the
flexibility to define constraints in a more convenient format, perhaps even
as EMF resources modeled using Ecore, and would relieve the extension
registry of a non-trivial load of data.

Of course, this is a much more heavy-weight solution, but might provide
additional benefits that make it worth your while in the long run.

Cheers,

Christian


Lars Heinemann wrote:

> Christian,
>
> thanks for the hint. Can you think of a solution without using EMF
> internal code?
>
> Cheers,
> Lars
>
> Christian W. Damus schrieb:
>> Hi, Lars,
>>
>> For version 1.0 of the validation component (which is what you need for
>> Eclipse 3.2), you may be able to work around this problem if you don't
>> mind using internal API.
>>
>> The XmlConstraintProvider that you see in your stack traces is simply the
>> default constraint provider when none is specified in the
>> <constraintProvider> element in the plugin.xml. You can identify a
>> custom
>> provider using the "class" attribute. To continue using the plugin.xml
>> method of declaring constraints, you could specify a subclass (defined by
>> you) of the XmlConstraintProvider and implement the synchronization,
>> there.
>>
>> HTH,
>>
>> Christian
>>
>>
>> Lars Heinemann wrote:
>>
>>> Hi Christian,
>>>
>>> yes we do call the BatchValidator from two different threads.
>>> First it is called from within a builder, which runs quite a while for
>>> large models and the second one is from a command stack listener to
>>> provide some instant validation while editing.
>>> At present I can't think of anything else but wrapping the call to
>>> IBatchValidator.validate with a lock to prevent the problem. But this
>>> would mean that the command stack could have to wait for the builder,
>>> which would be unacceptable.
>>> I will open an enhancement request, however I have to find a solution
>>> based on the release that 'fits' Eclipse 3.2/EMF 2.2.
>>>
>>> Cheers,
>>> Lars
>>
>> -----8<-----
Previous Topic:Eclipse Forms, IItemPropertyDescriptor and EList
Next Topic:Missing entries in 'collectNewChildDescriptors' in some rare case
Goto Forum:
  


Current Time: Thu Apr 25 14:02:09 GMT 2024

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

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

Back to the top