Ignore:
Timestamp:
2023-02-16T16:01:49+01:00 (23 months ago)
Author:
taylor.smock
Message:

Fix several coverity issues

CID-1504572: Synchronization on java.util.concurrent objects

The lock wasn't necessary after moving from AtomicBoolean to
CountDownLatch

CID-1504570: Dereference null value -- the default getApiUrl return was null
CID-1504570: Explicit null dereferenced

Consumer<IOAuthToken> to Consumer<Optional<IOAuthToken>>

CID-1476014, CID-1476013, CID-1476011: Resource leak

These resource leaks are unlikely to happen outside of plugin code,
and are all related to StringSelection#getTransferData, which may
return a Closeable object, but is unlikely to be the Transferable
for any of the affected classes.


This also fixes some recently introduced SonarLint issues. It also suppresses
squid:S100 ("Method names should comply with a naming convention") for the MapCSS
Functions class, since the convention for that method names in that class is
^[a-zA-Z][a-zA-Z0-9_]*$

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/oauth/OAuth20AuthorizationTest.java

    r18650 r18665  
    33
    44import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertFalse;
    56import static org.junit.jupiter.api.Assertions.assertNotNull;
    6 import static org.junit.jupiter.api.Assertions.assertNull;
    77import static org.junit.jupiter.api.Assertions.assertTrue;
    88
     
    1010import java.util.HashMap;
    1111import java.util.Map;
     12import java.util.Optional;
    1213import java.util.concurrent.atomic.AtomicReference;
    1314import java.util.stream.Collectors;
     
    166167    void testAuthorize(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOException {
    167168        final OAuth20Authorization authorization = new OAuth20Authorization();
    168         final AtomicReference<IOAuthToken> consumer = new AtomicReference<>();
     169        final AtomicReference<Optional<IOAuthToken>> consumer = new AtomicReference<>();
    169170        OAuth20Parameters parameters = (OAuth20Parameters) OAuthParameters.createDefault(OsmApi.getOsmApi().getBaseUrl(), OAuthVersion.OAuth20);
    170171        RemoteControl.start();
     
    181182        }
    182183        assertNotNull(consumer.get());
    183         assertEquals(OAuthVersion.OAuth20, consumer.get().getOAuthType());
    184         OAuth20Token token = (OAuth20Token) consumer.get();
     184        assertTrue(consumer.get().isPresent());
     185        assertEquals(OAuthVersion.OAuth20, consumer.get().get().getOAuthType());
     186        OAuth20Token token = (OAuth20Token) consumer.get().get();
    185187        assertEquals("test_access_token", token.getBearerToken());
    186188    }
     
    190192        oauthServer.stateToReturn = "Bad_State";
    191193        final OAuth20Authorization authorization = new OAuth20Authorization();
    192         final AtomicReference<IOAuthToken> consumer = new AtomicReference<>();
     194        final AtomicReference<Optional<IOAuthToken>> consumer = new AtomicReference<>();
    193195        OAuth20Parameters parameters = (OAuth20Parameters) OAuthParameters.createDefault(OsmApi.getOsmApi().getBaseUrl(), OAuthVersion.OAuth20);
    194196        RemoteControl.start();
     
    206208            client.disconnect();
    207209        }
    208         assertNull(consumer.get());
     210        assertFalse(consumer.get().isPresent());
    209211    }
    210212}
Note: See TracChangeset for help on using the changeset viewer.