Skip to content

Commit

Permalink
More fixes for issues found in SonarCloud
Browse files Browse the repository at this point in the history
Signed-off-by: Gary O'Neall <[email protected]>
  • Loading branch information
goneall committed Sep 2, 2024
1 parent e45de88 commit 748e769
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 86 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/spdx/core/CoreModelObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public abstract class CoreModelObject {

static final String PROPERTY_MSG = "Property ";

private static final String ATTEMPTING_EXTERNAL_MSG = "Attempting to set {0} for an external model object";
private static final String ATTEMPTING_EXTERNAL_MSG = "Attempting to set {} for an external model object";
protected IModelStore modelStore;
protected String objectUri;
protected String specVersion;
Expand Down Expand Up @@ -862,7 +862,7 @@ public CoreModelObject clone(IModelStore modelStore) {
retval.copyFrom(this);
return retval;
} catch (InvalidSPDXAnalysisException e) {
throw new RuntimeException(e);
throw new RuntimeSpdxException(e);
}
}

Expand Down Expand Up @@ -992,7 +992,7 @@ public boolean isStrict() {
/**
* @return the version of the SPDX specification this object complies with
*/
public String getSpecVersion() throws InvalidSPDXAnalysisException {
public String getSpecVersion() {
return this.specVersion;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/spdx/core/DefaultModelStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class DefaultModelStore {

static IModelStore defaultModelStore = null;
static IModelStore defaultStore = null;
static String defaultDocumentUri = "http://www.spdx.org/documents/default_doc_uri_for_SPDX_tools";
static IModelCopyManager defaultCopyManager = null;
static final String NOT_INITIALIZED_MSG = "Default model store has not been initialized";
Expand All @@ -50,10 +50,10 @@ private DefaultModelStore() {
public static IModelStore getDefaultModelStore() throws DefaultStoreNotInitialized {
lock.readLock().lock();
try {
if (Objects.isNull(defaultModelStore)) {
if (Objects.isNull(defaultStore)) {
throw new DefaultStoreNotInitialized(NOT_INITIALIZED_MSG);
}
return defaultModelStore;
return defaultStore;
} finally {
lock.readLock().unlock();
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public static final void initialize(IModelStore newModelStore, String newDefault
Objects.requireNonNull(newDefaultCopyManager, "Copy manager can not be null");
lock.writeLock().lock();
try {
defaultModelStore = newModelStore;
defaultStore = newModelStore;
defaultDocumentUri = newDefaultDocumentUri;
defaultCopyManager = newDefaultCopyManager;
} finally {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/spdx/core/ModelCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public int size() {
try {
return this.modelStore.collectionSize(objectUri, this.propertyDescriptor);
} catch (InvalidSPDXAnalysisException e) {
throw new RuntimeException(e);
throw new RuntimeSpdxException(e);
}
}

Expand All @@ -129,7 +129,7 @@ public boolean isEmpty() {
try {
return this.modelStore.collectionSize(objectUri, this.propertyDescriptor) == 0;
} catch (InvalidSPDXAnalysisException e) {
throw new RuntimeException(e);
throw new RuntimeSpdxException(e);
}
}

Expand All @@ -145,7 +145,7 @@ public boolean contains(Object o) {
return this.modelStore.collectionContains(
objectUri, this.propertyDescriptor, storedObject);
} catch (InvalidSPDXAnalysisException e) {
throw new RuntimeException(e);
throw new RuntimeSpdxException(e);
}
}

Expand All @@ -169,7 +169,7 @@ private Object checkConvertTypedValue(Object value) {
}
return retval;
} catch (InvalidSPDXAnalysisException e) {
throw new RuntimeException(e);
throw new RuntimeSpdxException(e);
}
}

Expand All @@ -195,7 +195,7 @@ public Iterator<Object> iterator() {
return new ModelCollectionIterator(
modelStore.listValues(objectUri, propertyDescriptor));
} catch (InvalidSPDXAnalysisException e) {
throw new RuntimeException(e);
throw new RuntimeSpdxException(e);
}
}

Expand All @@ -216,7 +216,7 @@ public boolean add(Object element) {
objectUri, propertyDescriptor,
ModelObjectHelper.modelObjectToStoredObject(element, modelStore, copyManager, idPrefix));
} catch (InvalidSPDXAnalysisException e) {
throw new RuntimeException(e);
throw new RuntimeSpdxException(e);
}
}

Expand All @@ -226,7 +226,7 @@ public boolean remove(Object element) {
return modelStore.removeValueFromCollection(objectUri, propertyDescriptor,
ModelObjectHelper.modelObjectToStoredObject(element, modelStore, null, null));
} catch (InvalidSPDXAnalysisException e) {
throw new RuntimeException(e);
throw new RuntimeSpdxException(e);
}
}

Expand Down Expand Up @@ -276,7 +276,7 @@ public void clear() {
try {
modelStore.clearValueCollection(objectUri, propertyDescriptor);
} catch (InvalidSPDXAnalysisException e) {
throw new RuntimeException(e);
throw new RuntimeSpdxException(e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/spdx/core/ModelRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ModelRegistry {
* Private constructor - singleton class
*/
private ModelRegistry() {
// Nothing really todo here
// Nothing really to be done here
}

public static ModelRegistry getModelRegistry() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spdx/core/ModelSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public boolean add(Object element) {
try {
lock = this.getModelStore().enterCriticalSection(false);
} catch (InvalidSPDXAnalysisException e) {
throw new RuntimeException(e);
throw new RuntimeSpdxException(e);
}
try {
if (!super.contains(element)) {
Expand All @@ -82,7 +82,7 @@ public boolean addAll(Collection c) {
try {
lock = this.getModelStore().enterCriticalSection(false);
} catch (InvalidSPDXAnalysisException e) {
throw new RuntimeException(e);
throw new RuntimeSpdxException(e);
}
try {
boolean retval = false;
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/org/spdx/core/RuntimeSpdxException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) 2024 Source Auditor Inc.
*/
package org.spdx.core;

/**
* Runtime Exception wrapper for SPDX exceptions (cause field)
*
* @author Gary O'Neall
*
*/
public class RuntimeSpdxException extends RuntimeException {


/**
*
*/
private static final long serialVersionUID = 1L;

/**
* @param message exception message
*/
public RuntimeSpdxException(String message) {
super(message);
}

/**
* @param cause SPDX analysis cause
*/
public RuntimeSpdxException(InvalidSPDXAnalysisException cause) {
super(cause);
}

/**
* @param message exception message
* @param cause SPDX analysis cause
*/
public RuntimeSpdxException(String message, InvalidSPDXAnalysisException cause) {
super(message, cause);
}

/**
* @param message exception message
* @param cause SPDX analysis cause
* @param enableSuppression
* @param writableStackTrace
*/
public RuntimeSpdxException(String message, Throwable cause,
boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/spdx/core/SimpleUriValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Object toModelObject(IModelStore store, IModelCopyManager copyManager,
} else {
retval = ModelRegistry.getModelRegistry().getExternalElement(store, uri, copyManager, type, specVersion);
if (Objects.isNull(retval)) {
logger.warn("{0} does not match an enum, individual, or external pattern", this.getIndividualURI());
logger.warn("{} does not match an enum, individual, or external pattern", this.getIndividualURI());
retval = this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@
*/
package org.spdx.licenseTemplate;


import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.spdx.licenseTemplate.LicenseTemplateRule.RuleType;

Expand All @@ -38,33 +33,6 @@ public class TestLicenseTemplateRule {
static final String RULE_ORIGINAL = "Copyright (c) <year> <owner>\nAll rights reserved.";
static final String RULE_MATCH = "Copyright \\(c\\) .+All rights reserved.";
static final String RULE_EXAMPLE = "Copyright (C) 2013 John Doe\nAll rights reserved.";
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}

/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
}

/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
}

/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}

@Test
public void testparseLicenseTemplateRule() throws LicenseTemplateRuleException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.spdx.licenseTemplate.LicenseTemplateRule.RuleType;

Expand Down Expand Up @@ -121,33 +117,6 @@ public void completeParsing() {
";original=original;match=.+this>>"+
"<<beginOptional;name="+PARSE_OPTIONAL_RULE_NAME+
">>"+PARSE_OPTIONAL_TEXT+"<<endOptional>>";
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}

/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
}

/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
}

/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}

/**
* Test method for {@link org.spdx.licenseTemplate.SpdxLicenseTemplateHelper#templateTextToHtml(java.lang.String)}.
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/spdx/storage/MockModelStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public class MockModelStore implements IModelStore {

@Override
public void unlock() {

// ignore - nothing to do
}

};

@Override
public void close() throws Exception {

// ignore - nothing to do
}

@Override
Expand Down Expand Up @@ -104,7 +104,7 @@ public IModelStoreLock enterCriticalSection(boolean readLockRequested)

@Override
public void leaveCriticalSection(IModelStoreLock lock) {

// ignore - nothing to do
}

@Override
Expand Down Expand Up @@ -207,7 +207,7 @@ public Optional<TypedValue> getTypedValue(String objectUri)

@Override
public void delete(String objectUri) throws InvalidSPDXAnalysisException {

// ignore - nothing to do
}

@Override
Expand Down

0 comments on commit 748e769

Please sign in to comment.