Skip to content

Commit

Permalink
ARTEMIS-4345: update to Error Prone 2.20.0 and fix up new errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmellr committed Jul 5, 2023
1 parent f60a7d5 commit cb9e1fe
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ public class FileBrokerTest {
public void startWithoutJMS() throws Exception {
ServerDTO serverDTO = new ServerDTO();
serverDTO.configuration = "broker-nojms.xml";
FileBroker broker = null;
FileBroker broker = new FileBroker(serverDTO, new ActiveMQJAASSecurityManager(), null);
try {
broker = new FileBroker(serverDTO, new ActiveMQJAASSecurityManager(), null);
broker.start();
JMSServerManagerImpl jmsServerManager = (JMSServerManagerImpl) broker.getComponents().get("jms");
Assert.assertNull(jmsServerManager);
Expand All @@ -59,7 +58,6 @@ public void startWithoutJMS() throws Exception {
Assert.assertTrue(activeMQServer.isStarted());
Assert.assertTrue(broker.isStarted());
} finally {
assert broker != null;
broker.stop();
}
}
Expand Down Expand Up @@ -145,7 +143,6 @@ public void testConfigFileReload() throws Exception {

locator.close();
} finally {
assert broker != null;
broker.stop();
if (path != null) {
replacePatternInFile(path, "X", "guest");
Expand Down Expand Up @@ -194,7 +191,6 @@ public void testConfigFileReloadNegative() throws Exception {

locator.close();
} finally {
assert broker != null;
broker.stop();
if (path != null) {
replacePatternInFile(path, "X", "guest");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ public void run() {
local.start();
final long newInitialDelay = 1000;
//the parameters are valid?
assert initialDelay != newInitialDelay && newInitialDelay != period;
Assert.assertTrue(initialDelay != newInitialDelay);
Assert.assertTrue(newInitialDelay != period);

local.setInitialDelay(newInitialDelay);
local.stop();
Assert.assertEquals("the initial dalay can't change", newInitialDelay, local.getInitialDelay());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void shouldClearConsumeRemainingElementsInOrder() {
for (int i = 1; i < elements; i++) {
list.add(i);
}
Assert.assertEquals(elements - 1, list.remove(e -> e != zero));
Assert.assertEquals(elements - 1, list.remove(e -> !zero.equals(e)));
final ArrayList<Integer> remaining = new ArrayList<>();
Assert.assertEquals(1, list.clear(remaining::add));
Assert.assertEquals(0, list.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

import org.jgroups.JChannel;
Expand All @@ -51,20 +52,8 @@ private ActiveMQRaUtils() {
* @param you Second value
* @return True if object equals else false.
*/
@SuppressWarnings("StringEquality")
public static boolean compare(final String me, final String you) {
// If both null or intern equals
if (me == you) {
return true;
}

// if me null and you are not
if (me == null) {
return false;
}

// me will not be null, test for equality
return me.equals(you);
return Objects.equals(me, you);
}

/**
Expand All @@ -75,18 +64,7 @@ public static boolean compare(final String me, final String you) {
* @return True if object equals else false.
*/
public static boolean compare(final Integer me, final Integer you) {
// If both null or intern equals
if (me == you) {
return true;
}

// if me null and you are not
if (me == null) {
return false;
}

// me will not be null, test for equality
return me.equals(you);
return Objects.equals(me, you);
}

/**
Expand All @@ -97,18 +75,7 @@ public static boolean compare(final Integer me, final Integer you) {
* @return True if object equals else false.
*/
public static boolean compare(final Long me, final Long you) {
// If both null or intern equals
if (me == you) {
return true;
}

// if me null and you are not
if (me == null) {
return false;
}

// me will not be null, test for equality
return me.equals(you);
return Objects.equals(me, you);
}

/**
Expand All @@ -119,18 +86,7 @@ public static boolean compare(final Long me, final Long you) {
* @return True if object equals else false.
*/
public static boolean compare(final Double me, final Double you) {
// If both null or intern equals
if (me == you) {
return true;
}

// if me null and you are not
if (me == null) {
return false;
}

// me will not be null, test for equality
return me.equals(you);
return Objects.equals(me, you);
}

/**
Expand All @@ -141,18 +97,7 @@ public static boolean compare(final Double me, final Double you) {
* @return True if object equals else false.
*/
public static boolean compare(final Boolean me, final Boolean you) {
// If both null or intern equals
if (me == you) {
return true;
}

// if me null and you are not
if (me == null) {
return false;
}

// me will not be null, test for equality
return me.equals(you);
return Objects.equals(me, you);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,9 @@ public boolean equals(Object o) {

if (acknowledgeMode != null ? !acknowledgeMode.equals(that.acknowledgeMode) : that.acknowledgeMode != null)
return false;
if (subscriptionDurability != that.subscriptionDurability)
if (subscriptionDurability != null ? !subscriptionDurability.equals(that.subscriptionDurability) : that.subscriptionDurability != null)
return false;
if (shareSubscriptions != that.shareSubscriptions)
if (shareSubscriptions != null ? !shareSubscriptions.equals(that.shareSubscriptions) : that.shareSubscriptions != null)
return false;
if (strConnectorClassName != null ? !strConnectorClassName.equals(that.strConnectorClassName) : that.strConnectorClassName != null)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1410,9 +1410,18 @@ public void testRoleSettingsViaProperties() throws Exception {

Assert.assertEquals(1, configuration.getSecurityRoles().size());
Assert.assertEquals(1, configuration.getSecurityRoles().get("TEST").size());
Assert.assertTrue(configuration.getSecurityRoles().get("TEST").stream().findFirst().orElse(null).isConsume());
Assert.assertTrue(configuration.getSecurityRoles().get("TEST").stream().findFirst().orElse(null).isSend());
Assert.assertFalse(configuration.getSecurityRoles().get("TEST").stream().findFirst().orElse(null).isCreateAddress());

Role role = configuration.getSecurityRoles().get("TEST").stream().findFirst().orElse(null);
Assert.assertNotNull(role);
Assert.assertTrue(role.isConsume());

role = configuration.getSecurityRoles().get("TEST").stream().findFirst().orElse(null);
Assert.assertNotNull(role);
Assert.assertTrue(role.isSend());

role = configuration.getSecurityRoles().get("TEST").stream().findFirst().orElse(null);
Assert.assertNotNull(role);
Assert.assertFalse(role.isCreateAddress());
}

@Test
Expand Down Expand Up @@ -1450,8 +1459,14 @@ public void testRoleAugmentViaProperties() throws Exception {
// verify new addition
Assert.assertEquals(2, configuration.getSecurityRoles().size());
Assert.assertEquals(1, configuration.getSecurityRoles().get("TEST").size());
Assert.assertFalse(configuration.getSecurityRoles().get("TEST").stream().findFirst().orElse(null).isConsume());
Assert.assertTrue(configuration.getSecurityRoles().get("TEST").stream().findFirst().orElse(null).isSend());

Role role = configuration.getSecurityRoles().get("TEST").stream().findFirst().orElse(null);
Assert.assertNotNull(role);
Assert.assertFalse(role.isConsume());

role = configuration.getSecurityRoles().get("TEST").stream().findFirst().orElse(null);
Assert.assertNotNull(role);
Assert.assertTrue(role.isSend());

// verify augmentation
Assert.assertEquals(2, configuration.getSecurityRoles().get("#").size());
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<jetty.version>10.0.15</jetty.version>
<tomcat.servlet-api.version>8.5.78</tomcat.servlet-api.version>
<jgroups.version>5.2.0.Final</jgroups.version>
<errorprone.version>2.10.0</errorprone.version>
<errorprone.version>2.20.0</errorprone.version>
<maven.bundle.plugin.version>5.1.9</maven.bundle.plugin.version>
<maven.checkstyle.plugin.version>3.2.2</maven.checkstyle.plugin.version>
<jib.maven.plugin.version>3.3.2</jib.maven.plugin.version>
Expand Down Expand Up @@ -1099,7 +1099,7 @@
<arg>--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED</arg>
<arg>--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED</arg>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne -Xep:ThreadLocalUsage:ERROR -Xep:MissingOverride:ERROR -Xep:NonAtomicVolatileUpdate:ERROR -Xep:SynchronizeOnNonFinalField:ERROR -Xep:StaticQualifiedUsingExpression:ERROR -Xep:WaitNotInLoop:ERROR -XepExcludedPaths:.*/generated-sources/.*</arg>
<arg>-Xplugin:ErrorProne -Xep:ThreadLocalUsage:ERROR -Xep:MissingOverride:ERROR -Xep:NonAtomicVolatileUpdate:ERROR -Xep:SynchronizeOnNonFinalField:ERROR -Xep:StaticQualifiedUsingExpression:ERROR -Xep:WaitNotInLoop:ERROR -Xep:BanJNDI:OFF -XepExcludedPaths:.*/generated-sources/.*</arg>
</compilerArgs>
</configuration>
</plugin>
Expand Down Expand Up @@ -1133,7 +1133,7 @@
<arg>--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED</arg>
<arg>--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED</arg>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne -Xep:ThreadLocalUsage:ERROR -Xep:MissingOverride:WARN -Xep:NonAtomicVolatileUpdate:ERROR -Xep:SynchronizeOnNonFinalField:ERROR -Xep:StaticQualifiedUsingExpression:ERROR -Xep:WaitNotInLoop:ERROR -XepExcludedPaths:.*/generated-sources/.*</arg>
<arg>-Xplugin:ErrorProne -Xep:ThreadLocalUsage:ERROR -Xep:MissingOverride:WARN -Xep:NonAtomicVolatileUpdate:ERROR -Xep:SynchronizeOnNonFinalField:ERROR -Xep:StaticQualifiedUsingExpression:ERROR -Xep:WaitNotInLoop:ERROR -Xep:BanJNDI:OFF -XepExcludedPaths:.*/generated-sources/.*</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ private void assertCompressionSize(byte[] data, int min, int max) {
int compressed = deflater.deflate(output);
deflater.end();

assert compressed > min && compressed < max;
Assert.assertTrue(compressed > min);
Assert.assertTrue(compressed < max);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import org.apache.activemq.artemis.api.core.QueueConfiguration;
Expand Down Expand Up @@ -213,11 +214,7 @@ protected ActiveMQServer createServer() throws Exception {

final String role = "testRole";
securityManager.getConfiguration().addRole(defUser, role);
config.getSecurityRoles().put("#", new HashSet<Role>() {
{
add(new Role(role, true, true, true, true, true, true, true, true, true, true));
}
});
config.getSecurityRoles().put("#", new HashSet<Role>(Set.of(new Role(role, true, true, true, true, true, true, true, true, true, true))));
}

return activeMQServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.jms.Topic;
import javax.management.MBeanServer;
import java.util.ArrayList;
import java.util.List;

import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
Expand Down Expand Up @@ -162,11 +163,7 @@ protected Configuration createConfigServer(final int source, final int destinati
.setMaxHops(MAX_HOPS)
.setConfirmationWindowSize(1024)
.setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND)
.setStaticConnectors(new ArrayList<String>() {
{
add(destinationLabel);
}
}));
.setStaticConnectors(new ArrayList<String>(List.of(destinationLabel))));

configuration.getAddressSettings().put("#", new AddressSettings().setRedistributionDelay(0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public void decode(ActiveMQBuffer buffer) {
public void timeoutShouldMatchFlushIOPSWithNotBlockingFlush() {
//use a large timeout in order to be reactive
final long timeout = TimeUnit.MILLISECONDS.toNanos(100);
assert ((int) timeout) > 0;
assertTrue(timeout > 0);
//it is optimistic: the timeout and the blockingDeviceFlushTime are a perfect match
final long deviceTime = timeout;
final int bufferSize = Env.osPageSize();
Expand All @@ -374,7 +374,7 @@ public void timeoutShouldMatchFlushIOPSWithNotBlockingFlush() {
//wait the first flush to happen
observer.waitUntilFlushIsDone(1);
//for a not-blocking flush I'm expecting the TimedBuffer has near to finished sleeping now
assert observer.flushesDone() == 1;
assertEquals(1, observer.flushesDone());
//issue a new write
timedBuffer.addBytes(LONG_ENCODER, true, DummyCallback.getInstance());
//the countdown on the TimedBuffer is already started even before this addBytes
Expand All @@ -383,7 +383,7 @@ public void timeoutShouldMatchFlushIOPSWithNotBlockingFlush() {
observer.waitUntilFlushIsDone(2);
final long flushDone = System.nanoTime();
final long elapsedTime = flushDone - endOfWriteRequest;
assert observer.flushesDone() == 2;
assertEquals(2, observer.flushesDone());
//it is much more than what is expected!!if it will fail it means that the timed IOPS = 1/(timeout + blockingDeviceFlushTime)!!!!!!
//while it has to be IOPS = 1/timeout
logger.debug("elapsed time: {} with timeout: {}", elapsedTime, timeout);
Expand All @@ -402,7 +402,7 @@ public void timeoutShouldMatchFlushIOPSWithNotBlockingFlush() {
public void timeoutShouldMatchFlushIOPSWithBlockingFlush() {
//use a large timeout in order to be reactive
final long timeout = TimeUnit.MILLISECONDS.toNanos(100);
assert ((int) timeout) > 0;
assertTrue(timeout > 0);
//it is optimistic: the timeout and the blockingDeviceFlushTime are a perfect match
final long deviceTime = timeout;
final int bufferSize = Env.osPageSize();
Expand All @@ -415,7 +415,7 @@ public void timeoutShouldMatchFlushIOPSWithBlockingFlush() {
//wait the first flush to happen
observer.waitUntilFlushIsDone(1);
//for a blocking flush I'm expecting the TimedBuffer has started sleeping now
assert observer.flushesDone() == 1;
assertEquals(1, observer.flushesDone());
//issue a new write
timedBuffer.addBytes(LONG_ENCODER, true, DummyCallback.getInstance());
//the countdown on the TimedBuffer is already started even before this addBytes
Expand All @@ -424,7 +424,7 @@ public void timeoutShouldMatchFlushIOPSWithBlockingFlush() {
observer.waitUntilFlushIsDone(2);
final long flushDone = System.nanoTime();
final long elapsedTime = flushDone - endOfWriteRequest;
assert observer.flushesDone() == 2;
assertEquals(2, observer.flushesDone());
//it is much more than what is expected!!if it will fail it means that the timed IOPS = 1/(timeout + blockingDeviceFlushTime)!!!!!!
//while it has to be IOPS = 1/timeout
logger.debug("elapsed time: {} with timeout: {}", elapsedTime, timeout);
Expand Down

0 comments on commit cb9e1fe

Please sign in to comment.