Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

JD.UNMOD

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

Example 1

12     public static void main(String[] args) {
13         argsCol = createCollection(args);
14         for (final Iterator<String> iterator = argsCol.iterator(); iterator.hasNext();) {
15             final String arg = iterator.next();
16             if ("version".equals(arg)) {
17                 printVersion();
18                 iterator.remove();
19             }
20         }
21         run();
22     }
23 
24     public static Collection<String> createCollection(final String[] array) {
25         return Arrays.asList(array);
26     }

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

Example 2

12     public static void main(String[] args) {
13         argsCol = createCollection(args);
14         for (final Iterator<String> iterator = argsCol.iterator(); iterator.hasNext();) {
15             final String arg = iterator.next();
16             if ("version".equals(arg)) {
17                 printVersion();
18                 iterator.remove();
19             }
20         }
21         run();
22     }
23 
24     public static Collection<String> createCollection(final String[] array) {
25         final List<String> list = new ArrayList<String>();
26         for (final String str : array) {
27             list.add(str);
28         }
29         return list;
30     }

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.