Skip to content

Commit

Permalink
fix: implicit narrowing conversion in compound assignment
Browse files Browse the repository at this point in the history
Solve the vulnerability raised by CodeQL scanning for the implicit narrowing conversion in compound assignment.

ING-4370
  • Loading branch information
emanuelaepure10 committed Jun 27, 2024
1 parent 39ae68e commit bfedff0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public boolean hasSize() {
*/
@Override
public int size() {
int size = 0;
long size = 0;
DatabaseReference<ODatabaseDocumentTx> ref = database.openRead();
ODatabaseDocumentTx db = ref.getDatabase();
try {
Expand All @@ -244,7 +244,11 @@ public int size() {
ref.dispose();
}

return size;
if (size > Integer.MAX_VALUE) {
throw new IllegalArgumentException("The size exceeds the range of int.");
}

return (int) size;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import java.util.List;
import java.util.Map;

import com.google.common.collect.ListMultimap;
import org.locationtech.jts.geom.Geometry;

import com.google.common.collect.ListMultimap;

import eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition;
import eu.esdihumboldt.hale.common.align.transformation.engine.TransformationEngine;
import eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue;
Expand Down Expand Up @@ -74,7 +75,7 @@ protected Object evaluate(String transformationIdentifier, TransformationEngine

if (geoms.size() > 1) {

int area = 0;
double area = 0;

for (GeometryProperty<?> geoProp : geoms) {
area += geoProp.getGeometry().getArea();
Expand All @@ -93,7 +94,8 @@ protected Object evaluate(String transformationIdentifier, TransformationEngine
return geom.getArea();
}
else {
throw new TransformationException("Geometry for calculate area could not be retrieved.");
throw new TransformationException(
"Geometry for calculate area could not be retrieved.");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import java.util.List;
import java.util.Map;

import com.google.common.collect.ListMultimap;
import org.locationtech.jts.geom.Geometry;

import com.google.common.collect.ListMultimap;

import eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition;
import eu.esdihumboldt.hale.common.align.transformation.engine.TransformationEngine;
import eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue;
Expand All @@ -39,9 +40,9 @@
*
* @author Kevin Mais
*/
public class CalculateLength extends
AbstractSingleTargetPropertyTransformation<TransformationEngine> implements
CalculateLengthFunction {
public class CalculateLength
extends AbstractSingleTargetPropertyTransformation<TransformationEngine>
implements CalculateLengthFunction {

/**
* @see eu.esdihumboldt.hale.common.align.transformation.function.impl.AbstractSingleTargetPropertyTransformation#evaluate(java.lang.String,
Expand Down Expand Up @@ -75,7 +76,7 @@ protected Object evaluate(String transformationIdentifier, TransformationEngine

if (geoms.size() > 1) {

int length = 0;
double length = 0;

for (GeometryProperty<?> geoProp : geoms) {
length += geoProp.getGeometry().getLength();
Expand Down

0 comments on commit bfedff0

Please sign in to comment.