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

Bug 207160

Summary: Template XML file isn't correctly queried
Product: z_Archived Reporter: Sinee Paungam <spaungam>
Component: TPTPAssignee: Alex Nan <apnan>
Status: CLOSED FIXED QA Contact:
Severity: critical    
Priority: P1 CC: apnan, jcayne, jkubasta, sluiman
Version: unspecifiedKeywords: plan
Target Milestone: ---Flags: jcayne: iplog+
apnan: review+
Hardware: PC   
OS: Windows XP   
Whiteboard: closed460
Attachments:
Description Flags
Workaround/patch for this problem
none
Patch
none
Test Plug-in none

Description Sinee Paungam CLA 2007-10-23 09:30:08 EDT
The API for EventXMLFileEventFactoryHomeImpl states that the following is the look up sequence for the template XML file.

1.	The EventXMLFileEventFactoryHomeImpl class' class loader is queried for the event configuration template XML file.
2.	The system's class loader is queried for the event configuration template XML file.
3.	The current thread's context class loader is queried for the event configuration template XML file.

When I look at the code that handles this search, resolveTemplateXMLFileInputStream(), the search expects that an exception is thrown whenever the XML can't be found.  Because a null is really returned (not an exception) when the xml file can't be resolved, the search never looks at any other classloaders other than the first one. 

I've attached my code that I use to override the resolveTemplateXMLFileInputStream() method.
Comment 1 Sinee Paungam CLA 2007-10-23 09:30:59 EDT
Created attachment 80949 [details]
Workaround/patch for this problem
Comment 2 Paul Slauenwhite CLA 2007-10-29 07:32:58 EDT
4.5 i1 development is closed.  I will check in the patch when i2 begins.
Comment 3 Paul Slauenwhite CLA 2007-10-29 07:35:36 EDT
Assuming problem found in TPTP 4.2.2.  Please correct if necessary.
Comment 4 Paul Slauenwhite CLA 2007-10-29 07:36:49 EDT
Created attachment 81438 [details]
Patch

Patch has been tested and verified with the existing JUnit tests for this component.
Comment 5 Paul Slauenwhite CLA 2007-10-29 07:46:48 EDT
Created attachment 81439 [details]
Test Plug-in

Ann, please verify that the fix resolves your issue (without the work-around) using this TPTP 4.5 plug-in.  

Note, this test plug-in is ONLY for testing purposes and should not be packaged, deployed, or shipped.
Comment 6 Paul Slauenwhite CLA 2007-11-07 18:32:27 EST
Correcting target.
Comment 7 Paul Slauenwhite CLA 2007-11-14 17:59:31 EST
Alex, can you please review this patch?
Comment 8 Alex Nan CLA 2007-11-15 13:53:25 EST
Patch reviewed.
Comment 9 Paul Slauenwhite CLA 2007-11-15 14:49:36 EST
Stop-ship template:

1. Explain why you believe this is a stop-ship defect. How does the defect manifest itself, and how will users of TPTP / consuming products be affected if the defect is not fixed?

In the Common Base Evnet implmentation, a template XML file is loaded by resilving its inputstream from the class loader.  The code uses a class loader look-up sequeunce (e.g. EventXMLFileEventFactoryHomeImpl's class loader, system's class loader, and the current thread's context class loader) to resolve the inputstream.  The current code expects that a failed look-up will throw an exception, but the ClassLoader#getResourceAsStream(String) API returns null when the resource cannot be found.  As a result, the template XML file is not loaded.

An IBM consumming product requires this fix.

2. Is there a work-around? If so, why do you believe the work-around is insufficient?

No.

3. Is this a regression or API breakage? Explain.

No.

4. Does this require new API?

No.

5. Who performed the code review?

Alex Nan

6. Is there a test case attached to the bugzilla record?

Yes.

7. What is the risk associated with this fix?

Low to medium.

8. Is this fix related to any standards that TPTP adheres to? If so, who has validated that the fix continues to adhere to the standard?

No.
Comment 10 Harm Sluiman CLA 2007-11-15 15:17:24 EST
Paul there seem to be a lot of caught and ignored exceptions which is not an encouraged practice. I realize this was in the end the previous behavior as well but the code in general is a complete replace of even the comments, so catching and at least logging the exception is one option or simply let the exception flow, although that is an api change that would ripple up.

This all implies that the old code never worked a was clearly not tested either. Although clearly bad, I find it odd that only now this problem is surfacing and now with high importance.

BTW the contributed patch will need to be marked as a non-committer contribution.
Comment 11 Paul Slauenwhite CLA 2007-11-16 13:05:30 EST
(In reply to comment #10)
> Paul there seem to be a lot of caught and ignored exceptions which is not an
> encouraged practice. I realize this was in the end the previous behavior as
> well but the code in general is a complete replace of even the comments, so
> catching and at least logging the exception is one option or simply let the
> exception flow, although that is an api change that would ripple up.

The multiple catch blocks (opposed to one) are required in the event that caller does not sufficient privileges for one particular class loader.

The Common Base Event implementation does not have logging instrumentation (we do not log from a log structure) and we should not change the API (re-throw the exception) to resolve a behaviour defect.

> This all implies that the old code never worked a was clearly not tested
> either. Although clearly bad, I find it odd that only now this problem is
> surfacing and now with high importance.

Correct, this code has never worked or been tested correctly.  The symptom has only surfaced now since in the consuming prodcut, the current class' class loader could not resolve the template file (e.g. segregated class loaders), for example, in a server environment where the template XML file is used by a different class loader.  This behaviour is not typical since in most cases, the current class' class loader resolves the template file.

Note, I did not attach the new test case:

Abstract: Loading an event configuration template XML file in a multiple class loader environment.

Version: October 28, 2007

Since: October 28, 2007

Authors: 
  1. Paul Slauenwhite

Requires: 

Platforms: 
  1. Windows
  2. Linux

Notes: 

Steps: 
  1. Create the EMF Common Base Event v1.0.1 Sample (File >> New >> Example... >> Logging).
  2. Create a second plug-in project (e.g. TestPluginProject).
  3. Move the HyadesEMFCommonBaseEventv101Project\src\HyadesEMFCommonBaseEventv101Sample.event.xml file to the source tree of the second plug-in project.
  4. Run the HyadesEMFCommonBaseEventv101Project\src\HyadesEMFCommonBaseEventv101Sample.java class, following the example's instructions.

Results: 
  1. See the example's instructions for desired output.

> BTW the contributed patch will need to be marked as a non-committer
> contribution.

Although Anne's patch was for resolving the issue in the consuming product by overloading the resolveTemplateXMLFileInputStream(String) method, we can mark it as a non-committer contribution and add Anne to the project IP log for 4.5.

Anne: 

There are three questions that should be answered for this
contribution (see http://www.eclipse.org/legal/EclipseLegalProcessPoster.pdf).  Please provide the answers in this defect:

1) Did you write this code yourself?
2) Do you have the right to contribute this code to Eclipse?
3) Do you submit this patch under the terms of the Eclipse Public License (http://www.eclipse.org/org/documents/epl-v10.php)?

Comment 12 Paul Slauenwhite CLA 2007-11-16 13:21:51 EST
Comment on attachment 80949 [details]
Workaround/patch for this problem

Not the patch submitted for Project/PMC approval.
Comment 13 Paul Slauenwhite CLA 2007-11-20 15:31:58 EST
Transferring to Alex.
Comment 14 Alex Nan CLA 2007-12-04 12:04:54 EST
Sinee, can you let us know on which release level this fix is required? Do you need a fix on 4.2.2 or the current 4.4.1 fix would be good?
Thanks.
Comment 15 Harm Sluiman CLA 2007-12-05 12:31:08 EST
(In reply to comment #14)
> Sinee, can you let us know on which release level this fix is required? Do you
> need a fix on 4.2.2 or the current 4.4.1 fix would be good?
> Thanks.
> 

or the default which would be 4.5
Comment 16 Alex Nan CLA 2007-12-10 11:31:31 EST
Changing target to 4.5 i5 since it was not approved in 4.4.1. The code will be checked into the 4.5 stream in i5 since this defect is not neccessarily needed in M4.
Comment 17 Alex Nan CLA 2008-01-08 22:16:27 EST
Fix commited to 4.5 and manual test case created for testing the defect.
Comment 18 Joel Cayne CLA 2008-10-23 14:44:23 EDT
adding iplog+ per Ganymede IP log
Comment 19 Paul Slauenwhite CLA 2009-06-30 12:17:16 EDT
As of TPTP 4.6.0, TPTP is in maintenance mode and focusing on improving quality by resolving relevant enhancements/defects and increasing test coverage through test creation, automation, Build Verification Tests (BVTs), and expanded run-time execution. As part of the TPTP Bugzilla housecleaning process (see http://wiki.eclipse.org/Bugzilla_Housecleaning_Processes), this enhancement/defect is verified/closed by the Project Lead since this enhancement/defect has been resolved and unverified for more than 1 year and considered to be fixed. If this enhancement/defect is still unresolved and reproducible in the latest TPTP release (http://www.eclipse.org/tptp/home/downloads/), please re-open.