Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOJIRA: remove redundant throws; use parameterized logs #922

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -50,7 +49,7 @@ public AMSessionDeserializer(final Class<?> vc) {

@Override
public AMSession deserialize(final JsonParser jp, final DeserializationContext ctxt)
throws IOException, JsonProcessingException {
throws IOException {

JsonNode node = jp.getCodec().readTree(jp);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static SearchClause getPrimitiveSearchClause(final SearchCondition<Searc
reduce(sc.getCondition().get(property), (s, v) -> s.replace(v, ENCODINGS.getKey(v)));
clause.setValue(value);

LOG.debug("Condition: " + sc.getCondition());
LOG.debug("Condition: {}", sc.getCondition());

if (SpecialAttr.ROLES.toString().equals(property)) {
clause.setType(SearchClause.Type.ROLE_MEMBERSHIP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static SyncopeClientCompositeException checkSyncopeClientCompositeExcept
try {
exceptionType = ClientExceptionType.fromHeaderValue(exTypeAsString);
} catch (IllegalArgumentException e) {
LOG.error("Unexpected value of " + RESTHeaders.ERROR_CODE + ": " + exTypeAsString, e);
LOG.error("Unexpected value of " + RESTHeaders.ERROR_CODE + ": {}", exTypeAsString, e);
}
if (exceptionType != null) {
handledExceptions.add(exTypeAsString);
Expand All @@ -136,7 +136,7 @@ private static SyncopeClientCompositeException checkSyncopeClientCompositeExcept

exTypesInHeaders.removeAll(handledExceptions);
if (!exTypesInHeaders.isEmpty()) {
LOG.error("Unmanaged exceptions: " + exTypesInHeaders);
LOG.error("Unmanaged exceptions: {}", exTypesInHeaders);
}
} else {
for (ErrorTO error : errors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ private void retry(

completionStage.whenComplete((response, throwable) -> {
if (throwable == null && response.getStatus() < 300) {
LOG.info("{} successfully " + action + "ed", service);
LOG.info("{} successfully {}ed", service, action);
} else {
LOG.error("Could not " + action + " {}", service, throwable);
LOG.error("Could not {} {}", action, service, throwable);

handleRetry(service, action, retries, backOffExecution);
}
}).exceptionally(throwable -> {
LOG.error("Could not " + action + " {}", service, throwable);
LOG.error("Could not {} {}", action, service, throwable);

handleRetry(service, action, retries, backOffExecution);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ protected void refresh(final HttpClient client, final String serviceAddress) {

@PreAuthorize("hasRole('" + AMEntitlement.WA_CONFIG_PUSH + "')")
public void pushToWA(final WAConfigService.PushSubject subject, final List<String> services) {
HttpClient client = HttpClient.newHttpClient();
try {
try (HttpClient client = HttpClient.newHttpClient()) {
serviceOps.list(NetworkService.Type.WA).stream().
filter(wa -> CollectionUtils.isEmpty(services) || services.contains(wa.getAddress())).
forEach(wa -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public String getFormat(final String key, final MailTemplateFormat format) {
? mailTemplate.getHTMLTemplate()
: mailTemplate.getTextTemplate();
if (StringUtils.isBlank(template)) {
LOG.error("Could not find mail template '" + key + "' in " + format + " format");
LOG.error("Could not find mail template '{}' in {} format", key, format);

throw new NotFoundException(key + " in " + format);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public ReportTO create(final ReportTO reportTO) {
AuthContextUtils.getUsername(),
false);
} catch (Exception e) {
LOG.error("While registering job for report " + report.getKey(), e);
LOG.error("While registering job for report {}", report.getKey(), e);

SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
sce.getElements().add(e.getMessage());
Expand All @@ -124,7 +124,7 @@ public ReportTO update(final ReportTO reportTO) {
AuthContextUtils.getUsername(),
false);
} catch (Exception e) {
LOG.error("While registering job for report " + report.getKey(), e);
LOG.error("While registering job for report {}", report.getKey(), e);

SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
sce.getElements().add(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public String getAnyLayout(final String key) {

String consoleLayout = role.getAnyLayout();
if (StringUtils.isBlank(consoleLayout)) {
LOG.error("Could not find console layout for Role '" + key + '\'');
LOG.error("Could not find console layout for Role '{}'", key);

throw new NotFoundException("Console layout for role " + key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public SecurityQuestionTO readByUser(final String username) {
orElseThrow(() -> new NotFoundException("User " + username));

if (user.getSecurityQuestion() == null) {
LOG.error("Could not find security question for user '" + username + '\'');
LOG.error("Could not find security question for user '{}'", username);

throw new NotFoundException("Security question for user " + username);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public <T extends SchedTaskTO> T createSchedTask(final TaskType type, final T ta
false,
Map.of());
} catch (Exception e) {
LOG.error("While registering job for task " + task.getKey(), e);
LOG.error("While registering job for task {}", task.getKey(), e);

SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
sce.getElements().add(e.getMessage());
Expand Down Expand Up @@ -195,7 +195,7 @@ public <T extends SchedTaskTO> T updateSchedTask(final TaskType type, final Sche
false,
Map.of());
} catch (Exception e) {
LOG.error("While registering job for task " + task.getKey(), e);
LOG.error("While registering job for task {}", task.getKey(), e);

SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
sce.getElements().add(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;

public abstract class AbstractXMLContentLoader implements ContentLoader {

Expand All @@ -53,7 +51,7 @@ public int getOrder() {
protected abstract void createIndexes(String domain) throws IOException;

protected SAXParser saxParser()
throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException, SAXException {
throws ParserConfigurationException, SAXException {

SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ protected boolean matches(final Any<?> any, final AttrCond cond, final boolean n
validator.validate(schema, cond.getExpression(), attrValue);
}
} catch (ValidationException e) {
LOG.error("Could not validate expression '" + cond.getExpression() + '\'', e);
LOG.error("Could not validate expression '{}'", cond.getExpression(), e);
return false;
}

Expand Down Expand Up @@ -469,7 +469,7 @@ protected boolean matches(final Any<?> any, final AnyCond cond, final boolean no
try {
validator.validate(schema, cond.getExpression(), attrValue);
} catch (ValidationException e) {
LOG.error("Could not validate expression '" + cond.getExpression() + '\'', e);
LOG.error("Could not validate expression '{}'", cond.getExpression(), e);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected boolean isValid(final PlainAttrValue value, final ConstraintValidatorC
isValid = nonNullVales == 1;

if (!isValid) {
LOG.error("More than one non-null value for " + value);
LOG.error("More than one non-null value for {}", value);

context.buildConstraintViolationWithTemplate(
AbstractValidator.getTemplate(EntityViolationType.MoreThanOneNonNull,
Expand All @@ -104,8 +104,8 @@ protected boolean isValid(final PlainAttrValue value, final ConstraintValidatorC
isValid = uniqueValueSchema.equals(attrSchema);

if (!isValid) {
LOG.error("Unique value schema for " + value + " is " + uniqueValueSchema
+ ", while owning attribute's schema is " + attrSchema);
LOG.error("Unique value schema for {} is {}, while owning attribute's schema is {}",
value, uniqueValueSchema, attrSchema);

context.buildConstraintViolationWithTemplate(
AbstractValidator.getTemplate(EntityViolationType.InvalidPlainAttr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean isValid(final PropagationTask task, final ConstraintValidatorCont
try {
ExecStatus.valueOf(execution.getStatus());
} catch (IllegalArgumentException e) {
LOG.error("Invalid execution status '" + execution.getStatus() + '\'', e);
LOG.error("Invalid execution status '{}'", execution.getStatus(), e);
isValid = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public boolean isValid(final Report report, final ConstraintValidatorContext con
try {
CronExpression.parse(report.getCronExpression());
} catch (IllegalArgumentException e) {
LOG.error("Invalid cron expression '" + report.getCronExpression() + '\'', e);
LOG.error("Invalid cron expression '{}'", report.getCronExpression(), e);
isValid = false;

context.disableDefaultConstraintViolation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public boolean isValid(final SchedTask task, final ConstraintValidatorContext co
try {
CronExpression.parse(task.getCronExpression());
} catch (IllegalArgumentException e) {
LOG.error("Invalid cron expression '" + task.getCronExpression() + '\'', e);
LOG.error("Invalid cron expression '{}'", task.getCronExpression(), e);
isValid = false;

context.disableDefaultConstraintViolation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static boolean isExpressionValid(final String expression) {
getJexlEngine().createExpression(expression);
result = true;
} catch (JexlException e) {
LOG.error("Invalid JEXL expression: " + expression, e);
LOG.error("Invalid JEXL expression: {}", expression, e);
Dismissed Show dismissed Hide dismissed
result = false;
}

Expand All @@ -122,7 +122,7 @@ public static Object evaluateExpr(final String expression, final JexlContext jex
JexlExpression jexlExpression = getJexlEngine().createExpression(expression);
result = jexlExpression.evaluate(jexlContext);
} catch (Exception e) {
LOG.error("Error while evaluating JEXL expression: " + expression, e);
LOG.error("Error while evaluating JEXL expression: {}", expression, e);
Dismissed Show dismissed Hide dismissed
}
} else {
LOG.debug("Expression not provided or invalid context");
Expand All @@ -140,7 +140,7 @@ public static String evaluateTemplate(final String template, final JexlContext j
getJxltEngine().createTemplate(template).evaluate(jexlContext, writer);
result = writer.toString();
} catch (Exception e) {
LOG.error("Error while evaluating JEXL template: " + template, e);
LOG.error("Error while evaluating JEXL template: {}", template, e);
}
} else {
LOG.debug("Template not provided or invalid context");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,8 @@ public Pair<URI, ConnectorInfo> getConnectorInfo(final ConnInstance connInstance
connInstance.getBundleName(), connInstance.getVersion(), connInstance.getConnectorName());

if (LOG.isDebugEnabled()) {
LOG.debug("\nBundle name: " + key.getBundleName()
+ "\nBundle version: " + key.getBundleVersion()
+ "\nBundle class: " + key.getConnectorName());
LOG.debug("\nBundle name: {}\nBundle version: {}\nBundle class: {}",
key.getBundleName(), key.getBundleVersion(), key.getConnectorName());
}

// get the specified connector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,15 +559,11 @@ public Pair<String, Attribute> prepareAttr(
schemaType = intValues.getLeft();
List<PlainAttrValue> values = intValues.getRight();

LOG.debug("Define mapping for: "
+ "\n* ExtAttrName " + item.getExtAttrName()
+ "\n* is connObjectKey " + item.isConnObjectKey()
+ "\n* is password " + item.isPassword()
+ "\n* mandatory condition " + item.getMandatoryCondition()
+ "\n* Schema " + intAttrName.getSchema()
+ "\n* ClassType " + schemaType.getType().getName()
+ "\n* AttrSchemaType " + schemaType
+ "\n* Values " + values);
LOG.debug("Define mapping for: \n* ExtAttrName {}\n* is connObjectKey {}\n"
+ "* is password {}\n* mandatory condition {}\n* Schema {}\n"
+ "* ClassType {}\n* AttrSchemaType {}\n* Values {}",
item.getExtAttrName(), item.isConnObjectKey(), item.isPassword(), item.getMandatoryCondition(),
intAttrName.getSchema(), schemaType.getType().getName(), schemaType, values);

Pair<String, Attribute> result;
if (readOnlyVirSchema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private void checkMandatory(
&& !schema.isReadonly()
&& JexlUtils.evaluateMandatoryCondition(schema.getMandatoryCondition(), any, derAttrHandler)) {

LOG.error("Mandatory schema " + schema.getKey() + " not provided with values");
LOG.error("Mandatory schema {} not provided with values", schema.getKey());

reqValMissing.getElements().add(schema.getKey());
}
Expand Down Expand Up @@ -517,8 +517,8 @@ protected void fill(
any.getAuxClasses().remove(auxClass);
}
},
() -> LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...",
patch.getValue()));
() -> LOG.debug("Invalid {} {}, ignoring...",
AnyTypeClass.class.getSimpleName(), patch.getValue()));
}

// 2. resources
Expand All @@ -535,8 +535,8 @@ protected void fill(
any.getResources().remove(resource);
}
},
() -> LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...",
patch.getValue()));
() -> LOG.debug("Invalid {} {}, ignoring...",
ExternalResource.class.getSimpleName(), patch.getValue()));
}

Set<ExternalResource> resources = anyUtils.getAllResources(any);
Expand All @@ -546,8 +546,7 @@ protected void fill(
anyUR.getPlainAttrs().stream().filter(patch -> patch.getAttr() != null).forEach(patch -> {
PlainSchema schema = getPlainSchema(patch.getAttr().getSchema());
if (schema == null) {
LOG.debug("Invalid " + PlainSchema.class.getSimpleName() + " {}, ignoring...",
patch.getAttr().getSchema());
LOG.debug("Invalid {} {}, ignoring...", PlainSchema.class.getSimpleName(), patch.getAttr().getSchema());
} else {
PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null);
if (attr == null) {
Expand Down Expand Up @@ -620,7 +619,7 @@ protected void fill(
flatMap(Optional::stream).
forEach(auxClass -> {
if (auxClass == null) {
LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", auxClass);
LOG.debug("Invalid {} {}, ignoring...", AnyTypeClass.class.getSimpleName(), auxClass);
} else {
any.add(auxClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void create(final AnyObject anyObject, final AnyObjectCR anyObjectCR) {
} else {
AnyObject otherEnd = anyObjectDAO.findById(relationshipTO.getOtherEndKey()).orElse(null);
if (otherEnd == null) {
LOG.debug("Ignoring invalid anyObject " + relationshipTO.getOtherEndKey());
LOG.debug("Ignoring invalid anyObject {}", relationshipTO.getOtherEndKey());
} else if (relationships.contains(Pair.of(otherEnd.getKey(), relationshipTO.getType()))) {
LOG.error("{} was already in relationship {} with {}",
otherEnd, relationshipTO.getType(), anyObject);
Expand Down Expand Up @@ -266,8 +266,7 @@ public void create(final AnyObject anyObject, final AnyObjectCR anyObjectCR) {
? groupDAO.findByName(membershipTO.getGroupName()).orElse(null)
: groupDAO.findById(membershipTO.getGroupKey()).orElse(null);
if (group == null) {
LOG.debug("Ignoring invalid group "
+ membershipTO.getGroupKey() + " / " + membershipTO.getGroupName());
LOG.debug("Ignoring invalid group {} / {}", membershipTO.getGroupKey(), membershipTO.getGroupName());
} else if (groups.contains(group.getKey())) {
LOG.error("{} was already assigned to {}", group, anyObject);

Expand Down Expand Up @@ -431,8 +430,8 @@ public PropagationByResource<String> update(final AnyObject toBeUpdated, final A
patch.getPlainAttrs().forEach(attrTO -> {
PlainSchema schema = getPlainSchema(attrTO.getSchema());
if (schema == null) {
LOG.debug("Invalid " + PlainSchema.class.getSimpleName()
+ "{}, ignoring...", attrTO.getSchema());
LOG.debug("Invalid {}{}, ignoring...",
PlainSchema.class.getSimpleName(), attrTO.getSchema());
} else {
Optional<? extends APlainAttr> attr =
anyObject.getPlainAttr(schema.getKey(), newMembership);
Expand Down
Loading