Skip to content

Commit

Permalink
Deploying to gh-pages from @ e2d2dd1 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
Swalkyn committed Sep 28, 2023
1 parent 5ab81db commit 78509c6
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 19 deletions.
54 changes: 45 additions & 9 deletions rules/S6322/default-description.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,58 @@
<div class="sect1">
<h2 id="_description">Description</h2>
<div class="sectionbody">

<div class="paragraph">
<p>Many modification methods in the collection interfaces are optional.
Some implementations do not implement those methods and throw a runtime exception (<code>UnsupportedOperationException</code>).
To fix this issue, make sure you call modification methods on a collection implementation that supports them.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_why_is_this_an_issue">Why is this an issue?</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The Java Collections framework defines interfaces such as <code>java.util.List</code> or <code>java.util.Map</code>. Several implementation classes are provided for each of those interfaces to fill different needs: some of the implementations guarantee a few given performance characteristics, some others ensure a given behavior, for example immutability.</p>
<p>The Java Collections framework defines interfaces such as <code>java.util.List</code> or <code>java.util.Map</code>.
Several implementation classes are provided for each of those interfaces to fill different needs: some of the implementations guarantee a few given performance characteristics, some others ensure a given behavior, for example immutability.</p>
</div>
<div class="paragraph">
<p>Among the methods defined by the interfaces of the Collections framework, some are declared as "optional": an implementation class may choose to throw an <code>UnsupportedOperationException</code> when one of those methods is called. For example, <code>java.util.Collections.emptyList()</code> returns an implementation of <code>java.util.List</code> which is documented as "immutable": calling the <code>add</code> method on this object triggers an <code>UnsupportedOperationException</code>.</p>
<p>Among the methods defined by the interfaces of the Collections framework, some are declared as "optional": an implementation class may choose to throw an <code>UnsupportedOperationException</code> when one of those methods is called.
For example, <code>java.util.Collections.emptyList()</code> returns an implementation of <code>java.util.List</code> which is documented as "immutable".
Calling the <code>add</code> method on this object triggers an <code>UnsupportedOperationException</code>.</p>
</div>
<div class="sect2">
<h3 id="_what_is_the_potential_impact">What is the potential impact?</h3>
<div class="paragraph">
<p>Issues of this type interrupt the normal execution of a program, causing it to
crash or putting it into an inconsistent state.
Therefore, this issue might impact the availability and reliability of your
application, or even result in data loss.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_how_to_fix_it">How to fix it</h2>
<div class="sectionbody">
<div class="paragraph">
<p>When calling one of the "optional" methods, a developer should therefore make sure that the implementation class on which the call is made indeed supports this method.</p>
<p>When calling a method labeled as optional, you should make sure that the implementation class on which the call is made indeed supports this method.</p>
</div>
<div class="sect2">
<h3 id="_noncompliant_code_example">Noncompliant code example</h3>
<h3 id="_code_examples">Code examples</h3>
<div class="sect3">
<h4 id="_noncompliant_code_example">Noncompliant code example</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">List&lt;String&gt; list = Collections.emptyList();
<pre class="highlight"><code class="language-java" data-lang="java">List&lt;String&gt; list = Collections.emptyList(); // The list implementation returned here is unmodifiable.
if (someCondition) {
list.add("hello"); // Noncompliant; throws an UnsupportedOperationException
}
return list;</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_compliant_solution">Compliant solution</h3>
<div class="sect3">
<h4 id="_compliant_solution">Compliant solution</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">List&lt;String&gt; list = new ArrayList&lt;&gt;();
Expand All @@ -53,15 +76,28 @@ <h3 id="_compliant_solution">Compliant solution</h3>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_resources">Resources</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_documentation">Documentation</h3>
<div class="ulist">
<ul>
<li>
<p><a href="https://docs.oracle.com/javase/8/docs/technotes/guides/collections/overview.html">Collections Framework Overview</a> in the Java documentation</p>
<p><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/doc-files/coll-overview.html">Collections Framework Overview</a> in the Java documentation</p>
</li>
<li>
<p><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/List.html">List</a> in the Java documentation</p>
</li>
<li>
<p><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Set.html">Set</a> in the Java documentation</p>
</li>
<li>
<p><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Map.html">Map</a> in the Java documentation</p>
</li>
</ul>
</div>
</div>
</div>
</div>
54 changes: 45 additions & 9 deletions rules/S6322/java-description.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,58 @@
<div class="sect1">
<h2 id="_description">Description</h2>
<div class="sectionbody">

<div class="paragraph">
<p>Many modification methods in the collection interfaces are optional.
Some implementations do not implement those methods and throw a runtime exception (<code>UnsupportedOperationException</code>).
To fix this issue, make sure you call modification methods on a collection implementation that supports them.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_why_is_this_an_issue">Why is this an issue?</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The Java Collections framework defines interfaces such as <code>java.util.List</code> or <code>java.util.Map</code>. Several implementation classes are provided for each of those interfaces to fill different needs: some of the implementations guarantee a few given performance characteristics, some others ensure a given behavior, for example immutability.</p>
<p>The Java Collections framework defines interfaces such as <code>java.util.List</code> or <code>java.util.Map</code>.
Several implementation classes are provided for each of those interfaces to fill different needs: some of the implementations guarantee a few given performance characteristics, some others ensure a given behavior, for example immutability.</p>
</div>
<div class="paragraph">
<p>Among the methods defined by the interfaces of the Collections framework, some are declared as "optional": an implementation class may choose to throw an <code>UnsupportedOperationException</code> when one of those methods is called. For example, <code>java.util.Collections.emptyList()</code> returns an implementation of <code>java.util.List</code> which is documented as "immutable": calling the <code>add</code> method on this object triggers an <code>UnsupportedOperationException</code>.</p>
<p>Among the methods defined by the interfaces of the Collections framework, some are declared as "optional": an implementation class may choose to throw an <code>UnsupportedOperationException</code> when one of those methods is called.
For example, <code>java.util.Collections.emptyList()</code> returns an implementation of <code>java.util.List</code> which is documented as "immutable".
Calling the <code>add</code> method on this object triggers an <code>UnsupportedOperationException</code>.</p>
</div>
<div class="sect2">
<h3 id="_what_is_the_potential_impact">What is the potential impact?</h3>
<div class="paragraph">
<p>Issues of this type interrupt the normal execution of a program, causing it to
crash or putting it into an inconsistent state.
Therefore, this issue might impact the availability and reliability of your
application, or even result in data loss.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_how_to_fix_it">How to fix it</h2>
<div class="sectionbody">
<div class="paragraph">
<p>When calling one of the "optional" methods, a developer should therefore make sure that the implementation class on which the call is made indeed supports this method.</p>
<p>When calling a method labeled as optional, you should make sure that the implementation class on which the call is made indeed supports this method.</p>
</div>
<div class="sect2">
<h3 id="_noncompliant_code_example">Noncompliant code example</h3>
<h3 id="_code_examples">Code examples</h3>
<div class="sect3">
<h4 id="_noncompliant_code_example">Noncompliant code example</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">List&lt;String&gt; list = Collections.emptyList();
<pre class="highlight"><code class="language-java" data-lang="java">List&lt;String&gt; list = Collections.emptyList(); // The list implementation returned here is unmodifiable.
if (someCondition) {
list.add("hello"); // Noncompliant; throws an UnsupportedOperationException
}
return list;</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_compliant_solution">Compliant solution</h3>
<div class="sect3">
<h4 id="_compliant_solution">Compliant solution</h4>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">List&lt;String&gt; list = new ArrayList&lt;&gt;();
Expand All @@ -53,15 +76,28 @@ <h3 id="_compliant_solution">Compliant solution</h3>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_resources">Resources</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_documentation">Documentation</h3>
<div class="ulist">
<ul>
<li>
<p><a href="https://docs.oracle.com/javase/8/docs/technotes/guides/collections/overview.html">Collections Framework Overview</a> in the Java documentation</p>
<p><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/doc-files/coll-overview.html">Collections Framework Overview</a> in the Java documentation</p>
</li>
<li>
<p><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/List.html">List</a> in the Java documentation</p>
</li>
<li>
<p><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Set.html">Set</a> in the Java documentation</p>
</li>
<li>
<p><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Map.html">Map</a> in the Java documentation</p>
</li>
</ul>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion rules/rule-index.json

Large diffs are not rendered by default.

0 comments on commit 78509c6

Please sign in to comment.