Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 339689 - CurrentConstraintData set on first call to Constraint cannot be retrieved again
Summary: CurrentConstraintData set on first call to Constraint cannot be retrieved again
Status: CLOSED WONTFIX
Alias: None
Product: EMF Services
Classification: Modeling
Component: Validation (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 minor
Target Milestone: ---   Edit
Assignee: EMF Services Validation inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 513438 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-03-11 08:45 EST by Paul Hoser CLA
Modified: 2022-05-26 15:32 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Hoser CLA 2011-03-11 08:45:06 EST
Build Identifier: 201005251253

If a constraint registered via the XMLConstraintProvider uses the putCurrentConstraintData() method on the AbstractValidationContext the first time its validate() method is called the data stored in the AbstractValidationContext can not be retrieved in later calls to the Constraint's validate() method via the getCurrentConstraintData().

public class MyConstraint extends AbstractModelConstraint {

  private int fCounter = 0;

  public IStatus validate(IValidationConstext ctx) {
    if(fCounter == 0) {
      ctx.putCurrentConstraintData("MyData");
    } else {
      ((String)ctx.getCurrentConstraintData()).length();
    }
    fCounter++;
  }

}

The above Constraint will throw a NPE the second time it is being called. This due to the fact that when being called the first time the AbsttractValidationContext's currentConstraint field (which is used as storage key in the putCurrentConstraintData() method) is a AbstractConstraintProvider$ConstraintProxy.
When the Constraint is called the second time the currentConstraint field of the AbstractValidationContext is a JavaConstraintParser$ConstraintAdapter. Two different objects are used as a key for storing and retrieving.

Reproducible: Always
Comment 1 Felix Dorner CLA 2019-01-22 06:50:26 EST
*** Bug 513438 has been marked as a duplicate of this bug. ***
Comment 2 Pierre-Charles David CLA 2022-05-14 09:53:10 EDT
Eclipse EMF Validation is moving away from this bugs.eclipse.org issue tracker to https://github.com/eclipse/emf-validation.

If this issue is relevant to you and still present in the latest release:

* Create a new issue at https://github.com/eclipse/emf-validation/issues/.
  * Use as title in GitHub the title of this Bugzilla ticket (may include the bug number or not, at your own convenience)
  * In the GitHub description, start with a link to this bugzilla ticket
  * Optionally add new content to the description if it can helps towards resolution
* Update bugzilla ticket
  * Add to "See also" property (up right column) the link to the newly created GitHub issue
  * Add a comment "Migrated to <link-to-newly-created-GitHub-issue>"
  * Set status as CLOSED MOVED

All issues that remain open will be automatically closed next week or so. Then the Bugzilla component for EMF Validation will be archived and made read-only.
Comment 3 Pierre-Charles David CLA 2022-05-26 15:32:29 EDT
EMF Validation is in maintenance mode and has very few resources available.
If you feel this issue is still relevant and important enough, and are willing to actively contribute yourself (or fund someone to work on it), please re-open on GitHub at https://github.com/eclipse/emf-validation/issues