Skip to content

Commit

Permalink
Merge pull request #511 from ngeorges-cnrs/java21_warnings
Browse files Browse the repository at this point in the history
Fix build warnings
  • Loading branch information
axlbonnet authored Dec 11, 2024
2 parents 046e67b + d144186 commit a509927
Show file tree
Hide file tree
Showing 31 changed files with 131 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ public SpringWebConfig(Environment env, VipConfigurer vipConfigurer) {
this.vipConfigurer = vipConfigurer;
}

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
// Otherwise all that follow a dot in an URL is considered an extension and removed
// It's a problem for URL like "/pipelines/gate/3.2
// The below will become the default values in Spring 5.3
// Safe to use in 5.2 as long as disabling pattern match
configurer.setUseSuffixPatternMatch(false);
}

@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
// necessary in the content negotiation stuff of carmin data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import fr.insalyon.creatis.vip.datamanager.server.business.TransferPoolBusiness;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.input.ReaderInputStream;
import org.apache.commons.io.input.ReaderInputStream.Builder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -391,8 +392,12 @@ private boolean isOperationOver(String operationId, User user)
private void writeFileFromBase64(String base64Content, String localFilePath) throws ApiException {
Base64.Decoder decoder = Base64.getDecoder();
StringReader stringReader = new StringReader(base64Content);
InputStream inputStream = new ReaderInputStream(stringReader, StandardCharsets.UTF_8);
try (InputStream base64InputStream = decoder.wrap(inputStream)) {
try {
InputStream inputStream = ReaderInputStream.builder()
.setReader(new StringReader(base64Content))
.setCharset(StandardCharsets.UTF_8)
.get();
InputStream base64InputStream = decoder.wrap(inputStream);
Files.copy(base64InputStream, Paths.get(localFilePath));
} catch (IOException e) {
logger.error("Error writing base64 file in {}", localFilePath, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private User getVipUser(Jwt jwt) throws BadCredentialsException {

// Create authorities list from jwt claims.
// Parsing realm_access.roles or resource_access.<resourceName>.roles is Keycloak-specific.
@SuppressWarnings("unchecked")
private List<GrantedAuthority> parseAuthorities(User user, Jwt jwt) {
List<String> roles = new ArrayList<>(); // default to no roles
// At this point, jwt has already been verified by Spring resource server, so we assume the issuer is known (server != null).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class AuthenticationInfoTestUtils {
authenticationInfoSuppliers = getAuthenticationInfoSuppliers();
}

@SuppressWarnings("unchecked")
public static Map<String, Function> getAuthenticationInfoSuppliers() {
return JsonCustomObjectMatcher.formatSuppliers(
Arrays.asList("httpHeader", "httpHeaderValue"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class ErrorCodeAndMessageTestUtils {
errorCodeAndMessageSuppliers = getErrorCodeAndMessageSuppliers();
}

@SuppressWarnings("unchecked")
public static Map<String,Function> getErrorCodeAndMessageSuppliers() {
return JsonCustomObjectMatcher.formatSuppliers(
Arrays.asList("errorCode", "errorMessage"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public static Simulation copySimulationWithNewName(Simulation simu, String newNa
return newSimulation;
}

@SuppressWarnings("unchecked")
public static Map<String,Function> getExecutionSuppliers() {
return JsonCustomObjectMatcher.formatSuppliers(
Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ public static PathProperties getPath(Data data, boolean isDirectory,
return pathProperties;
}

// [WARNING] VIP-portal/vip-api/src/test/java/fr/insalyon/creatis/vip/api/data/PathTestUtils.java:[182,55] unchecked generic array creation for varargs parameter of type java.util.function.Function<fr.insalyon.creatis.vip.api.model.PathProperties,?>[]
@SuppressWarnings("unchecked")
private static Map<String, Function> getPathSuppliers() {
return JsonCustomObjectMatcher.formatSuppliers(
Arrays.asList("path", "lastModificationDate", "isDirectory", "exists",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
/**
* Created by abonnet on 8/3/16.
*/
@SuppressWarnings("unchecked")
public class PipelineTestUtils {

public static final Map<String,Function> pipelineSuppliers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ public void setUp() throws Exception {
}

@Test
@SuppressWarnings("unchecked")
public void shouldListExecutions() throws Exception {
when(workflowDAO.get(eq(simulation1.getID()))).thenReturn(w1, null);
when(workflowDAO.get(eq(simulation2.getID()))).thenReturn(w2, null);
when(workflowDAO.get(eq(simulation1.getID()))).thenReturn(w1, (Workflow) null);
when(workflowDAO.get(eq(simulation2.getID()))).thenReturn(w2, (Workflow) null);
when(workflowDAO.get(Collections.singletonList(baseUser1.getFullName()), null, null, null, null, null, null))
.thenReturn(Arrays.asList(w1, w2), null);
.thenReturn(Arrays.asList(w1, w2), (List<Workflow>) null);

// perform a getWorkflows()
mockMvc.perform(
Expand All @@ -106,9 +107,10 @@ public void shouldListExecutions() throws Exception {
}

@Test
@SuppressWarnings("unchecked")
public void shouldCountExecutions() throws Exception {
when(workflowDAO.get(Collections.singletonList(baseUser1.getFullName()), null, null, null, null, null, null))
.thenReturn(Arrays.asList(w1, w2), null);
.thenReturn(Arrays.asList(w1, w2), (List<Workflow>) null);

// perform a getWorkflows()
mockMvc.perform(
Expand Down Expand Up @@ -315,12 +317,13 @@ public void testPlayExecutionIsNotImplemented() throws Exception {
}

@Test
@SuppressWarnings("unchecked")
public void shouldGetExecution2Results() throws Exception {
String resultPath = "/root/user/user1/path/to/result.res";

when(workflowDAO.get(eq(simulation2.getID()))).thenReturn(w2, null);
when(workflowDAO.get(eq(simulation2.getID()))).thenReturn(w2, (Workflow) null);
Output output = new Output(new OutputID("workflowID", resultPath, "processor"), DataType.URI, "port");
when(outputDAO.get(eq(simulation2.getID()))).thenReturn(Arrays.asList(output), null);
when(outputDAO.get(eq(simulation2.getID()))).thenReturn(Arrays.asList(output), (List<Output>) null);

Mockito.when(server.getDataManagerUsersHome()).thenReturn("/root/user");
Mockito.when(gridaClient.exist(resultPath)).thenReturn(true);
Expand Down Expand Up @@ -351,6 +354,7 @@ public void shouldKillExecution2() throws Exception
}

@Test
@SuppressWarnings("unchecked")
public void testInitGwendiaExecution() throws Exception
{
String appName = "test application", groupName = "testGroup", className = "testClass", versionName = "4.2";
Expand Down Expand Up @@ -421,6 +425,7 @@ public void testInitGwendiaExecution() throws Exception

// the difference (at the moment) is that with moteurLite the optional and absent parameters are not included
@Test
@SuppressWarnings("unchecked")
public void testInitBoutiquesExecution() throws Exception
{
String appName = "test application", groupName = "testGroup", className = "testClass", versionName = "4.2";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public JsonCustomObjectMatcher(T expectedBean,
this(expectedBean, suppliers, new HashMap<>());
}

@SuppressWarnings("unchecked")
public JsonCustomObjectMatcher(T expectedBean,
Map<String, Function> suppliers,
Map<Class,Map<String,Function>> suppliersRegistry) {
Expand All @@ -88,6 +89,7 @@ public JsonCustomObjectMatcher(T expectedBean,
nonNullPropertiesCountMatcher = equalTo(propertyMatchers.size());
}

@SuppressWarnings("unchecked")
private static Matcher<?> getGenericMatcher(
Object expectedValue,
Map<Class, Map<String, Function>> suppliersRegistry) {
Expand Down Expand Up @@ -133,6 +135,7 @@ private static Matcher<?> getGenericMatcher(
}
}

@SuppressWarnings("unchecked")
private static Matcher<Map<String, ?>> getCustomObjectMatcherFromRegistry(
Object o,
Map<Class, Map<String, Function>> suppliersRegistry) {
Expand All @@ -157,6 +160,7 @@ public static <T> Matcher<Map<String,?>> jsonCorrespondsTo(
return new JsonCustomObjectMatcher<T>(expectedBean, suppliers, suppliersRegistry);
}

@SuppressWarnings("unchecked")
public static <T> Map<String, Function> formatSuppliers(
List<String> mapKeys, Function<T,?>... suppliers) {
if (mapKeys.size() != suppliers.length) {
Expand Down Expand Up @@ -207,6 +211,7 @@ private static class JsonMapMatcher extends TypeSafeDiagnosingMatcher<Map<String
private final Matcher<Integer> sizeMatcher;
private final List<Matcher<?>> mapEntriesMatchers = new ArrayList<>();

@SuppressWarnings("unchecked")
private JsonMapMatcher(
Map<?, ?> expectedMap,
Map<Class, Map<String, Function>> suppliersRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void configureForm() {
chartsItem.addChangedHandler(new ChangedHandler() {
@Override
public void onChanged(ChangedEvent event) {
int value = new Integer(chartsItem.getValueAsString());
int value = Integer.parseInt(chartsItem.getValueAsString());
if (value == 1 || value == 2 || value == 6) {
binItem.setDisabled(true);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ private void configureForm() {
chartsItem.setWidth(250);
chartsItem.setValueMap(chartsMap);
chartsItem.setEmptyDisplayValue("Select a chart...");
chartsItem.addChangedHandler(new ChangedHandler() {

@Override
public void onChanged(ChangedEvent event) {
int value = new Integer(chartsItem.getValueAsString());
}
});

generateButton = WidgetUtil.getIButton("Get Stats", null, new ClickHandler() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void build(String caption, String color, int binSize) {
max = localMax;
}
if (res.length > 4) {
sum += new Integer(res[4]);
sum += Integer.parseInt(res[4]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ private Map<String, String> mapOutputDataPathsByFilenames(List<String> outputDat
return outputDataMap;
}

@SuppressWarnings("unchecked")
private Map<String, String> getOutputFilenamesFromProvenanceFile(Path provenanceFilePath) throws BusinessException {
try {
Map<?, ?> map = new ObjectMapper().readValue(provenanceFilePath.toFile(), Map.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.*;
Expand Down Expand Up @@ -390,7 +391,7 @@ public Descriptor getApplicationDescriptor(
}
return getGwendiaParser().parse(workflowPath);

} catch (SAXException | IOException ex) {
} catch (SAXException | ParserConfigurationException | IOException ex) {
logger.error("Error getting application descriptor for {}/{}", applicationName, applicationVersion, ex);
throw new BusinessException(WRONG_APPLICATION_DESCRIPTOR, ex, applicationName + "/" + applicationVersion);
} catch (DAOException | BusinessException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
Expand All @@ -61,16 +63,18 @@ protected AbstractWorkflowParser() {
sources = new ArrayList<Source>();
}

public Descriptor parse(String fileName) throws IOException, SAXException {
public Descriptor parse(String fileName) throws IOException, SAXException, ParserConfigurationException {
return parse(new FileReader(fileName));
}

public Descriptor parseString(String workflowString) throws IOException, SAXException {
public Descriptor parseString(String workflowString) throws IOException, SAXException, ParserConfigurationException {
return parse(new StringReader(workflowString));
}

private Descriptor parse(Reader workflowReader) throws IOException, SAXException {
reader = XMLReaderFactory.createXMLReader();
private Descriptor parse(Reader workflowReader) throws IOException, SAXException, ParserConfigurationException {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
reader = parserFactory.newSAXParser().getXMLReader();
reader.setContentHandler(this);
reader.parse(new InputSource(workflowReader));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;

/**
* Parse a m2 input file.
*
Expand Down Expand Up @@ -93,13 +96,15 @@ public Map<String, String> parse(String fileName)
throws BusinessException {

try {
XMLReader reader = XMLReaderFactory.createXMLReader();
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
XMLReader reader = parserFactory.newSAXParser().getXMLReader();
reader.setContentHandler(this);
reader.parse(new InputSource(new FileReader(fileName)));

return inputs;

} catch (IOException | SAXException ex) {
} catch (IOException | SAXException | ParserConfigurationException ex) {
logger.error("Error parsing {}", fileName, ex);
throw new BusinessException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;

/**
* Parse a input file.
*
Expand All @@ -69,13 +72,15 @@ public InputParser() {

public String parse(String fileName) throws BusinessException {
try {
reader = XMLReaderFactory.createXMLReader();
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
reader = parserFactory.newSAXParser().getXMLReader();
reader.setContentHandler(this);
reader.parse(new InputSource(new FileReader(fileName)));

return inputs.toString();

} catch (IOException | SAXException ex) {
} catch (IOException | SAXException | ParserConfigurationException ex) {
logger.error("Error parsing file {}", fileName, ex);
throw new BusinessException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.slf4j.LoggerFactory;

import jakarta.servlet.ServletException;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*/
package localhost.moteur_service_wsdl;

import java.net.URISyntaxException;

public class Moteur_ServiceLocator extends org.apache.axis.client.Service implements localhost.moteur_service_wsdl.Moteur_Service {

/**
Expand Down Expand Up @@ -71,9 +73,11 @@ public void setmoteur_serviceWSDDServiceName(java.lang.String name) {
public localhost.moteur_service_wsdl.Moteur_servicePortType getmoteur_service() throws javax.xml.rpc.ServiceException {
java.net.URL endpoint;
try {
endpoint = new java.net.URL(moteur_service_address);
endpoint = new java.net.URI(moteur_service_address).toURL();
} catch (java.net.MalformedURLException e) {
throw new javax.xml.rpc.ServiceException(e);
} catch (URISyntaxException e) {
throw new javax.xml.rpc.ServiceException(e);
}
return getmoteur_service(endpoint);
}
Expand All @@ -100,7 +104,7 @@ public void setmoteur_serviceEndpointAddress(java.lang.String address) {
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
try {
if (localhost.moteur_service_wsdl.Moteur_servicePortType.class.isAssignableFrom(serviceEndpointInterface)) {
localhost.moteur_service_wsdl.Moteur_BindingStub _stub = new localhost.moteur_service_wsdl.Moteur_BindingStub(new java.net.URL(moteur_service_address), this);
localhost.moteur_service_wsdl.Moteur_BindingStub _stub = new localhost.moteur_service_wsdl.Moteur_BindingStub(new java.net.URI(moteur_service_address).toURL(), this);
_stub.setPortName(getmoteur_serviceWSDDServiceName());
return _stub;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public void shouldNotIncludePrivateGroupsAndClasses() throws BusinessException,
Group privateGroup = new Group("private group", false, true, true);
// classes are not really public/private, but they are linked to public/private groups
// a class is considered private if it is linked only to private groups
AppClass publicClass = new AppClass("public class", Collections.EMPTY_LIST, Collections.singletonList(publicGroup.getName()));
AppClass privateClass = new AppClass("private class", Collections.EMPTY_LIST, Collections.singletonList(privateGroup.getName()));
AppClass publicClass = new AppClass("public class", Collections.emptyList(), Collections.singletonList(publicGroup.getName()));
AppClass privateClass = new AppClass("private class", Collections.emptyList(), Collections.singletonList(privateGroup.getName()));
Application app = new Application("testApp", Arrays.asList(publicClass.getName(), privateClass.getName()), "");
AppVersion appVersion = new AppVersion(app.getName(), "", null, null, true, false);
// persist data in database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.spec.InvalidKeySpecException;
Expand Down Expand Up @@ -139,7 +140,7 @@ protected void checkValidRequest(HttpServletRequest request) throws BusinessExce
logger.error("Error with SAML assertion {} : audience is not valid", new String(xmlAssertion));
throw new BusinessException("Assertion audience is not valid!");
}
} catch (MalformedURLException ex) {
} catch (MalformedURLException | URISyntaxException ex) {
logger.error("Error with SAML assertion {}", new String(xmlAssertion), ex);
throw new BusinessException(ex);
}
Expand Down
Loading

0 comments on commit a509927

Please sign in to comment.