# Error in method invocation: Method addMessage(java.lang.String) not found in class'java.lang.String'

**URL:** <https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079>\
**Category:** IIQ Discussion and Questions\
**Tags:** rules, identityiq, provisioning\
**Created:** [April 5, 2024, 8:11pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079 "2024-04-05T20:11:49Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![j1241](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@j1241](https://developer.sailpoint.com/discuss/u/j1241)\
**Post date:** [April 5, 2024, 8:11pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/1 "2024-04-05T20:11:49Z")

</div>

Hello,  
I am coming to an error that I could not find a reason. Any suggestion will be helpful.

Error:  
Error in method invocation: Method addMessage(java.lang.String) not found in class’java.lang.String’

Code:

```auto
<Description>
		    Rule 
		</Description>
  <Signature returnType="String">
    <Inputs>
      <Argument name="config">
        <Description>
			  The current user's locale
			</Description>
      </Argument>
      <Argument name="taskResult">
        <Description>
			  The current user's locale
			</Description>
      </Argument>
    </Inputs>
  </Signature>
  <Source>
import sailpoint.object.TaskDefinition;
import sailpoint.object.TaskResult;
import sailpoint.api.TaskManager;
String name ="1234567";
  
  
  if(name != null &amp;&amp; !name.isEmpty())
  {
    
    
    taskResult.addMessage("Identities updated ");
  }
  else
  {
    taskResult.addMessage(" No Identities ");
  }

  return taskResult;
</Source>

```

---

<div class="post-metadata">

**Author:** ![ipobeidi](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/ipobeidi/32/16000_2.png) [@ipobeidi](https://developer.sailpoint.com/discuss/u/ipobeidi)\
**Post date:** [April 5, 2024, 9:28pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/2 "2024-04-05T21:28:13Z")

</div>

The TaskResult variable is a String?

you’re doing it in a RuleTask? What you trying to do?

best!

---

<div class="post-metadata">

**Author:** ![kjakubiak](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/kjakubiak/32/7052_2.png) [@kjakubiak](https://developer.sailpoint.com/discuss/u/kjakubiak)\
**Post date:** [April 6, 2024, 11:43am UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/3 "2024-04-06T11:43:03Z")

</div>

> [@j1241](#):
>
> ```auto
> <Signature returnType="String">
> 
> ```

I believe this line is causing problems - I would suggest to remove temporarly whole signature as it’s not needed really. Try to remove it and chekc if it works

---

<div class="post-metadata">

**Author:** ![j1241](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@j1241](https://developer.sailpoint.com/discuss/u/j1241)\
**Post date:** [April 8, 2024, 12:35pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/4 "2024-04-08T12:35:16Z")

</div>

Hello @ipobeidi I am trying to run a Rule through a task but this is where it throwing error.  
This is only mimicking the code.

---

<div class="post-metadata">

**Author:** ![iamksatish](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/iamksatish/32/26217_2.png) [@iamksatish](https://developer.sailpoint.com/discuss/u/iamksatish)\
**Post date:** [April 8, 2024, 12:51pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/5 "2024-04-08T12:51:28Z")

</div>

Did you try removing the signature as @kjakubiak mentioned and tried?

---

<div class="post-metadata">

**Author:** ![j1241](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@j1241](https://developer.sailpoint.com/discuss/u/j1241)\
**Post date:** [April 8, 2024, 12:59pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/7 "2024-04-08T12:59:55Z")

</div>

Hello @iamksatish I tried @kjakubiak recommendation but system throws error.

```auto
 <Description>
    Rule 
  </Description>    
  <Inputs>
    <Argument name="config">
      <Description>
        The current user's locale
      </Description>
    </Argument>
    <Argument name="taskResult">
      <Description>
        The current user's locale
      </Description>
    </Argument>
  </Inputs>   
  <Source>

```

---

<div class="post-metadata">

**Author:** ![ipobeidi](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/ipobeidi/32/16000_2.png) [@ipobeidi](https://developer.sailpoint.com/discuss/u/ipobeidi)\
**Post date:** [April 8, 2024, 1:01pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/8 "2024-04-08T13:01:18Z")

</div>

You dont need to have the taskResult as a variable. It will be on the context to be captured and updated.  
Just remove the TaskResult from the input an try to add the massage.

Put back the Signature.

best!

---

<div class="post-metadata">

**Author:** ![iamksatish](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/iamksatish/32/26217_2.png) [@iamksatish](https://developer.sailpoint.com/discuss/u/iamksatish)\
**Post date:** [April 8, 2024, 3:39pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/9 "2024-04-08T15:39:48Z")

</div>

Please try removing the Signature completely along with Inputs, you dont need this specifically.

---

<div class="post-metadata">

**Author:** ![patrickboston](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/patrickboston/32/5876_2.png) [@patrickboston](https://developer.sailpoint.com/discuss/u/patrickboston)\
**Post date:** [April 8, 2024, 4:56pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/10 "2024-04-08T16:56:28Z")

</div>

The signature doesn’t really matter at all. It’s purely informational to let you know what is being passed into the Beanshell namespace. As @ipobeidi mentioned originally, the error indicates that the `taskResult` variable is of type `String` which doesn’t have a method for `addMessage(String)`. This method is only applicable for a `sailpoint.object.TaskResult` object, in which case the `taskResult` variable passed into a Rule Runner task _should_ be of that type, but it seems like you are not maybe running this rule properly via a Rule Runner task, or you are somehow re-declaring it as a String?

---

<div class="post-metadata">

**Author:** ![vishal\_kejriwal1](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/vishal_kejriwal1/32/10904_2.png) [@vishal\_kejriwal1](https://developer.sailpoint.com/discuss/u/vishal_kejriwal1)\
**Post date:** [April 8, 2024, 5:18pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/11 "2024-04-08T17:18:47Z")

</div>

Try below

```auto
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule language="beanshell" name="Vishal User">
  <Description>A rule to disable a user.</Description>
  <Signature returnType="SailPointObject">
    <Inputs>
      <Argument name="log">
        <Description>
          The log object associated with the SailPointContext.
        </Description>
      </Argument>
      <Argument name="context">
        <Description>
          A sailpoint.api.SailPointContext object that can be used to query the database if necessary.
        </Description>
      </Argument>
      <Argument name="taskResult">
        <Description>
          A sailpoint.object.TaskResult object that can be used to set messages and responses for the task result.
        </Description>
      </Argument>
    </Inputs>
    <Returns>
      <Argument name="taskSuccess" type="string">
        <Prompt>Task Result:</Prompt>
      </Argument>
    </Returns>
  </Signature>
  <Source>
        import sailpoint.object.Identity;
        import sailpoint.tools.Message;
        import org.apache.log4j.Logger;
        import sailpoint.api.ObjectUtil;
        import sailpoint.api.PersistenceManager;
        
    		String name ="1234567";
    
      	if(name != null &amp;&amp; !name.isEmpty()){   
    		            taskResult.addMessage(new Message(Message.Type.Info, "Identities updated",null));
  			}else{
    		            taskResult.addMessage(new Message(Message.Type.Info, "No Identities",null));
  			}
    return "Success";
  </Source>
</Rule>

```

```auto
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE TaskDefinition PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<TaskDefinition name="Vishal User" resultAction="Rename" subType="task_item_type_generic" type="Generic">
  <Attributes>
    <Map>
      <entry key="TaskDefinition.runLengthAverage" value="0"/>
      <entry key="TaskDefinition.runLengthTotal" value="0"/>
      <entry key="TaskDefinition.runs" value="0"/>
      <entry key="TaskSchedule.host"/>
      <entry key="ruleName" value="Vishal User"/>
      <entry key="taskCompletionEmailNotify" value="Disabled"/>
      <entry key="taskCompletionEmailRecipients"/>
      <entry key="taskCompletionEmailTemplate" value="Task Status"/>
    </Map>
  </Attributes>
  <Description>A task that can be used to run an arbitrary rule.</Description>
  <Parent>
    <Reference class="sailpoint.object.TaskDefinition" name="Run Rule"/>
  </Parent>
</TaskDefinition>

```

 ![image](https://global.discourse-cdn.com/sailpoint/original/2X/5/527ce8203f1be46e64525d437ebdda480ca6853a.png)

---

<div class="post-metadata">

**Author:** ![j1241](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@j1241](https://developer.sailpoint.com/discuss/u/j1241)\
**Post date:** [April 8, 2024, 6:05pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/12 "2024-04-08T18:05:09Z")

</div>

@vishal_kejriwal1 Thank you very much for you solution. I will try and get back to you.

---

<div class="post-metadata">

**Author:** ![j1241](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@j1241](https://developer.sailpoint.com/discuss/u/j1241)\
**Post date:** [April 9, 2024, 3:02pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/13 "2024-04-09T15:02:51Z")

</div>

Thank you Vishal. Your code fixed my issue. I really appreciate your help.

---

<div class="post-metadata">

**Author:** ![vishal\_kejriwal1](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/vishal_kejriwal1/32/10904_2.png) [@vishal\_kejriwal1](https://developer.sailpoint.com/discuss/u/vishal_kejriwal1)\
**Post date:** [April 9, 2024, 3:39pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/14 "2024-04-09T15:39:02Z")

</div>

Awesome @j1241 ! Happy Learning !!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [June 8, 2024, 3:39pm UTC](https://developer.sailpoint.com/discuss/t/error-in-method-invocation-method-addmessage-java-lang-string-not-found-in-classjava-lang-string/40079/15 "2024-06-08T15:39:55Z")

</div>

Closed on June 8, 2024, 3:39pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
