Uploaded image for project: 'OpenOLAT'
  1. OpenOLAT
  2. OO-3530

Folder node: NPE occurs when renaming a linked folder from course folder

    XMLWordPrintable

    Details

      Description

      The steps to reproduce the NPE:

      Create a folder node and choose a folder from course folder. Publish the course. Then rename the origin from course folder. After that the course is not usable any more. A lion occurs with a meaningless NullPointerException.

      Only the preceeding warning points to the real cause:

      stack of 1.cause::java.lang.NullPointerException: null ->  at org.olat.course.MergedCourseContainer.getBCContainer(MergedCourseContainer.java:363) at org.olat.course.MergedCourseContainer.addFoldersForAdmin(MergedCourseContainer.java:276)

      I fixed that by checking for (rootFolder != null). To inform the author abaout the fault, I suggest to display a warning message in course editor.

      This is the patch:

      diff --git a/src/main/java/org/olat/course/MergedCourseContainer.java b/src/main/java/org/olat/course/MergedCourseContainer.java
      --- a/src/main/java/org/olat/course/MergedCourseContainer.java
      +++ b/src/main/java/org/olat/course/MergedCourseContainer.java
      @@ -360,7 +360,7 @@
       			} else {
       				VFSContainer courseBase = course.getCourseBaseContainer();
       				rootFolder = (VFSContainer) courseBase.resolve("/coursefolder" + subpath);
      -				if(rootFolder.getLocalSecurityCallback() != null) {
      +				if((rootFolder != null) && rootFolder.getLocalSecurityCallback() != null) {
       					SubscriptionContext subContext = CourseModule.createSubscriptionContext(course.getCourseEnvironment(), bcNode);
       					rootFolder.setLocalSecurityCallback(new OverrideSubscriptionSecurityCallback(rootFolder.getLocalSecurityCallback(), subContext));
       				}
      diff --git a/src/main/java/org/olat/course/nodes/bc/BCCourseNodeEditForm.java b/src/main/java/org/olat/course/nodes/bc/BCCourseNodeEditForm.java
      --- a/src/main/java/org/olat/course/nodes/bc/BCCourseNodeEditForm.java
      +++ b/src/main/java/org/olat/course/nodes/bc/BCCourseNodeEditForm.java
      @@ -66,6 +66,7 @@
       	private FormLink createFolder;
       	private BCCourseNodeEditCreateFolderForm createFolderForm;
       	private FormItem sharedFolderWarning, sharedFolderInfo;
      +	private FormItem linkedFolderWarning;
       	private BCCourseNodeEditChooseFolderForm chooseForm;
       
       	public BCCourseNodeEditForm(UserRequest ureq, WindowControl wControl, BCCourseNode bcNode, ICourse course) {
      @@ -89,12 +90,16 @@
       		sharedFolderWarning = uifactory.createSimpleErrorText("warning", translate("warning.no.sharedfolder"));
       		formLayout.add(sharedFolderWarning);
       
      +		linkedFolderWarning = uifactory.createSimpleErrorText("warning2", translate("warning.no.linkedfolder"));
      +		formLayout.add(linkedFolderWarning);
      +
       		boolean isAuto = node.getModuleConfiguration().getBooleanSafe(BCCourseNodeEditController.CONFIG_AUTO_FOLDER);
       
       		if(isAuto){
       			folderTargetChoose.select("autoPath", true);
       			subPath.setVisible(false);
       			sharedFolderWarning.setVisible(false);
      +			linkedFolderWarning.setVisible(false);
       		}else{
       			folderTargetChoose.select("pathChoose", false);
       			String subpath = node.getModuleConfiguration().getStringValue(BCCourseNodeEditController.CONFIG_SUBPATH);
      @@ -110,6 +115,12 @@
       				sharedFolderWarning.setVisible(false);
       			}
       
      +			if(isLinkedFolderNotPresent()){
      +				linkedFolderWarning.setVisible(true);
      +			}else{
      +				linkedFolderWarning.setVisible(false);
      +			}
      +
       
       		}
       		if(node.isSharedFolder()) {
      @@ -137,6 +148,7 @@
       	protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
       		if(folderTargetChoose.isSelected(0)){
       			sharedFolderWarning.setVisible(false);
      +			linkedFolderWarning.setVisible(false);
       		}else{
       			if(isSharedfolderNotPresent()){
       				sharedFolderWarning.setVisible(true);
      @@ -148,6 +160,11 @@
       			}else{
       				sharedFolderInfo.setVisible(false);
       			}
      +			if(isLinkedFolderNotPresent()){
      +				linkedFolderWarning.setVisible(true);
      +			}else{
      +				linkedFolderWarning.setVisible(false);
      +			}
       		}
       		if(source == folderTargetChoose){
       			subPath.setVisible(folderTargetChoose.isSelected(1));
      @@ -276,4 +293,10 @@
       		return false;
       	}
       
      +	private boolean isLinkedFolderNotPresent(){
      +		VFSContainer courseBase = course.getCourseBaseContainer();
      +		String subpath = node.getModuleConfiguration().getStringValue(BCCourseNodeEditController.CONFIG_SUBPATH);
      +		VFSContainer rootFolder = (VFSContainer) courseBase.resolve("/coursefolder" + subpath);
      +		return rootFolder == null;
      +	}
       }
      diff --git a/src/main/java/org/olat/course/nodes/bc/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/course/nodes/bc/_i18n/LocalStrings_de.properties
      --- a/src/main/java/org/olat/course/nodes/bc/_i18n/LocalStrings_de.properties
      +++ b/src/main/java/org/olat/course/nodes/bc/_i18n/LocalStrings_de.properties
      @@ -31,6 +31,7 @@
       createButton=Ordner erstellen
       warning.no.sharedfolder=Der konfigurierte Ressourcenordner ist nicht mehr verf\u00FCgbar
       info.sharedfolder=F\u00fcr den Ressourcenordner erhalten Kursmitglieder im Kurs nur Leserechte.
      +warning.no.linkedfolder=Der angegebene Ordner existiert nicht im Ablageordner.
       chooseFolder=Ordner w\u00E4hlen
       #	<VCRP-POD>
       pod.enable=Print On Demand erm\u00F6glichen
      
      

        Attachments

          Activity

            People

            • Assignee:
              srosse Stéphane Rossé
              Reporter:
              stephan Stephan Clemenz
              Tester:
              Mandy Menzel
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 35 minutes
                35m