Skip to content

Commit

Permalink
Fix a bunch of issues the new PMD is reporting, many more to go
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Jul 9, 2019
1 parent c09877e commit 7815364
Show file tree
Hide file tree
Showing 24 changed files with 70 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void cache(Message message) throws IOException {
cache = new CachedOutputStream();
AttachmentUtil.setStreamedAttachmentProperties(message, cache);
try {
IOUtils.copy(ins, cache);
IOUtils.copyAndCloseInput(ins, cache);
cache.lockOutputStream();
if (delegate != null) {
delegate.setInputStream(cache.getInputStream());
Expand All @@ -61,11 +61,6 @@ public void cache(Message message) throws IOException {
cache = null;
throw cee;
} finally {
try {
ins.close();
} catch (Exception ex) {
//ignore
}
ins = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public void getRealLambdaClassPropertyWasNotSetInBus() {
EasyMock.verify(bus);
}

@Test
public void getRealLambdaClassPropertyWasSetInBus() {
EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(true);
EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.service.invoker.BeanInvoker;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertTrue;
Expand All @@ -45,6 +46,7 @@ public class ExceptionInheritanceTest extends AbstractAegisTest {
private WS1 client;
private Map<String, Object> props;

@Before
public void setUp() throws Exception {
super.setUp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.apache.ws.commons.schema.XmlSchemaSequenceMember;
import org.apache.ws.commons.schema.constants.Constants;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
Expand All @@ -63,6 +64,7 @@ public class BeanTest extends AbstractAegisTest {
TypeMapping mapping;
private AegisContext context;

@Before
public void setUp() throws Exception {
super.setUp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import org.apache.cxf.aegis.services.DataService;
import org.apache.cxf.wsdl.WSDLConstants;

import org.junit.Before;
import org.junit.Test;

public class ByteDataTest extends AbstractAegisTest {
@Before
public void setUp() throws Exception {
super.setUp();
createService(DataService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.cxf.aegis.type.TypeMapping;
import org.apache.cxf.aegis.xml.stax.ElementReader;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
Expand All @@ -37,6 +38,7 @@
public class DynamicProxyTest extends AbstractAegisTest {
TypeMapping mapping;

@Before
public void setUp() throws Exception {
super.setUp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
import org.apache.cxf.aegis.type.TypeMapping;
import org.apache.ws.commons.schema.constants.Constants;

import org.junit.Before;
import org.junit.Test;

public class QualificationTest extends AbstractAegisTest {

@Before
public void setUp() throws Exception {
super.setUp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.ws.commons.schema.constants.Constants;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertSame;
Expand All @@ -40,6 +41,7 @@ public class ArrayTypeInfoTest extends AbstractAegisTest {
private TypeMapping mapping;
private StructType addressType;

@Before
public void setUp() throws Exception {
super.setUp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.cxf.aegis.type.basic.BeanTypeInfo;
import org.apache.cxf.aegis.xml.stax.ElementReader;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertArrayEquals;
Expand All @@ -48,6 +49,7 @@ public class SoapArrayTypeTest extends AbstractEncodedTest {
},
};

@Before
public void setUp() throws Exception {
super.setUp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.cxf.aegis.xml.stax.ElementReader;
import org.apache.cxf.helpers.DOMUtils;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
Expand All @@ -49,6 +50,7 @@ private Context getLocalContext() {
return new Context(aegisContext);
}

@Before
public void setUp() throws Exception {
super.setUp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,29 +749,29 @@ protected void storeMessage(Connection con, Identifier sid, RMMessage msg, boole
new Object[] {outbound ? "outbound" : "inbound", nr, id, to});
}
PreparedStatement stmt = null;
CachedOutputStream cos = msg.getContent();
InputStream msgin = null;
try {
msgin = cos.getInputStream();
stmt = getStatement(con, outbound ? CREATE_OUTBOUND_MESSAGE_STMT_STR : CREATE_INBOUND_MESSAGE_STMT_STR);

stmt.setString(1, id);
stmt.setLong(2, nr);
stmt.setString(3, to);
stmt.setLong(4, msg.getCreatedTime());
stmt.setBinaryStream(5, msgin);
stmt.setString(6, contentType);
stmt.execute();
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Successfully stored {0} message number {1} for sequence {2}",
new Object[] {outbound ? "outbound" : "inbound", nr, id});
}
} finally {
releaseResources(stmt, null);
if (null != msgin) {
msgin.close();
try (CachedOutputStream cos = msg.getContent()) {
InputStream msgin = null;
try {
msgin = cos.getInputStream();
stmt = getStatement(con, outbound ? CREATE_OUTBOUND_MESSAGE_STMT_STR : CREATE_INBOUND_MESSAGE_STMT_STR);

stmt.setString(1, id);
stmt.setLong(2, nr);
stmt.setString(3, to);
stmt.setLong(4, msg.getCreatedTime());
stmt.setBinaryStream(5, msgin);
stmt.setString(6, contentType);
stmt.execute();
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Successfully stored {0} message number {1} for sequence {2}",
new Object[] {outbound ? "outbound" : "inbound", nr, id});
}
} finally {
releaseResources(stmt, null);
if (null != msgin) {
msgin.close();
}
}
cos.close(); // needed to clean-up tmp file folder
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void tearDown() {
rq = null;
}

void setUpSource() {
protected void setUpSource() {
source = control.createMock(Source.class);
manager = control.createMock(RMManager.class);
EasyMock.expect(source.getManager()).andReturn(manager).anyTimes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class WSDLServiceBuilderTest {

private DestinationFactoryManager destinationFactoryManager;

public void setUpBasic() throws Exception {
protected void setUpBasic() throws Exception {
setUpWSDL(WSDL_PATH, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void testSequentialStrategyWithDiffBaseAddresses() throws Exception {
getFeature(false, Server.ADDRESS3, null);
strategyTest(Server.ADDRESS1, feature, Server.ADDRESS3, Server.ADDRESS2, false, false, false);
}

@Test
public void testSequentialStrategyWithDiffBaseAddresses2() throws Exception {
FailoverFeature feature =
getFeature(false, Server.ADDRESS3, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ public static void cleanUp() {

//methods that a subclass can override to inject a Proxy into the flow
//and assert the proxy was appropriately called
public void configureProxy(Client c) {
protected void configureProxy(Client c) {
}
public void resetProxyCount() {
protected void resetProxyCount() {
}
public void assertProxyRequestCount(int i) {
protected void assertProxyRequestCount(int i) {
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static void setupPorts() {
BusServer.resetPortMap();
}

public void startServers() throws Exception {
protected void startServers() throws Exception {
assertTrue(
"Server failed to launch",
// run the server in the same process
Expand All @@ -83,7 +83,7 @@ public void startServers() throws Exception {
}


public void stopServers() throws Exception {
protected void stopServers() throws Exception {
stopAllServers();
System.clearProperty(Configurer.USER_CFG_FILE_PROPERTY_URL);
BusFactory.setDefaultBus(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ public static TrustManager[] getTrustManagers(KeyStore keyStore)

//methods that a subclass can override to inject a Proxy into the flow
//and assert the proxy was appropriately called
public void configureProxy(Client c) {
protected void configureProxy(Client c) {
}
public void resetProxyCount() {
protected void resetProxyCount() {
}
public void assertProxyRequestCount(int i) {
protected void assertProxyRequestCount(int i) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void setTheConfiguration(String config) {
}
}

public void startServers() throws Exception {
protected void startServers() throws Exception {
assertTrue(
"Server failed to launch",
// run the server in the same process
Expand All @@ -77,7 +77,7 @@ public void startServers() throws Exception {
}


public void stopServers() throws Exception {
protected void stopServers() throws Exception {
stopAllServers();
System.clearProperty(Configurer.USER_CFG_FILE_PROPERTY_URL);
BusFactory.setDefaultBus(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public abstract class AbstractTypeTestClient

protected boolean perfTestOnly;

public void setPerformanceTestOnly() {
protected void setPerformanceTestOnly() {
perfTestOnly = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void testRecovery() throws Exception {
verifyRecovery();
}

void startClient() throws Exception {
protected void startClient() throws Exception {
LOG.fine("Creating greeter client");
System.setProperty("db.name", getPrefix() + "-client");
SpringBusFactory bf = new SpringBusFactory();
Expand All @@ -163,7 +163,7 @@ void startClient() throws Exception {
bus.getInInterceptors().add(in);
}

void populateStore() throws Exception {
protected void populateStore() throws Exception {

bus.getExtension(RMManager.class).getConfiguration().setBaseRetransmissionInterval(Long.valueOf(60000));
bus.getOutInterceptors().add(new MessageLossSimulator());
Expand Down Expand Up @@ -198,7 +198,7 @@ void populateStore() throws Exception {
mf.verifyAcknowledgements(new boolean[] {false, true, true}, false);
}

void verifyStorePopulation() {
protected void verifyStorePopulation() {

RMManager manager = bus.getExtension(RMManager.class);
assertNotNull(manager);
Expand All @@ -225,12 +225,12 @@ void verifyStorePopulation() {
assertEquals(0, msgs.size());
}

void stopClient() {
protected void stopClient() {
// ClientProxy.getClient(greeter).destroy();
bus.shutdown(true);
}

void populateStoreAfterRestart() throws Exception {
protected void populateStoreAfterRestart() throws Exception {

bus.getExtension(RMManager.class).getConfiguration().setBaseRetransmissionInterval(Long.valueOf(60000));

Expand Down Expand Up @@ -274,7 +274,7 @@ void populateStoreAfterRestart() throws Exception {
}
}

void recover() throws Exception {
protected void recover() throws Exception {

// do nothing - resends should happen in the background

Expand All @@ -283,7 +283,7 @@ void recover() throws Exception {

}

void verifyRecovery() throws Exception {
protected void verifyRecovery() throws Exception {

RMManager manager = bus.getExtension(RMManager.class);
assertNotNull(manager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void verifyServerRecovery(Response<GreetMeResponse>[] responses) throws Exceptio
}


void verifyRetransmissionQueue() throws Exception {
protected void verifyRetransmissionQueue() throws Exception {
awaitMessages(2, 2, 60000);

int count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ public FaultThrowingInterceptor(String phase) {
super(phase);
}

public synchronized void handleMessage(Message message) throws Fault {
public void handleMessage(Message message) throws Fault {
if (MessageUtils.isRequestor(message)) {
return;
}
String msg = MESSAGE_FORMAT.format(new Object[] {getPhase()});
String msg = null;
synchronized (MESSAGE_FORMAT) {
msg = MESSAGE_FORMAT.format(new Object[] {getPhase()});
}
LOG.fine(msg);
throw new Fault(new RuntimeException(msg));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ package org.apache.cxf.systest.type_test;
* org.apache.type_test.TypeTestTester
*/
public interface TypeTestTester {
void setPerformanceTestOnly();
void testVoid() throws Exception;
Expand Down
Loading

0 comments on commit 7815364

Please sign in to comment.