title: Why I always got the Unexpected global error from drools?
body: <p>When I fire the rules I got a strange error.<br>
  The error details are </p>
  
  <pre><code>java.lang.RuntimeException: Unexpected global [validateResult]
      at org.drools.core.impl.StatefulKnowledgeSessionImpl.setGlobal(StatefulKnowledgeSessionImpl.java:1209)
      at com.hikedu.backend.service.impl.signupproject.SignUpProjectServiceImpl.validate(SignUpProjectServiceImpl.java:190)
      at com.hikedu.backend.service.impl.signupproject.SignUpProjectServiceImpl.validate(SignUpProjectServiceImpl.java:204)
      at com.hikedu.backend.service.impl.signupproject.SignUpProjectServiceImpl.signUp(SignUpProjectServiceImpl.java:102)
      at com.hikedu.backend.controller.ProjectApplicationRecordController.signUp(ProjectApplicationRecordController.java:94)
      at com.hikedu.backend.controller.ProjectApplicationRecordController$$FastClassBySpringCGLIB$$dc339407.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
  </code></pre>
  
  <p>Here is my code to fire the rules</p>
  
  <pre><code>    KieSession session = sessionBuilder.build(theDsl);
      ProjectVersion latestVersion = projectVersionService.getLatestVersionIfNotExistsThenThrowException(projectId);
      User user = userService.getUserIfNotExistsThenThrowException(userId);
      ApplicationInfo info = getTheInsertObj(userId, projectId);
      ProjectSignUpValidateResultDTO resultDTO = new ProjectSignUpValidateResultDTO();
      resultDTO.setPass(true);
      session.setGlobal("validateResult", resultDTO);
      session.insert(latestVersion);
      session.insert(info);
      session.insert(user);
      session.fireAllRules(1);
      session.dispose();
  
      return resultDTO;
  </code></pre>
  
  <p>I searched a lot about this error. The answers all talking the same thing--The dsl file must declar the global and the declar name and path must be euqal to the code given
  But I confirmd again and again my dsl and my code there is not  found any mistaken.  </p>
  
  <p>I tried to change the global name to nother one but still get that error.</p>
  
  <p>So please help me.</p>
  
  <p>Here is my dsl</p>
  
  <pre><code>import com.hikedu.backend.model.User;
  import com.hikedu.backend.model.ProjectVersion;
  import java.util.Map;
  import com.hikedu.backend.dto.signupproject.ApplicationInfo
  import java.util.Date
  import java.sql.Timestamp
  
  global com.hikedu.backend.dto.project.ProjectSignUpValidateResultDTO validateResult
  
  rule "department not match"
  no-loop
  when
      $p : ProjectVersion()
      $u : User($p.applicationRequirements.departmentId not contains departmentOfJoined.id)
  then
      validateResult.setPass(false);
      validateResult.setTheReasonOfUnPass("some reason");
  end
  </code></pre>
  
  <p>And I did the debug to check the globals of the session. Here is the debug result 
  <a href="https://i.stack.imgur.com/xpxyj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xpxyj.png" alt="enter image description here"></a></p>
  
  <p>The drools version I am using is 
  <a href="https://i.stack.imgur.com/n8ExB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n8ExB.png" alt="enter image description here"></a></p>
  
  <p>Here is the KieSessionBuilder.build method </p>
  
  <pre><code>@Override
      public KieSession build(String dsl) {
          if (dsl == null) {
              throw new RuntimeException("Dsl cannot be null");
          }
          KieHelper helper = new KieHelper();
          helper.setClassLoader(getClass().getClassLoader());
          helper.addContent(dsl, ResourceType.DSL);
          KieBase base = helper.build();
          return base.newKieSession();
      }
  </code></pre>
  
  <p>Thanks you all. My english dost not good well please forgive me.</p>