Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Code Block
bgColor#FFcccc
private final String lock = new String("LOCK").intern();

public void doSomething() {
  synchronized (lock) {
    // ...
  }
}

Wiki MarkupAccording to the Java API class {{java.lang.String}} documentation \ [[API 2006|AA. References#API 06]\]:

When the intern() method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

LCK01-J

medium

probable

medium

P8

L2

Automated Detection

Some static analysis tools can detect violations of this rule.

Bibliography

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="809ec4bb-8da5-4cc9-ae5a-d6b404bc8de4"><ac:plain-text-body><![CDATA[

[ [API 2006AA. References#API 06]]

Class String, Collections

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8572b1ea-b6e4-432b-bbcf-7c51adb30477"><ac:plain-text-body><![CDATA[

[ [Findbugs 2008AA. References#Findbugs 08] ]

 

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="293fc7e5-8560-4eb6-a9db-c8d160cb17d4"><ac:plain-text-body><![CDATA[

[ [Miller 2009AA. References#Miller 09]]

Locking

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b647c1bc-cdf0-4ff2-bd88-dfe39e5445e7"><ac:plain-text-body><![CDATA[

[[Pugh 2008AA. References#Pugh 08] ]

Synchronization ]]></ac:plain-text-body></ac:structured-macro><ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="92b3ffc2-274e-42c8-b4c3-7c177cf90f5b"><ac:plain-text-body><![CDATA

[ [[Tutorials 2008AA. References#Tutorials 08] ]

[Wrapper Implementations

http://java.sun.com/docs/books/tutorial/collections/implementations/wrapper.html]

]]></ac:plain-text-body></ac:structured-macro>

...

      08. Locking (LCK)