Skip to content

Commit bcc8182

Browse files
committed
findbugs: write to static from instance these are the trivial cases of ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD as reported by findbugs
Signed-off-by: Daan Hoogland <daan.hoogland@gmail.com> This closes apache#539
1 parent 25e9918 commit bcc8182

5 files changed

Lines changed: 54 additions & 29 deletions

File tree

‎engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ public class ImageFormatHelper {
3131

3232
@Inject
3333
public void setFormats(List<ImageFormat> formats) {
34-
ImageFormatHelper.formats = formats;
34+
ImageFormatHelper.initFormats(formats);
35+
}
36+
37+
private static synchronized void initFormats(List<ImageFormat> newFormats) {
38+
formats = newFormats;
3539
}
3640

3741
public static ImageFormat getFormat(String format) {

‎plugins/event-bus/rabbitmq/src/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,8 @@
3030
import javax.ejb.Local;
3131
import javax.naming.ConfigurationException;
3232

33-
import org.apache.cloudstack.framework.events.Event;
34-
import org.apache.cloudstack.framework.events.EventBus;
35-
import org.apache.cloudstack.framework.events.EventBusException;
36-
import org.apache.cloudstack.framework.events.EventSubscriber;
37-
import org.apache.cloudstack.framework.events.EventTopic;
38-
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
3933
import org.apache.log4j.Logger;
4034

41-
import com.cloud.utils.Ternary;
42-
import com.cloud.utils.component.ManagerBase;
4335
import com.rabbitmq.client.AMQP;
4436
import com.rabbitmq.client.AlreadyClosedException;
4537
import com.rabbitmq.client.Channel;
@@ -51,6 +43,16 @@
5143
import com.rabbitmq.client.ShutdownListener;
5244
import com.rabbitmq.client.ShutdownSignalException;
5345

46+
import org.apache.cloudstack.framework.events.Event;
47+
import org.apache.cloudstack.framework.events.EventBus;
48+
import org.apache.cloudstack.framework.events.EventBusException;
49+
import org.apache.cloudstack.framework.events.EventSubscriber;
50+
import org.apache.cloudstack.framework.events.EventTopic;
51+
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
52+
53+
import com.cloud.utils.Ternary;
54+
import com.cloud.utils.component.ManagerBase;
55+
5456
@Local(value = EventBus.class)
5557
public class RabbitMQEventBus extends ManagerBase implements EventBus {
5658

@@ -138,23 +140,23 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
138140
return true;
139141
}
140142

141-
public void setServer(String amqpHost) {
143+
public static void setServer(String amqpHost) {
142144
RabbitMQEventBus.amqpHost = amqpHost;
143145
}
144146

145-
public void setUsername(String username) {
147+
public static void setUsername(String username) {
146148
RabbitMQEventBus.username = username;
147149
}
148150

149-
public void setPassword(String password) {
151+
public static void setPassword(String password) {
150152
RabbitMQEventBus.password = password;
151153
}
152154

153-
public void setPort(Integer port) {
155+
public static void setPort(Integer port) {
154156
RabbitMQEventBus.port = port;
155157
}
156158

157-
public void setSecureProtocol(String protocol) {
159+
public static void setSecureProtocol(String protocol) {
158160
RabbitMQEventBus.secureProtocol = protocol;
159161
}
160162

@@ -163,11 +165,11 @@ public void setName(String name) {
163165
this.name = name;
164166
}
165167

166-
public void setExchange(String exchange) {
168+
public static void setExchange(String exchange) {
167169
RabbitMQEventBus.amqpExchangeName = exchange;
168170
}
169171

170-
public void setRetryInterval(Integer retryInterval) {
172+
public static void setRetryInterval(Integer retryInterval) {
171173
RabbitMQEventBus.retryInterval = retryInterval;
172174
}
173175

@@ -378,7 +380,7 @@ private synchronized Connection createConnection() throws Exception {
378380
}
379381

380382
if (useSsl != null && !useSsl.isEmpty() && useSsl.equalsIgnoreCase("true")) {
381-
factory.useSslProtocol(this.secureProtocol);
383+
factory.useSslProtocol(secureProtocol);
382384
}
383385
Connection connection = factory.newConnection();
384386
connection.addShutdownListener(disconnectHandler);

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,19 @@
3535

3636
public class KVMHAMonitor extends KVMHABase implements Runnable {
3737
private static final Logger s_logger = Logger.getLogger(KVMHAMonitor.class);
38-
private Map<String, NfsStoragePool> _storagePool = new ConcurrentHashMap<String, NfsStoragePool>();
38+
private final Map<String, NfsStoragePool> _storagePool = new ConcurrentHashMap<String, NfsStoragePool>();
3939

40-
private String _hostIP; /* private ip address */
40+
private final String _hostIP; /* private ip address */
4141

4242
public KVMHAMonitor(NfsStoragePool pool, String host, String scriptPath) {
4343
if (pool != null) {
4444
_storagePool.put(pool._poolUUID, pool);
4545
}
4646
_hostIP = host;
47+
configureHeartBeatPath(scriptPath);
48+
}
49+
50+
private static synchronized void configureHeartBeatPath(String scriptPath) {
4751
KVMHABase.s_heartBeatPath = scriptPath;
4852
}
4953

‎server/src/com/cloud/api/auth/APIAuthenticationManagerImpl.java‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@
1616
// under the License.
1717
package com.cloud.api.auth;
1818

19-
import com.cloud.utils.component.ComponentContext;
20-
import com.cloud.utils.component.ManagerBase;
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.Map;
22+
import java.util.concurrent.ConcurrentHashMap;
23+
24+
import javax.ejb.Local;
25+
26+
import org.apache.log4j.Logger;
27+
2128
import org.apache.cloudstack.api.APICommand;
2229
import org.apache.cloudstack.api.auth.APIAuthenticationManager;
2330
import org.apache.cloudstack.api.auth.APIAuthenticator;
2431
import org.apache.cloudstack.api.auth.PluggableAPIAuthenticator;
25-
import org.apache.log4j.Logger;
2632

27-
import javax.ejb.Local;
28-
import java.util.ArrayList;
29-
import java.util.HashMap;
30-
import java.util.List;
31-
import java.util.Map;
33+
import com.cloud.utils.component.ComponentContext;
34+
import com.cloud.utils.component.ManagerBase;
3235

3336
@Local(value = APIAuthenticationManager.class)
3437
@SuppressWarnings("unchecked")
@@ -52,17 +55,25 @@ public void setApiAuthenticators(List<PluggableAPIAuthenticator> authenticators)
5255

5356
@Override
5457
public boolean start() {
55-
s_authenticators = new HashMap<String, Class<?>>();
58+
initAuthenticator();
5659
for (Class<?> authenticator: getCommands()) {
5760
APICommand command = authenticator.getAnnotation(APICommand.class);
5861
if (command != null && !command.name().isEmpty()
5962
&& APIAuthenticator.class.isAssignableFrom(authenticator)) {
60-
s_authenticators.put(command.name().toLowerCase(), authenticator);
63+
addAuthenticator(authenticator, command);
6164
}
6265
}
6366
return true;
6467
}
6568

69+
private static synchronized void addAuthenticator(Class<?> authenticator, APICommand command) {
70+
s_authenticators.put(command.name().toLowerCase(), authenticator);
71+
}
72+
73+
private static synchronized void initAuthenticator() {
74+
s_authenticators = new ConcurrentHashMap<String, Class<?>>();
75+
}
76+
6677
@Override
6778
public List<Class<?>> getCommands() {
6879
List<Class<?>> cmdList = new ArrayList<Class<?>>();

‎utils/src/com/cloud/utils/component/ComponentContext.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ public boolean isInitializeBeans() {
273273
}
274274

275275
public void setInitializeBeans(boolean initializeBeans) {
276+
initInitializeBeans(initializeBeans);
277+
}
278+
279+
private static synchronized void initInitializeBeans(boolean initializeBeans) {
276280
s_initializeBeans = initializeBeans;
277281
}
278282
}

0 commit comments

Comments
 (0)