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

Bug 193816

Summary: validators are still being triggered when they use contentTypeBinding
Product: [WebTools] WTP Common Tools Reporter: Amy Wu <for.work.things>
Component: wst.validationAssignee: Gary Karasiuk <karasiuk>
Status: CLOSED FIXED QA Contact: Chuck Bridgham <cbridgha>
Severity: major    
Priority: P3 CC: ccc, remy.suen, thatnitind
Version: 2.0   
Target Milestone: 3.0.3   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
org.eclipse.wst.validation.patch
none
updated patch none

Description Amy Wu CLA 2007-06-21 14:56:22 EDT
using wtp2.0 RC4 200706210235

Even though a validator specifies a contentTypeBinding, it appears the validator is still being run on files that are not of that content type.

This was discovered in bug 193805 since the JSP Semantics validator, which should only run on JSP content types, was still being triggered when you invoke Validate on a text file.
Comment 1 Amy Wu CLA 2007-06-21 16:39:11 EDT
Created attachment 72088 [details]
org.eclipse.wst.validation.patch

Fix is in 2 isApplicableTo() methods in ValidatorMetaData.

In the first one, isApplicableTo() was checking if there were any filters associated with the validator, if not, then the validator would run on every resource.  The fix was not only to check if there were any filters, but also to check if the validator was associated with any content types.  If not, then it would run on every resource.  But if so, then do further checking.
public boolean isApplicableTo(IResource resource, int resourceDelta) {
	// If no filters are specified, then every type of resource should be 
	// validated/trigger a
	// rebuild of the model cache
	// Also make sure no content type id is specified (BUG 193816)
===>	if (_filters == null && getContentTypeIds() == null)
		return true;

	return isApplicableTo(resource, resourceDelta, _filters);
}

In the second isApplicableTo(), just need to add a null check for _filters since the first isApplicableTo() was altered to allow null _filters as long as the validator was associated with some contentTypeIds.
boolean isApplicableTo(IResource resource, int resourceDelta,
		ValidatorFilter[] filters) {
	// Are any of the filters satisfied? (i.e., OR them, not AND them.)
	// make sure filters is not null (BUG 193816)
==>	if (_filters != null && checkIfValidSourceFile(resource)) {
		for (int i = 0; i < filters.length; i++) {
			ValidatorFilter filter = filters[i];
...
Comment 2 Amy Wu CLA 2007-06-21 16:41:32 EDT
I should note that this problem will occur if a validator only specifies a contentTypeBinding and no name filters in its extension.
Comment 3 Chuck Bridgham CLA 2007-09-05 09:30:42 EDT
Moving to 3.0
Comment 4 Gary Karasiuk CLA 2008-07-21 07:24:27 EDT
Amy,

Can you please confirm if this is still a problem in WTP 3.0?

With the JSP validator being ported to the new framework, I'm wondering if this problem has gone away (at least for the JSP validator). 
Comment 5 Amy Wu CLA 2008-07-25 13:06:35 EDT
Yes, this is still a problem in WTP 3.0.  I ran into this problem with the validator formerly known as the JSP Semantics Validator which was contributed by JSF component, not JSP component.  The validator is now called the JSF View Validator, and this validator has not migrated to the new V2 framework yet.

I verified on a recent WTP 3.0.1 build that if I create a JSF project (Web project + JSF Facet) and then create a text file, I verified that the JSF validator will still be called even though it's only supposed to run on files with JSP content type.

JSF has since fixed their validator a bit so that at least the validator will check again once it's called to validate to make sure the file is JSP content type.  They also added some project facet filters so that their validator at least doesnt run on all files in all projects (see bug 214385).  So I can lower the severity to normal if you'd like, but yes, this is still a problem with the old validation framework.
Comment 6 Gary Karasiuk CLA 2008-10-03 08:02:46 EDT
Created attachment 114182 [details]
updated patch
Comment 7 Gary Karasiuk CLA 2008-10-05 15:42:21 EDT
Released to 3.0.3
Comment 8 Gary Karasiuk CLA 2008-10-05 15:54:30 EDT
Released to 3.1 (i.e. HEAD)
Comment 9 Amy Wu CLA 2008-10-20 01:53:35 EDT
I didn't see the JSF View Validator popping up in my progress view when I validated a text file in a recent wtp 303 build, so it looks like this bug is fixed. marking as verified.
Comment 10 Gary Karasiuk CLA 2008-10-20 05:01:12 EDT
closing