Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322940 - Library provider enablement is being evaluated bottom up rather than top down
Summary: Library provider enablement is being evaluated bottom up rather than top down
Status: RESOLVED INVALID
Alias: None
Product: WTP Common Tools
Classification: WebTools
Component: Faceted Project Framework (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: wst.common CLA
QA Contact: Konstantin Komissarchik CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-17 13:48 EDT by Paul Fullbright CLA
Modified: 2010-08-19 11:40 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 Fullbright CLA 2010-08-17 13:48:14 EDT
I have redefined our library providers a bit.  Here's an example that illustrates the problem.

<provider
   id="jpa-user-library-provider"
   extends="user-library-provider"
   abstract="true">
   <enablement>
      <and>
         <with variable="requestingProjectFacet">
            <test property="org.eclipse.wst.common.project.facet.core.projectFacet" value="jpt.jpa" forcePluginActivation="true"/>
         </with>
         <with variable="projectFacets">
            <iterate>
               <not>
                  <test property="org.eclipse.jpt.core.group" value="modules" forcePluginActivation="true"/>
               </not>
            </iterate>
         </with>
      </and>		
   </enablement>
</provider>

<provider 
   id="jpa-generic1_0-user-library-provider" 
   extends="jpa-user-library-provider">
   <param name="validator" value="org.eclipse.jpt.core.internal.utility.KeyClassesValidator"/>
   <param name="validator.param.0" value="javax.persistence.Entity"/>
   <enablement>
      <with variable="jpaPlatform">
         <equals value="generic"/>
      </with>
   </enablement>
</provider>


In this case, there are exceptions being thrown when library providers are being tested for other facets (not JPA), because the second (above) library provider is being tested by using its enablement before its parent's enablement.  For instance, when library providers are being tested for JSF, the first thing that is tested is the value of the "jpaPlatform" variable, but there is no such variable, and so a CoreException is thrown.  It would be my expectation that the parent's more general enablement would be tested first before then proceeding to the child's more specific enablement.

Note that this works perfectly well when the "jpaPlatform" variable *is* present.
Comment 1 Paul Fullbright CLA 2010-08-17 14:03:37 EDT
Of course, the other option is to treat the CoreException as an expected possibility, not log it, and return false from LibraryProvider.isEnabledFor(.....).   That seems to be what others have done.  I hit many other similar CoreExceptions without the error log being filled up.
Comment 2 Paul Fullbright CLA 2010-08-17 14:17:47 EDT
Should also stipulate that this exists in 3.3 M1
Comment 3 Konstantin Komissarchik CLA 2010-08-18 12:21:54 EDT
One can equally well argue that the current ordering is the correct one. In many cases, the more derived provider will have more specific condition, so it makes sense to evaluate that condition first and skip evaluating the base condition. 

Regardless, the current ordering is API and cannot be changed without risking breakage to existing providers. I recommend adding a jpa facet check in your derived provider to guard your with expression.
Comment 4 Paul Fullbright CLA 2010-08-19 09:29:06 EDT
Do you have no comment on the CoreException failure?  In many other places in eclipse, the CoreException is treated as an expected possibility and false is returned rather than true.
Comment 5 Konstantin Komissarchik CLA 2010-08-19 11:40:10 EDT
> Do you have no comment on the CoreException failure?  In many other places in
> eclipse, the CoreException is treated as an expected possibility and false is
> returned rather than true.

It is generally not appropriate to treat CoreException as expected condition and not report it. I've seen very few cases where that is justified. In most situations, this approach just leads to debugging difficulties. I do not see this as an appropriate solution in this case.