Integration News

Troubleshooting: Sterling Map with replaceAll user exit gives a java.lang.NoSuchMethod exception

Problem

When running a map that has a user exit rule with a replaceAll function, the translator issues this error message:
java.lang.NoSuchMethodException: java.lang.NoSuchMethodException: java.lang.String.<init>(null)

 

Cause

The data that was used for the replaceALL function was empty.

The characters after the 1803 above refer to the element TDLINE in the map, which is this case is empty.
The translator report shows that in Block 26, which is the example data line above, so we know this is the data used which caused the error:

Section: INPUT       Severity: ERROR
       SyntaxSpecific: false       Syntax: -1        Code: 170 Extended Rule Error
       Info:
              10002: Block Count
              26

Diagnosing The Problem

If you search for the error message, this is what was returned:
The error message java.lang.NoSuchMethodException: java.lang.String.<init>(null) indicates that you’re trying to create a String object using a constructor that takes a null argument, but such a constructor doesn’t exist.
Here’s why this might be happening and how to fix it:

Common Causes:

      • Passingnull to a String constructor: You might be explicitly passing null as an argument to a String
      • Indirectnull argument: A variable you’re using to create the String might be 

How to Fix:

      • Check for null:
      • Before creating the String object, check if the variable you’re using is null.
      • Handle null values:
      • If the variable is null, you can either:
          • Use a default value: Assign a default value (e.g., an empty string) if the variable is 
          • Throw an exception:If the variable should never be null, throw an exception to handle the error condition.

Resolving The Problem

As stated in the Diagnose section, we will  have to check before creating the String object that the variable we’re using is null.
We will then need to change the extended rule as follows,

object ob;
If exist(#TDLINE) then
 Begin
  ob= new(«java.lang.String»,#TDLINE);
  #TDLINE = ob.replaceALL(«[^^A-Za-z0-9\\s]» , » «);
 End

This link shows more about using the replaceALL function: 
Replacing-characters-string-value-replaceall-javalangstring-user-exit

Click the button below to download this newsletter in PDF format.

home.b2b.solutions
Privacy Overview

This website uses cookies so that we can offer you the best possible user experience.
Cookie information is stored in your browser and performs functions such as recognizing you when you return to our website or helping our team understand which sections of the website you find most interesting and useful.