Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-64331

StringUtil.randomId() sometimes generates the same name for the structure's option type elements in the same structure

    Details

      Description

      In 6.1 the the journalstructure looked like this (with select element):

       	<dynamic-element name="leftHeadingColor" type="list" index-type="" repeatable="false">
       		<dynamic-element name=" White " type="font-white" repeatable="false"/>
            	</dynamic-element>
      

      During upgrade to 6.2, we moved the journalstructure to DDMStructure table and converted the structure during upgrade:

       	<dynamic-element name="leftHeadingColor" repeatable="false" dataType="string" indexType="" required="false" showLabel="true" type="select">
       		<dynamic-element name="optionxequ" type="option" repeatable="false" value="font-white">
       			<meta-data locale="en_US">
       				<entry name="label"><![CDATA[ White ]]></entry>
       			</meta-data>
       		</dynamic-element>
      

      During upgrade, we generate a random name for every option type elements in JournalConverterImpl.java:

      ...
      				element.addAttribute("name", "option" + StringUtil.randomId());
      ...
      

      So the name will be option + a 4 character long random string:

      	public static String randomId() {
      		Random random = new Random();
      
      		char[] chars = new char[4];
      
      		for (int i = 0; i < 4; i++) {
      			chars[i] = (char)(CharPool.LOWER_CASE_A + random.nextInt(26));
      		}
      
      		return new String(chars);
      	}
      

      If a structure has a lot of elements with option types (100+), there is a tiny possibility that the random name generator will generate the same name in the same structure, it will cause that the upgrade will fail:

      17:45:21,136 WARN  [localhost-startStop-1][VerifyDynamicDataMapping:189] Structure with class name ID 10108 and structure key = 10898 contains more than one element that is identified by the same name either within itself or within any of its parent structures. The duplicate element names are: optionylgt
      17:45:21,243 ERROR [localhost-startStop-1][DBUpgrader:247] Unable to execute verify process: com.liferay.portal.verify.VerifyException: com.liferay.portal.verify.VerifyException: Duplicate element name found in structures
      com.liferay.portal.verify.VerifyException: com.liferay.portal.verify.VerifyException: com.liferay.portal.verify.VerifyException: Duplicate element name found in structures
      	at com.liferay.portal.verify.VerifyProcess.verify(VerifyProcess.java:71)
      	at com.liferay.portal.verify.VerifyProcessUtil._verifyProcess(VerifyProcessUtil.java:111)
      	at com.liferay.portal.verify.VerifyProcessUtil._verifyProcess(VerifyProcessUtil.java:76)
      	at com.liferay.portal.verify.VerifyProcessUtil.verifyProcess(VerifyProcessUtil.java:46)
      	at com.liferay.portal.events.StartupHelper.verifyProcess(StartupHelper.java:146)
      	at com.liferay.portal.events.StartupHelperUtil.verifyProcess(StartupHelperUtil.java:67)
      	at com.liferay.portal.tools.DBUpgrader.verify(DBUpgrader.java:240)
      	at com.liferay.portal.events.StartupAction.doRun(StartupAction.java:237)
      	at com.liferay.portal.ee.license.StartupAction.doRun(Unknown Source)
      	at com.liferay.portal.events.StartupAction.run(StartupAction.java:75)
      	at com.liferay.portal.servlet.MainServlet.processStartupEvents(MainServlet.java:1250)
      	at com.liferay.portal.servlet.MainServlet.init(MainServlet.java:231)
      	at javax.servlet.GenericServlet.init(GenericServlet.java:160)
      	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
      	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
      	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
      	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
      	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
      	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
      	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
      	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
      	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:656)
      	at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1635)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      	at java.lang.Thread.run(Thread.java:745)
      Caused by: com.liferay.portal.verify.VerifyException: com.liferay.portal.verify.VerifyException: Duplicate element name found in structures
      	at com.liferay.portal.verify.VerifyProcess.verify(VerifyProcess.java:71)
      	at com.liferay.portal.verify.VerifyProcess.verify(VerifyProcess.java:76)
      	at com.liferay.portal.verify.VerifyProcessSuite.doVerify(VerifyProcessSuite.java:43)
      	at com.liferay.portal.verify.VerifyProcess.verify(VerifyProcess.java:68)
      	... 28 more
      Caused by: com.liferay.portal.verify.VerifyException: Duplicate element name found in structures
      	at com.liferay.portal.verify.VerifyDynamicDataMapping.doVerify(VerifyDynamicDataMapping.java:241)
      	at com.liferay.portal.verify.VerifyProcess.verify(VerifyProcess.java:68)
      	... 31 more

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  3 years, 31 weeks, 6 days ago

                  Packages

                  Version Package
                  6.2.X EE
                  7.0.1 CE GA2