Skip to content
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
6 changes: 6 additions & 0 deletions .github/scripts/generate-quality-report.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,12 @@ def main() -> None:
"REC_CATCH_EXCEPTION",
"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE",
"RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT",
"INT_VACUOUS_COMPARISON",
"DM_STRING_TOSTRING",
"HE_HASHCODE_USE_OBJECT_EQUALS",
"IM_BAD_CHECK_FOR_ODD",
"IT_NO_SUCH_ELEMENT",
"FL_FLOATS_AS_LOOP_COUNTERS",
"UI_INHERITANCE_UNSAFE_GETRESOURCE",
"URF_UNREAD_FIELD",
"URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD",
Expand Down
7 changes: 4 additions & 3 deletions CodenameOne/src/com/codename1/charts/views/PieSegment.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ public boolean isInSegment(double angle) {
double cAngle = angle % 360;
double startAngle = mStartAngle;
double stopAngle = mEndAngle;
while (stopAngle > 360) {
startAngle -= 360;
stopAngle -= 360;
if (stopAngle > 360) {
int rotations = (int) Math.floor(stopAngle / 360d);
startAngle -= 360 * rotations;
stopAngle -= 360 * rotations;
}
return cAngle >= startAngle && cAngle <= stopAngle;
}
Expand Down
5 changes: 3 additions & 2 deletions CodenameOne/src/com/codename1/charts/views/RadarChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint
paint.setColor(ColorUtil.GRAY);
float thisRad = (float) Math.toRadians(90 - currentAngle);
float nextRad = (float) Math.toRadians(90 - (currentAngle + angle));
for (double level = 0; level <= 1d; level += decCoef) { // PMD Fix: DontUseFloatTypeForLoopIndices switched to double
float levelFactor = (float) level;
int levelSteps = (int) Math.round(1d / decCoef);
for (int level = 0; level <= levelSteps; level++) {
float levelFactor = (float) (level * decCoef);
float thisX = (float) (centerX - Math.sin(thisRad) * radius * levelFactor);
float thisY = (float) (centerY - Math.cos(thisRad) * radius * levelFactor);
float nextX = (float) (centerX - Math.sin(nextRad) * radius * levelFactor);
Expand Down
10 changes: 5 additions & 5 deletions CodenameOne/src/com/codename1/io/MultipartRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ protected long calculateContentLength() {
length += key.length();
if (ignoreEncoding.contains(key)) {
try {
length += value.toString().getBytes("UTF-8").length;
length += ((String) value).getBytes("UTF-8").length;
} catch (UnsupportedEncodingException ex) {
length += StringUtil.getBytes(value.toString()).length;
length += StringUtil.getBytes((String) value).length;
}
} else {
if (base64Binaries) {
Expand All @@ -287,9 +287,9 @@ protected long calculateContentLength() {
length += key.length();
if (ignoreEncoding.contains(key)) {
try {
length += s.toString().getBytes("UTF-8").length;
length += s.getBytes("UTF-8").length;
} catch (UnsupportedEncodingException ex) {
length += StringUtil.getBytes(value.toString()).length;
length += StringUtil.getBytes(s).length;
}
} else {
if (base64Binaries) {
Expand Down Expand Up @@ -534,4 +534,4 @@ public int hashCode() {
result = 31 * result + (args != null ? args.hashCode() : 0);
return result;
}
}
}
5 changes: 3 additions & 2 deletions CodenameOne/src/com/codename1/io/rest/RequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* This class is used to build, invoke the http request and to get the http
Expand Down Expand Up @@ -249,8 +250,8 @@ public RequestBuilder queryParam(String key, String[] values) {
*/
public RequestBuilder header(String key, String value) {
checkFetched();
// .toString() is used to trigger an NPE early for null headers
headers.put(key.toString(), value.toString());
headers.put(Objects.requireNonNull(key, "Header key cannot be null"),
Objects.requireNonNull(value, "Header value cannot be null"));
return this;
}

Expand Down
8 changes: 5 additions & 3 deletions CodenameOne/src/com/codename1/properties/PropertyIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.List;
import java.util.Map;
import java.util.Enumeration;
import java.util.NoSuchElementException;

/**
* Maps the properties that are in a class/object and provides access to them so tools such as ORM
Expand Down Expand Up @@ -198,9 +199,10 @@ public void remove() {
}

public PropertyBase next() {
int i = off;
off++;
return properties[i];
if (!hasNext()) {
throw new NoSuchElementException();
}
return properties[off++];
}
};
}
Expand Down
24 changes: 21 additions & 3 deletions CodenameOne/src/com/codename1/properties/PropertyXMLElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Vector;

/**
Expand Down Expand Up @@ -295,7 +297,21 @@ public boolean isEmpty() {

@Override
public int hashCode() {
return parent.hashCode();
return Objects.hash(parent, parentElement, index);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof PropertyXMLElement)) {
return false;
}
PropertyXMLElement other = (PropertyXMLElement) obj;
return index == other.index
&& Objects.equals(parent, other.parent)
&& Objects.equals(parentElement, other.parentElement);
}

@Override
Expand Down Expand Up @@ -330,8 +346,10 @@ public boolean hasNext() {

@Override
public Element next() {
offset++;
return getChildAt(index);
if (!hasNext()) {
throw new NoSuchElementException();
}
return getChildAt(offset++);
}

@Override
Expand Down
29 changes: 0 additions & 29 deletions CodenameOne/src/com/codename1/ui/geom/Rectangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,6 @@ public static void intersection(int rrX, int rrY, int rrW, int rrH, int rtx1, in
tx2 -= tx1;
ty2 -= ty1;

// tx2,ty2 will never overflow (they will never be
// larger than the smallest of the two source w,h)
// they might underflow, though...
if (tx2 < Integer.MIN_VALUE) {
tx2 = Integer.MIN_VALUE;
}
if (ty2 < Integer.MIN_VALUE) {
ty2 = Integer.MIN_VALUE;
}

dest.x = tx1;
dest.y = ty1;
dest.size.setWidth(tx2);
Expand Down Expand Up @@ -422,16 +412,6 @@ public Rectangle intersection(int rX, int rY, int rW, int rH) {
}
tx2 -= tx1;
ty2 -= ty1;
// tx2,ty2 will never overflow (they will never be
// larger than the smallest of the two source w,h)
// they might underflow, though...
if (tx2 < Integer.MIN_VALUE) {
tx2 = Integer.MIN_VALUE;
}
if (ty2 < Integer.MIN_VALUE) {
ty2 = Integer.MIN_VALUE;
}

return new Rectangle(tx1, ty1, tx2, ty2);
}

Expand Down Expand Up @@ -462,15 +442,6 @@ public void intersection(Rectangle input, Rectangle output) {
}
tx2 -= tx1;
ty2 -= ty1;
// tx2,ty2 will never overflow (they will never be
// larger than the smallest of the two source w,h)
// they might underflow, though...
if (tx2 < Integer.MIN_VALUE) {
tx2 = Integer.MIN_VALUE;
}
if (ty2 < Integer.MIN_VALUE) {
ty2 = Integer.MIN_VALUE;
}
tx2 = Math.max(0, tx2);
ty2 = Math.max(0, ty2);
output.setBounds(tx1, ty1, tx2, ty2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ public static UnitValue[] parseInsets(String s, boolean acceptPanel) {
String[] insS = toTrimmedTokens(s, ' ');
UnitValue[] ins = new UnitValue[4];
for (int j = 0; j < 4; j++) {
UnitValue insSz = parseUnitValue(insS[j < insS.length ? j : insS.length - 1], UnitValue.ZERO, j % 2 == 1);
UnitValue insSz = parseUnitValue(insS[j < insS.length ? j : insS.length - 1], UnitValue.ZERO, (j & 1) != 0);
ins[j] = insSz != null ? insSz : PlatformDefaults.getPanelInsets(j);
}
return ins;
Expand Down
40 changes: 34 additions & 6 deletions CodenameOne/src/com/codename1/ui/layouts/mig/UnitValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@

import com.codename1.util.MathUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Objects;

public final class UnitValue {
/**
Expand Down Expand Up @@ -617,7 +619,33 @@ public String getConstraintString() {
return LayoutUtil.getCCString(this);
}

public int hashCode() {
return (int) (value * 12345) + (oper >>> 5) + unit >>> 17;
}
}
public int hashCode() {
int result = 17;
result = 31 * result + Float.floatToIntBits(value);
result = 31 * result + unit;
result = 31 * result + oper;
result = 31 * result + (isHor ? 1 : 0);
result = 31 * result + (unitStr != null ? unitStr.hashCode() : 0);
result = 31 * result + (linkId != null ? linkId.hashCode() : 0);
result = 31 * result + Arrays.hashCode(subUnits);
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof UnitValue)) {
return false;
}
UnitValue other = (UnitValue) obj;
return Float.compare(value, other.value) == 0
&& unit == other.unit
&& oper == other.oper
&& isHor == other.isHor
&& Objects.equals(unitStr, other.unitStr)
&& Objects.equals(linkId, other.linkId)
&& Arrays.equals(subUnits, other.subUnits);
}
}
2 changes: 1 addition & 1 deletion CodenameOne/src/com/codename1/ui/plaf/RoundRectBorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ private GeneralPath createShape(int shapeW, int shapeH) {
x += strokePx / 2f;
y += strokePx / 2f;

if (strokePx % 2 == 1) {
if ((strokePx & 1) != 0) {
x += 0.5f;
y += 0.5f;
}
Expand Down
Loading