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
- Start Liferay and go to Control Panel > Server Administration > Script
- 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)).
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.