Skip to content

Commit

Permalink
Synchronize static members intialization in constructor
Browse files Browse the repository at this point in the history
There are rare cases of entering an infinite loop when initializing multiple instances of TwitterImpl from multiple threads concurrently.

```implicitParamsStrMap.put(conf, implicitParamsStr);```

Might cause an infinite loop in 

```
        at java.util.HashMap.transfer(HashMap.java:484)
        at java.util.HashMap.resize(HashMap.java:463)
        at java.util.HashMap.addEntry(HashMap.java:755)
        at java.util.HashMap.put(HashMap.java:385)
```

More info about ```HashMap.put()``` causing an infinite loop can be found here http://stackoverflow.com/q/13695832/1442259
  • Loading branch information
nivs committed Jun 15, 2014
1 parent eb0eeb4 commit 26e8201
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions twitter4j-core/src/main/java/twitter4j/TwitterImpl.java
Expand Up @@ -47,6 +47,7 @@ class TwitterImpl extends TwitterBaseImpl implements Twitter {
TwitterImpl(Configuration conf, Authorization auth) {
super(conf, auth);
INCLUDE_MY_RETWEET = new HttpParameter("include_my_retweet", conf.isIncludeMyRetweetEnabled());
synchronized(TwitterImpl.class) {
HttpParameter[] implicitParams = implicitParamsMap.get(conf);
String implicitParamsStr = implicitParamsStrMap.get(conf);
if (implicitParams == null) {
Expand Down Expand Up @@ -76,6 +77,7 @@ class TwitterImpl extends TwitterBaseImpl implements Twitter {

IMPLICIT_PARAMS = implicitParams;
IMPLICIT_PARAMS_STR = implicitParamsStr;
}
}

/* Timelines Resources */
Expand Down

0 comments on commit 26e8201

Please sign in to comment.