JD.UNMOD

This error is reported when an attempt to modify an unmodifiable collection is detected. Such attempts cause runtime exceptions.

Example 1

Copy
     public static void main(String[] args) {
         argsCol = createCollection(args);
         for (final Iterator<String> iterator = argsCol.iterator(); iterator.hasNext();) {
             final String arg = iterator.next();
             if ("version".equals(arg)) {
                 printVersion();
                 iterator.remove();
             }
         }
         run();
     }
 
     public static Collection<String> createCollection(final String[] array) {
         return Arrays.asList(array);
     }

JD.UNMOD is reported for the snippet on line 18: attempt to modify the unmodifiable collection 'argsCol' via its iterator.

Example 2

Copy
     public static void main(String[] args) {
         argsCol = createCollection(args);
         for (final Iterator<String> iterator = argsCol.iterator(); iterator.hasNext();) {
             final String arg = iterator.next();
             if ("version".equals(arg)) {
                 printVersion();
                 iterator.remove();
             }
         }
         run();
     }
 
     public static Collection<String> createCollection(final String[] array) {
         final List<String> list = new ArrayList<String>();
         for (final String str : array) {
             list.add(str);
         }
         return list;
     }

The problem from the previous snippet is fixed: the code is still modifying 'argsCol' via its iterator, however the 'argsCol' is not unmodifiable here; see the modified 'createCollection' method. JD.UNMOD is not reported here.

Extension

This checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information.