<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>What is "java.lang.InstantiationException: java.util.Locale" in a portlet?</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=110864714" />
  <subtitle>What is "java.lang.InstantiationException: java.util.Locale" in a portlet?</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=110864714</id>
  <updated>2026-04-04T05:53:46Z</updated>
  <dc:date>2026-04-04T05:53:46Z</dc:date>
  <entry>
    <title>What is "java.lang.InstantiationException: java.util.Locale" in a portlet?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110864713" />
    <author>
      <name>Mirto Silvio Busico</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110864713</id>
    <updated>2018-09-03T14:07:36Z</updated>
    <published>2018-09-03T14:07:36Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;I'm trying to write localized content in a service builder generated field.&lt;/p&gt;
&lt;p&gt;The code I have up to now is (for field5 of the default foo entity
  defined as &lt;code&gt;&amp;amp;lt;column name="field5"
    type="String" localized="true"/&amp;amp;gt;&lt;/code&gt;):&lt;/p&gt;
&lt;pre&gt;
        &lt;strong&gt;Set&amp;lt;Locale&amp;gt; locales = LanguageUtil.getAvailableLocales();

        Map&amp;lt;Locale, String&amp;gt; map = new HashMap&amp;lt;Locale, String&amp;gt;();

        for (Locale locale : locales) {
            String languageId = LocaleUtil.toLanguageId(locale);
            String xxx = "field5";
            String localeParameter = xxx.concat(StringPool.UNDERLINE).concat(languageId);
            String yyy = ParamUtil.getString(actionRequest,localeParameter);
            map.put(locale, yyy);
        }
        
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        XMLEncoder xmlEncoder = new XMLEncoder(bos);
        xmlEncoder.writeObject(map);
        xmlEncoder.flush();

        String field5 = bos.toString();&lt;/strong&gt;
&lt;/pre&gt;
&lt;p&gt;But the loop to assign values to map gives these errors:&lt;/p&gt;
&lt;pre&gt;
java.lang.InstantiationException: java.util.Locale
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement HashMap.put(Locale, "");
Continuing ...
java.lang.InstantiationException: java.util.Locale
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement HashMap.put(Locale, "italiano");
Continuing ...
java.lang.InstantiationException: java.util.Locale
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement HashMap.put(Locale, "");
Continuing ...
java.lang.InstantiationException: java.util.Locale
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement HashMap.put(Locale, "english");
Continuing ...
java.lang.InstantiationException: java.util.Locale
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement HashMap.put(Locale, "");
Continuing ...
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What I'm doing wrong?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Mirto Silvio Busico</dc:creator>
    <dc:date>2018-09-03T14:07:36Z</dc:date>
  </entry>
</feed>
