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

Bug 369444

Summary: Add session bean should not always create a ejbModule source folder in the client project
Product: [WebTools] WTP EJB Tools Reporter: Roberto Sanchez Herrera <shr31223>
Component: jst.ejbAssignee: Roberto Sanchez Herrera <shr31223>
Status: RESOLVED FIXED QA Contact: Kaloyan Raev <kaloyan>
Severity: normal    
Priority: P3 CC: ccc, makandre
Version: 3.2.5PFlags: kaloyan: review+
Target Milestone: 3.3.2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 369832    
Attachments:
Description Flags
EAR for recreating bug
none
Proposed patch for 3.3.2 and 3.4
none
Proposed patch for 3.3.2 and 3.4 (version 2) none

Description Roberto Sanchez Herrera CLA 2012-01-23 15:25:44 EST
When a EJB project and its EJB client jar project have different source folders (e.g. EJB project has ejbModule, client has scr), and a session bean is created, the interfaces are not created in the existing source folder, but a source folder with the same name as the source folder in the EJB project is created, leaving the EJB client project with two source folders.

Steps to recreate:

1. Import the attached EAR file. Note that the EJB project has one scource folder: ejbModule, and the client has one source folder: src. Also note that both folders have java files.
2. Create a new session bean, including local and/or remote business interfaces.
3. Note that a new source folder (ejbModule) is created in the client project, instead of using the existing folder. Now, the EJB client project has two different source folders.
Comment 1 Roberto Sanchez Herrera CLA 2012-01-23 15:26:46 EST
Created attachment 209936 [details]
EAR for recreating bug
Comment 2 Roberto Sanchez Herrera CLA 2012-01-23 15:38:16 EST
Created attachment 209937 [details]
Proposed patch for 3.3.2 and 3.4

This patch uses existing source folder in ejb client jar if a source folder with the same name as the one uses in the EJB project does not exist.
Comment 3 Roberto Sanchez Herrera CLA 2012-01-25 15:40:39 EST
Any though on this one?
Comment 4 Kaloyan Raev CLA 2012-01-26 06:52:29 EST
Roberto, sorry for the delay. 

This bug is a good catch and worth fixing it for Indigo. 

I have one comment on the patch. On line 144 you call "folder.exists" and a few lines later you check "folder == null". It seems like the order is not correct. If folder is null then line 144 will throw NPE. Do you agree?
Comment 5 Roberto Sanchez Herrera CLA 2012-01-26 10:43:56 EST
Well, not completely :D The call to getClientSourceFolder() will never return null, so the call to "if (!folder.exists()){ " should be safe. The method getFirstJavaSourceFolderInClientJar() will return null in the case the project does not have a source folder, so that is why I check if the folder in null this time, and if it is, then the folder will be created.

But Carl found a small optimization to the code, that consists on putting the check for null inside the first if, and not at the same level. Attaching a new patch. 

Kaloyan, would you mind reviewing it again after these comments? 

Thank you!
Comment 6 Roberto Sanchez Herrera CLA 2012-01-26 10:44:34 EST
Created attachment 210120 [details]
Proposed patch for 3.3.2 and 3.4 (version 2)
Comment 7 Kaloyan Raev CLA 2012-01-26 10:47:03 EST
OK. Now I understand. Thank you for the detailed explanation.
Comment 8 Roberto Sanchez Herrera CLA 2012-01-26 11:39:29 EST
Code committed to HEAD and R3_3_maintenance for WTP 3.4 and 3.3.2. Resolving bug.