Skip to main content

NullPointerException thrown by java.nio.charset.Charset.put

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2003-06-11

The following test case throws an NPE when run in our maven project.
package pack;

<pre>import java.nio.charset.Charset;

import java.util.Iterator;
import java.util.Set;
<pre>public class TestCase {

    public static void main(String[] args) {
        Set set = Charset.availableCharsets().keySet();
        for (Iterator iterator = set.iterator(); iterator.hasNext();) {
            String s = (String);

Here is the stacktrace:

Exception in thread "main" java.lang.NullPointerException
at java.nio.charset.Charset.put(
at java.nio.charset.Charset.access$300(
at java.nio.charset.Charset$
at java.nio.charset.Charset$
at Method)
at java.nio.charset.Charset.availableCharsets(
at pack.TestCase.main(

However, when we run the project as a separate project, it runs fine.

Does anyone have any clue as to how to fix this error?

Thanks in advance,