Program: 185171
Project: 185171
Buggy source:
private void addWindowListenerToHousing(){
  this.addWindowListener(new WindowAdapter(){
    public void windowClosing(    WindowEvent e){
      if (UserEnvironmentRegistry.getHousingCount() == 1) {
        Object[] options={"String_Node_Str","String_Node_Str"};
        String message="String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str";
        int answer=OptionBox.showOptionDialog(MCTStandardHousing.this,message,"String_Node_Str",OptionBox.YES_NO_OPTION,OptionBox.WARNING_MESSAGE,null,options,options[0]);
switch (answer) {
case OptionBox.YES_OPTION:
          OSGIRuntime osgiRuntime=EquinoxOSGIRuntimeImpl.getOSGIRuntime();
        try {
          osgiRuntime.stopOSGI();
        }
 catch (        Exception e1) {
          LoggerFactory.getLogger(MCTStandardHousing.class).warn(e1.getMessage(),e1);
        }
      disposeHousing();
    System.exit(0);
  break;
default :
break;
}
}
 else {
boolean toCloseWindow=true;
MCTContentArea centerPane=housingViewManifestation.getContentArea();
if (centerPane != null) {
View centerPaneView=centerPane.getHousedViewManifestation();
AbstractComponent centerComponent=centerPaneView.getManifestedComponent();
if (!centerComponent.isStale() && centerComponent.isDirty()) {
toCloseWindow=commitOrAbortPendingChanges(centerPaneView,MessageFormat.format(BUNDLE.getString("String_Node_Str"),centerPaneView.getInfo().getViewName(),centerComponent.getDisplayName()));
}
}
View inspectionArea=housingViewManifestation.getInspectionArea();
if (inspectionArea != null) {
View inspectorPaneView=inspectionArea.getHousedViewManifestation();
AbstractComponent inspectorComponent=inspectorPaneView.getManifestedComponent();
if (!inspectorComponent.isStale() && inspectorComponent.isDirty()) {
toCloseWindow=commitOrAbortPendingChanges(inspectionArea,MessageFormat.format(BUNDLE.getString("String_Node_Str"),inspectorPaneView.getInfo().getViewName(),inspectorComponent.getDisplayName()));
}
}
if (toCloseWindow) disposeHousing();
}
}
/** 
 * Prompts users to commit or abort pending changes in view.
 * @param view the modified view
 * @param dialogMessage the dialog message which differs from where the view is located (in the center or inspector pane)
 * @return true to keep the window open, false to close the window
 */
private boolean commitOrAbortPendingChanges(View view,String dialogMessage){
if (!isComponentWriteableByUser(view.getManifestedComponent())) return true;
Object[] options={BUNDLE.getString("String_Node_Str"),BUNDLE.getString("String_Node_Str"),BUNDLE.getString("String_Node_Str")};
int answer=OptionBox.showOptionDialog(view,dialogMessage,BUNDLE.getString("String_Node_Str"),OptionBox.YES_NO_CANCEL_OPTION,OptionBox.WARNING_MESSAGE,null,options,options[0]);
switch (answer) {
case OptionBox.CANCEL_OPTION:
return false;
case OptionBox.YES_OPTION:
PlatformAccess.getPlatform().getPersistenceProvider().persist(Collections.singleton(view.getManifestedComponent()));
default :
return true;
}
}
private boolean isComponentWriteableByUser(AbstractComponent component){
Platform p=PlatformAccess.getPlatform();
PolicyContext policyContext=new PolicyContext();
policyContext.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(),component);
policyContext.setProperty(PolicyContext.PropertyName.ACTION.getName(),'w');
String inspectionKey=PolicyInfo.CategoryType.OBJECT_INSPECTION_POLICY_CATEGORY.getKey();
return p.getPolicyManager().execute(inspectionKey,policyContext).getStatus();
}
}
);
}

Fixed version (ground truth):
private void addWindowListenerToHousing(){
  this.addWindowListener(new WindowAdapter(){
    public void windowClosing(    WindowEvent e){
      if (UserEnvironmentRegistry.getHousingCount() == 1) {
        Object[] options={"String_Node_Str","String_Node_Str"};
        String message="String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str";
        int answer=OptionBox.showOptionDialog(MCTStandardHousing.this,message,"String_Node_Str",OptionBox.YES_NO_OPTION,OptionBox.WARNING_MESSAGE,null,options,options[0]);
switch (answer) {
case OptionBox.YES_OPTION:
          OSGIRuntime osgiRuntime=EquinoxOSGIRuntimeImpl.getOSGIRuntime();
        try {
          osgiRuntime.stopOSGI();
        }
 catch (        Exception e1) {
          LoggerFactory.getLogger(MCTStandardHousing.class).warn(e1.getMessage(),e1);
        }
      disposeHousing();
    System.exit(0);
  break;
default :
break;
}
}
 else {
boolean toCloseWindow=true;
MCTContentArea centerPane=housingViewManifestation.getContentArea();
if (centerPane != null) {
View centerPaneView=centerPane.getHousedViewManifestation();
AbstractComponent centerComponent=centerPaneView.getManifestedComponent();
if (!centerComponent.isStale() && centerComponent.isDirty()) {
toCloseWindow=commitOrAbortPendingChanges(centerPaneView,MessageFormat.format(BUNDLE.getString("String_Node_Str"),centerPaneView.getInfo().getViewName(),centerComponent.getDisplayName()));
}
}
View inspectionArea=housingViewManifestation.getInspectionArea();
if (inspectionArea != null) {
View inspectorPaneView=inspectionArea.getHousedViewManifestation();
AbstractComponent inspectorComponent=inspectorPaneView.getManifestedComponent();
if (!inspectorComponent.isStale() && inspectorComponent.isDirty()) {
toCloseWindow=commitOrAbortPendingChanges(inspectionArea,MessageFormat.format(BUNDLE.getString("String_Node_Str"),inspectorPaneView.getInfo().getViewName(),inspectorComponent.getDisplayName()));
}
}
if (toCloseWindow) disposeHousing();
}
}
/** 
 * Prompts users to commit or abort pending changes in view.
 * @param view the modified view
 * @param dialogMessage the dialog message which differs from where the view is located (in the center or inspector pane)
 * @return true to keep the window open, false to close the window
 */
private boolean commitOrAbortPendingChanges(View view,String dialogMessage){
if (!isComponentWriteableByUser(view.getManifestedComponent())) return true;
Object[] options={BUNDLE.getString("String_Node_Str"),BUNDLE.getString("String_Node_Str"),BUNDLE.getString("String_Node_Str")};
int answer=OptionBox.showOptionDialog(view,dialogMessage,BUNDLE.getString("String_Node_Str"),OptionBox.YES_NO_CANCEL_OPTION,OptionBox.WARNING_MESSAGE,null,options,options[0]);
switch (answer) {
case OptionBox.CANCEL_OPTION:
return false;
case OptionBox.YES_OPTION:
PlatformAccess.getPlatform().getPersistenceProvider().persist(Collections.singleton(view.getManifestedComponent()));
return true;
default :
return true;
}
}
private boolean isComponentWriteableByUser(AbstractComponent component){
Platform p=PlatformAccess.getPlatform();
PolicyContext policyContext=new PolicyContext();
policyContext.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(),component);
policyContext.setProperty(PolicyContext.PropertyName.ACTION.getName(),'w');
String inspectionKey=PolicyInfo.CategoryType.OBJECT_INSPECTION_POLICY_CATEGORY.getKey();
return p.getPolicyManager().execute(inspectionKey,policyContext).getStatus();
}
}
);
}