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

Bug 357426

Summary: org/eclipse/wst/server/core/internal/ServerNotificationManager bitwise kind check is incorrect
Product: [WebTools] WTP ServerTools Reporter: Raymond Lai <rkklai>
Component: wst.serverAssignee: Steven Hung <sghung>
Status: RESOLVED FIXED QA Contact: Elson Yuen <eyuen7>
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   
See Also: https://git.eclipse.org/r/109071
Whiteboard:
Attachments:
Description Flags
Patch v1.0 eyuen7: iplog+

Description Raymond Lai CLA 2011-09-12 18:06:07 EDT
Build Identifier: 

The current check is:
boolean isKindMatch = (mask & eventKind ^ ServerEvent.SERVER_CHANGE ^ ServerEvent.MODULE_CHANGE) != 0;

Say the mask is in binary:
(MODULE_CHANGE) (SERVER_CHANGE) (NOT USED YET) (RESTART_STATE_CHANGE) (PUBLISH_STATE_CHANGE) (STATE_CHANGE)
100010, e.g. interested in MODULE_CHANGE | PUBLISH_STATE_CHANGE

Now the server has a module state change, so 100001 is fired.

The current code will give true for the kind check which is wrong.
1. mask & eventKind = 100010 & 100001 = 100000
2. 100000 ^ SERVER_CHANGE = 110000
3. 110000 ^ MODULE_CHANGE = 010000 which is != 0. 
The kind check gave a result of true which is wrong

The correct check should take out the SERVER_CHANGE and MODULE_CHANGE bits first. 
int kindOnly = (eventKind | ServerEvent.SERVER_CHANGE | ServerEvent.MODULE_CHANGE) ^ ServerEvent.SERVER_CHANGE ^ ServerEvent.MODULE_CHANGE;

Then do the kind check:
boolean isKindMatch = (mask & kindOnly) != 0;



Reproducible: Always
Comment 1 Steven Hung CLA 2011-09-13 17:42:09 EDT
Created attachment 203308 [details]
Patch v1.0

The changes are as Raymond has described in his description.

Testing:
I used a server adapter that supports events for server state, module state, and module status.

A breakpoint was added into org.eclipse.wst.server.core.internal.ServerNotificationManager.broadcastChange(ServerEvent). When the breakpoint is hit, the stack was examined to determine which method had caused the broadcast. 

The broadcast will do a bitwise OR of the type of event and the kind of event. I examine the kind that was used to create the broadcast and compared it to the value of org.eclipse.wst.server.core.internal.ServerNotificationManager.broadcastChange(ServerEvent).kindOnly. 

The correct kind was extracted from the broadcast for :
1. fireModuleStateChangeEvent
2. fireModuleStatusChangeEvent
3. fireServerStateChangeEvent

I also verified that the mask was applied correctly and would return false or true as appropriate.
Comment 2 Elson Yuen CLA 2011-09-14 16:13:37 EDT
Changes looks good and the test looks sufficient.  Code released to 32M and HEAD
Comment 3 Elson Yuen CLA 2011-10-05 15:14:30 EDT
Code released to 32M
Comment 4 Eclipse Genie CLA 2017-10-11 16:37:15 EDT
New Gerrit change created: https://git.eclipse.org/r/109071