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

Localized string expando throws ClassCastException

Details

    Description

      With the latest 6.2 Portal, CE and EE+all patches, I'm getting an ClassCastException when using an expando with STRING_LOCALIZED as its type.

      Steps:
      1. Add an expando for "Site" of type "Localized Text" in the Admin Panel
      2. Go to site configuration -> custom fields of any site
      3. Change the value to something like "

      {en_US=test,de_DE=Test}

      " or simply do nothing and click on the save button

      A stacktrace like this will appear in console:

      ERROR [http-bio-8080-exec-1][render_portlet_jsp:132] null
      java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
         at com.liferay.portlet.expando.service.impl.ExpandoValueLocalServiceImpl.addValue(ExpandoValueLocalServiceImpl.java:546)
      
      So it's reffering to this file: https://github.com/liferay/liferay-portal/blob/master/portal-impl/src/com/liferay/portlet/expando/service/impl/ExpandoValueLocalServiceImpl.java?source=cc#L542
      

      As far as I see, there's no code for any of the localized expando types like STRING_LOCALIZED.
      We've added some lines of code at this point, to handle it and the error is gone:

      //...
      else if(type == ExpandoColumnConstants.STRING_LOCALIZED) {
         String tmp = (String) data;
         if (!tmp.startsWith("{") && !tmp.endsWith("}")) {
            throw new PortalException("Localized Strings must begin with '{' and end with '}'");
         }
         // remove curly braces
         tmp = tmp.trim().substring(1, ((String)data).length()-1);
         String[] splits = tmp.split(",");
         if (splits.length == 0) {
            throw new PortalException("Localized String too short");
         }
         Map<Locale, String> vals = new HashMap<>();
         for (String part : splits) {
            String[] split = part.split("=");
            if (split.length == 0 || split.length > 2)
               throw new PortalException("Localized Part '"+part+"' not parseable");
            Locale locale = LocaleUtil.fromLanguageId(split[0]);
            if (split.length == 1) {
              vals.put(locale, "");
            } else {
              vals.put(locale, split[1]);
            }
         }
      //...
      

      I found LPS-42143, which seems to be pretty similar. It was fixed some weeks ago, but as this issue still appears in 6.2 EE with latest patches, I guess, it's not included in these patches but might be fixed already in some other way.

      Attachments

        Issue Links

          Activity

            People

              mika.koivisto Mika Koivisto (Inactive)
              mod David Kubitza (Inactive)
              Kiyoshi Lee Kiyoshi Lee
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                8 years, 45 weeks, 4 days ago

                Packages

                  Version Package
                  7.0.0 M3