Program: 69578
Project: 69578
Buggy source:
/** 
 * Initializes the course tools according to the users rights (repository author group and course rights in course groupmanagement)
 * @param identity
 * @param ureq
 * @param ureq
 * @return ToolController
 */
private ToolController initToolController(Identity identity,UserRequest ureq){
  ToolController myTool=ToolFactory.createToolController(getWindowControl());
  CourseConfig cc=uce.getCourseEnvironment().getCourseConfig();
  if (isCourseAdmin || isCourseCoach || hasCourseRight(CourseRights.RIGHT_COURSEEDITOR)|| hasCourseRight(CourseRights.RIGHT_GROUPMANAGEMENT)|| hasCourseRight(CourseRights.RIGHT_ARCHIVING)|| hasCourseRight(CourseRights.RIGHT_STATISTICS)|| hasCourseRight(CourseRights.RIGHT_DB)|| hasCourseRight(CourseRights.RIGHT_ASSESSMENT)) {
    myTool.addHeader(translate("String_Node_Str"));
    if (hasCourseRight(CourseRights.RIGHT_COURSEEDITOR) || isCourseAdmin) {
      boolean managed=RepositoryEntryManagedFlag.isManaged(courseRepositoryEntry,RepositoryEntryManagedFlag.editcontent);
      myTool.addLink(COMMAND_EDIT,translate("String_Node_Str"),"String_Node_Str",null,"String_Node_Str",false);
      myTool.setEnabled("String_Node_Str",!managed);
    }
    if (hasCourseRight(CourseRights.RIGHT_GROUPMANAGEMENT) || isCourseAdmin) {
      myTool.addLink("String_Node_Str",translate("String_Node_Str"),null,null,"String_Node_Str",false);
    }
    if (hasCourseRight(CourseRights.RIGHT_ARCHIVING) || isCourseAdmin) {
      myTool.addLink("String_Node_Str",translate("String_Node_Str"));
    }
    if (hasCourseRight(CourseRights.RIGHT_ASSESSMENT) || isCourseCoach || isCourseAdmin) {
      myTool.addLink("String_Node_Str",translate("String_Node_Str"));
    }
    if (hasCourseRight(CourseRights.RIGHT_STATISTICS) || isCourseAdmin || isCourseCoach) {
      final AtomicInteger testNodes=new AtomicInteger();
      final AtomicInteger surveyNodes=new AtomicInteger();
      new TreeVisitor(new Visitor(){
        @Override public void visit(        INode node){
          if (((CourseNode)node).isStatisticNodeResultAvailable(uce,QTIType.test,QTIType.onyx)) {
            testNodes.incrementAndGet();
          }
 else           if (((CourseNode)node).isStatisticNodeResultAvailable(uce,QTIType.survey)) {
            surveyNodes.incrementAndGet();
          }
        }
      }
,course.getRunStructure().getRootNode(),true).visitAll();
      if (testNodes.intValue() > 0) {
        myTool.addLink("String_Node_Str",translate("String_Node_Str"));
      }
      if (surveyNodes.intValue() > 0) {
        myTool.addLink("String_Node_Str",translate("String_Node_Str"));
      }
    }
    if (hasCourseRight(CourseRights.RIGHT_STATISTICS) || isCourseAdmin) {
      myTool.addLink("String_Node_Str",translate("String_Node_Str"));
    }
    if (CourseDBManager.getInstance().isEnabled() && (hasCourseRight(CourseRights.RIGHT_DB) || isCourseAdmin)) {
      myTool.addLink("String_Node_Str",translate("String_Node_Str"));
    }
  }
  if (uce.getCoachedGroups().size() > 0) {
    myTool.addHeader(translate("String_Node_Str"));
    for (    BusinessGroup group : uce.getCoachedGroups()) {
      myTool.addLink(CMD_START_GROUP_PREFIX + group.getKey().toString(),StringHelper.escapeHtml(group.getName()));
    }
  }
  if (uce.getParticipatingGroups().size() > 0) {
    myTool.addHeader(translate("String_Node_Str"));
    for (    BusinessGroup group : uce.getParticipatingGroups()) {
      myTool.addLink(CMD_START_GROUP_PREFIX + group.getKey().toString(),group.getName());
    }
  }
  if (uce.getWaitingLists().size() > 0) {
    myTool.addHeader(translate("String_Node_Str"));
    for (    BusinessGroup group : uce.getWaitingLists()) {
      int pos=businessGroupService.getPositionInWaitingListFor(identity,group);
      myTool.addLink(CMD_START_GROUP_PREFIX + group.getKey().toString(),group.getName() + "String_Node_Str" + pos+ "String_Node_Str",group.getKey().toString(),null);
      myTool.setEnabled(group.getKey().toString(),false);
    }
  }
  myTool.addHeader(translate("String_Node_Str"));
  if (cc.isCalendarEnabled() && !isGuest) {
    myTool.addPopUpLink(ACTION_CALENDAR,translate("String_Node_Str"),null,null,"String_Node_Str","String_Node_Str",false);
  }
  if (cc.hasGlossary()) {
    myTool.addComponent(glossaryToolCtr.getInitialComponent());
  }
  if (showCourseConfigLink) {
    ChiefController chief=(ChiefController)Windows.getWindows(ureq).getAttribute("String_Node_Str");
    if (chief != null && chief.hasStaticSite(RepositorySite.class)) {
      myTool.addLink(TOOLBOX_LINK_COURSECONFIG,translate("String_Node_Str"));
    }
  }
  if (!isGuest) {
    myTool.addPopUpLink("String_Node_Str",translate("String_Node_Str"),null,null,"String_Node_Str","String_Node_Str",false);
  }
  if (offerBookmark && !isGuest) {
    boolean marked=markManager.isMarked(courseRepositoryEntry,getIdentity(),null);
    String css=marked ? "String_Node_Str" : "String_Node_Str";
    myTool.addLink(ACTION_BOOKMARK,translate("String_Node_Str"),TOOL_BOOKMARK,css);
  }
  if (cc.isEfficencyStatementEnabled() && course.hasAssessableNodes() && !isGuest) {
    myTool.addPopUpLink("String_Node_Str",translate("String_Node_Str"),"String_Node_Str",null,"String_Node_Str","String_Node_Str",false);
    UserEfficiencyStatement es=efficiencyStatementManager.getUserEfficiencyStatementLight(courseRepositoryEntry.getKey(),identity);
    if (es == null) {
      myTool.setEnabled("String_Node_Str",false);
    }
  }
  InstantMessagingModule imModule=CoreSpringFactory.getImpl(InstantMessagingModule.class);
  boolean chatIsEnabled=!isGuest && imModule.isEnabled() && imModule.isCourseEnabled()&& CourseModule.isCourseChatEnabled()&& cc.isChatEnabled();
  if (chatIsEnabled) {
    myTool.addLink(ACTION_CHAT,translate("String_Node_Str"),TOOL_CHAT,null);
  }
  if (CourseModule.displayParticipantsCount() && !isGuest) {
    addCurrentUserCount(myTool);
  }
  return myTool;
}

Fixed version (ground truth):
/** 
 * Initializes the course tools according to the users rights (repository author group and course rights in course groupmanagement)
 * @param identity
 * @param ureq
 * @param ureq
 * @return ToolController
 */
private ToolController initToolController(Identity identity,UserRequest ureq){
  ToolController myTool=ToolFactory.createToolController(getWindowControl());
  CourseConfig cc=uce.getCourseEnvironment().getCourseConfig();
  if (isCourseAdmin || isCourseCoach || hasCourseRight(CourseRights.RIGHT_COURSEEDITOR)|| hasCourseRight(CourseRights.RIGHT_GROUPMANAGEMENT)|| hasCourseRight(CourseRights.RIGHT_ARCHIVING)|| hasCourseRight(CourseRights.RIGHT_STATISTICS)|| hasCourseRight(CourseRights.RIGHT_DB)|| hasCourseRight(CourseRights.RIGHT_ASSESSMENT)) {
    myTool.addHeader(translate("String_Node_Str"));
    if (hasCourseRight(CourseRights.RIGHT_COURSEEDITOR) || isCourseAdmin) {
      boolean managed=RepositoryEntryManagedFlag.isManaged(courseRepositoryEntry,RepositoryEntryManagedFlag.editcontent);
      myTool.addLink(COMMAND_EDIT,translate("String_Node_Str"),"String_Node_Str",null,"String_Node_Str",false);
      myTool.setEnabled("String_Node_Str",!managed);
    }
    if (hasCourseRight(CourseRights.RIGHT_GROUPMANAGEMENT) || isCourseAdmin) {
      myTool.addLink("String_Node_Str",translate("String_Node_Str"),null,null,"String_Node_Str",false);
    }
    if (hasCourseRight(CourseRights.RIGHT_ARCHIVING) || isCourseAdmin) {
      myTool.addLink("String_Node_Str",translate("String_Node_Str"));
    }
    if (hasCourseRight(CourseRights.RIGHT_ASSESSMENT) || isCourseCoach || isCourseAdmin) {
      myTool.addLink("String_Node_Str",translate("String_Node_Str"));
    }
    if (hasCourseRight(CourseRights.RIGHT_STATISTICS) || isCourseAdmin || isCourseCoach) {
      final AtomicInteger testNodes=new AtomicInteger();
      final AtomicInteger surveyNodes=new AtomicInteger();
      new TreeVisitor(new Visitor(){
        @Override public void visit(        INode node){
          if (((CourseNode)node).isStatisticNodeResultAvailable(uce,QTIType.test,QTIType.onyx)) {
            testNodes.incrementAndGet();
          }
 else           if (((CourseNode)node).isStatisticNodeResultAvailable(uce,QTIType.survey)) {
            surveyNodes.incrementAndGet();
          }
        }
      }
,course.getRunStructure().getRootNode(),true).visitAll();
      if (testNodes.intValue() > 0) {
        myTool.addLink("String_Node_Str",translate("String_Node_Str"));
      }
      if (surveyNodes.intValue() > 0) {
        myTool.addLink("String_Node_Str",translate("String_Node_Str"));
      }
    }
    if (hasCourseRight(CourseRights.RIGHT_STATISTICS) || isCourseAdmin) {
      myTool.addLink("String_Node_Str",translate("String_Node_Str"));
    }
    if (CourseDBManager.getInstance().isEnabled() && (hasCourseRight(CourseRights.RIGHT_DB) || isCourseAdmin)) {
      myTool.addLink("String_Node_Str",translate("String_Node_Str"));
    }
  }
  if (uce.getCoachedGroups().size() > 0) {
    myTool.addHeader(translate("String_Node_Str"));
    for (    BusinessGroup group : uce.getCoachedGroups()) {
      myTool.addLink(CMD_START_GROUP_PREFIX + group.getKey().toString(),StringHelper.escapeHtml(group.getName()));
    }
  }
  if (uce.getParticipatingGroups().size() > 0) {
    myTool.addHeader(translate("String_Node_Str"));
    for (    BusinessGroup group : uce.getParticipatingGroups()) {
      myTool.addLink(CMD_START_GROUP_PREFIX + group.getKey().toString(),group.getName());
    }
  }
  if (uce.getWaitingLists().size() > 0) {
    myTool.addHeader(translate("String_Node_Str"));
    for (    BusinessGroup group : uce.getWaitingLists()) {
      int pos=businessGroupService.getPositionInWaitingListFor(identity,group);
      myTool.addLink(CMD_START_GROUP_PREFIX + group.getKey().toString(),group.getName() + "String_Node_Str" + pos+ "String_Node_Str",group.getKey().toString(),null);
      myTool.setEnabled(group.getKey().toString(),false);
    }
  }
  myTool.addHeader(translate("String_Node_Str"));
  if (cc.isCalendarEnabled() && !isGuest) {
    myTool.addPopUpLink(ACTION_CALENDAR,translate("String_Node_Str"),null,null,"String_Node_Str","String_Node_Str",false);
  }
  if (cc.hasGlossary()) {
    myTool.addComponent(glossaryToolCtr.getInitialComponent());
  }
  if (showCourseConfigLink) {
    ChiefController chief=(ChiefController)Windows.getWindows(ureq).getAttribute("String_Node_Str");
    if (chief == null || chief.hasStaticSite(RepositorySite.class)) {
      myTool.addLink(TOOLBOX_LINK_COURSECONFIG,translate("String_Node_Str"));
    }
  }
  if (!isGuest) {
    myTool.addPopUpLink("String_Node_Str",translate("String_Node_Str"),null,null,"String_Node_Str","String_Node_Str",false);
  }
  if (offerBookmark && !isGuest) {
    boolean marked=markManager.isMarked(courseRepositoryEntry,getIdentity(),null);
    String css=marked ? "String_Node_Str" : "String_Node_Str";
    myTool.addLink(ACTION_BOOKMARK,translate("String_Node_Str"),TOOL_BOOKMARK,css);
  }
  if (cc.isEfficencyStatementEnabled() && course.hasAssessableNodes() && !isGuest) {
    myTool.addPopUpLink("String_Node_Str",translate("String_Node_Str"),"String_Node_Str",null,"String_Node_Str","String_Node_Str",false);
    UserEfficiencyStatement es=efficiencyStatementManager.getUserEfficiencyStatementLight(courseRepositoryEntry.getKey(),identity);
    if (es == null) {
      myTool.setEnabled("String_Node_Str",false);
    }
  }
  InstantMessagingModule imModule=CoreSpringFactory.getImpl(InstantMessagingModule.class);
  boolean chatIsEnabled=!isGuest && imModule.isEnabled() && imModule.isCourseEnabled()&& CourseModule.isCourseChatEnabled()&& cc.isChatEnabled();
  if (chatIsEnabled) {
    myTool.addLink(ACTION_CHAT,translate("String_Node_Str"),TOOL_CHAT,null);
  }
  if (CourseModule.displayParticipantsCount() && !isGuest) {
    addCurrentUserCount(myTool);
  }
  return myTool;
}