小编Bug*_*low的帖子

Sonar: Replace the synchronized class "Hashtable" by an unsynchronized one such as "HashMap"

Im having trouble replacing hashtable for hashmap because the method im using receives a hashtable:

private Context getInitialContext() throws NamingException {

        final Hashtable<String, Object> jndiProperties = new Hashtable<>();

        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        // This "new InitialContext()" receives a Hastable, and I can't modify that
        // because that is part of a jar
        // "javax.naming.InitialContext.InitialContext(Hashtable<?, ?> environment)
        // throws NamingException"
        context = new InitialContext(jndiProperties);

        return context;
    }
Run Code Online (Sandbox Code Playgroud)

InitialContext method:

public InitialContext(Hashtable<?,?> environment)
        throws NamingException
    {
        if (environment != null) {
            environment = (Hashtable)environment.clone(); …
Run Code Online (Sandbox Code Playgroud)

java sonarqube sonarlint

5
推荐指数
2
解决办法
648
查看次数

标签 统计

java ×1

sonarlint ×1

sonarqube ×1