Legacy Knowledge Base
Published Jul. 2, 2025

A non-friendly error message appears in the logs when trying to create a new user through API with a firstName that is longer than allowed

Written By

Kanchan Bisht

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • Trying to create a new user via API with a longer than allowed firstName produces a non-friendly error message in the logs
  • Reproducing steps

    1. Start Liferay and go to Control Panel > Server Administration > Script
    2. Use the following Groovy script to create a new user via API with a very long firstName (longer than 75 characters).
      import com.liferay.portal.kernel.service.UserLocalServiceUtil;
      import com.liferay.portal.kernel.util.LocaleUtil;
      import com.liferay.portal.kernel.service.ServiceContext;
      import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
      import com.liferay.portal.kernel.model.User;
      
      ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
      long companyId = serviceContext.getCompanyId();
      User defaultUser = UserLocalServiceUtil.getDefaultUser(companyId);
      String firstName = "veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongfirstname";
      
      UserLocalServiceUtil.addUser(defaultUser.getUserId(), companyId, false, "1234", "1234", true, null, "user01@liferay.com", 0, null, LocaleUtil.getDefault(), firstName, null, "user01", -1, -1, true, 1, 1, 1977, "", new long[0], new long[0], new long[0], new long[0], false, serviceContext);
      

      Observed Behavior: There's an error in the log produced by the database indicating that one of the fields is too long for the existing constraint (VARCHAR(75)).59ee08eedfb10267d8a33af543834e7.png

      2021-05-14 10:49:43.044 ERROR [http-nio-8080-exec-4][JDBCExceptionReporter:234] Batch entry 0 insert into User_ (mvccVersion, ctCollectionId, uuid_, externalReferenceCode, companyId, createDate, modifiedDate, defaultUser, contactId, password_, passwordEncrypted, passwordReset, passwordModifiedDate, digest, reminderQueryQuestion, reminderQueryAnswer, graceLoginCount, screenName, emailAddress, facebookId, googleUserId, ldapServerId, openId, portraitId, languageId, timeZoneId, greeting, comments, firstName, middleName, lastName, jobTitle, loginDate, loginIP, lastLoginDate, lastLoginIP, lastFailedLoginDate, failedLoginAttempts, lockout, lockoutDate, agreedToTermsOfUse, emailAddressVerified, status, userId) values (0, 0, '9b91320b-fa07-c0b8-922c-31e573e7c49d', NULL, 20103, '2021-05-14 10:49:43.024+00', '2021-05-14 10:49:43.024+00', 'FALSE', 39458, '{PBKDF2WITHHMACSHA1}AAAAoAAB9ABJkHqzYtguDbRCwEbRsJghz5wgsW5ISD9FE/+l', 'TRUE', 'TRUE', NULL, '9ad14b9978803512de35c5abf7eae246,99d3f5b2f43f6c71b0db76450253223f,2d871374e4c9045618155eaca32c0e75', NULL, NULL, 0, 'user01', 'user01@liferay.com', 0, NULL, -1, NULL, 0, 'en_US', 'UTC', 'Welcome v user01!', NULL, 'veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongfirstname', NULL, 'user01', NULL, NULL, NULL, NULL, NULL, NULL, 0, 'FALSE', NULL, 'FALSE', 'FALSE', 2, 39457) was aborted: ERROR: value too long for type character varying(75)  Call getNextException to see other errors in the batch.
      2021-05-14 10:49:43.046 ERROR [http-nio-8080-exec-4][JDBCExceptionReporter:234] ERROR: value too long for type character varying(75)
      

      Expected Behavior: There's a friendly error message generated by Liferay explaining that the argument firstName is longer than the maximum number of characters allowed.

Environment

  • Liferay DXP 7.0
  • Liferay DXP 7.1
  • Liferay DXP 7.2
  • Liferay DXP 7.3

Resolution

  • This behavior is a known issue and can be tracked here: LPS-132241

Additional Information

  • We have a different channel called "Global Service Team" in case of further assistance regarding Groovy script.
Did this article resolve your issue ?

Legacy Knowledge Base