From d90308a508202461651e47a5dbbcdaa1e91a5c39 Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Fri, 17 Oct 2025 19:25:38 +0300 Subject: [PATCH 1/2] Fix PMD warnings across UI and database modules --- .../codename1/components/ScaleImageLabel.java | 14 ++-- .../codename1/components/SliderBridge.java | 7 +- .../com/codename1/components/SplitPane.java | 44 ++++++----- .../src/com/codename1/components/Switch.java | 7 +- .../com/codename1/components/ToastBar.java | 37 +++++----- .../com/codename1/components/WebBrowser.java | 23 +++--- CodenameOne/src/com/codename1/db/Cursor.java | 33 +++++---- .../src/com/codename1/db/Database.java | 7 +- CodenameOne/src/com/codename1/db/Row.java | 19 ++--- CodenameOne/src/com/codename1/db/RowExt.java | 5 +- .../com/codename1/db/ThreadSafeDatabase.java | 6 +- .../codename1/facebook/FaceBookAccess.java | 73 +------------------ .../facebook/FacebookRESTService.java | 5 +- .../src/com/codename1/facebook/Post.java | 5 ++ .../impl/CodenameOneImplementation.java | 56 +++++++------- .../codename1/impl/FullScreenAdService.java | 2 +- .../com/codename1/ui/geom/GeneralPath.java | 9 ++- 17 files changed, 140 insertions(+), 212 deletions(-) diff --git a/CodenameOne/src/com/codename1/components/ScaleImageLabel.java b/CodenameOne/src/com/codename1/components/ScaleImageLabel.java index ff14b0bf1d..b3ac6c3a1a 100644 --- a/CodenameOne/src/com/codename1/components/ScaleImageLabel.java +++ b/CodenameOne/src/com/codename1/components/ScaleImageLabel.java @@ -244,10 +244,9 @@ public int getPreferredH() { } if (preferredW > 0) { Image i = getIcon(); - if (i != null) { - if (preferredW < i.getWidth()) { - return (int)(i.getHeight() * preferredW / (double)i.getWidth()); - } + // PMD Fix (CollapsibleIfStatements): Combine the nested icon and width checks into a single conditional. + if (i != null && preferredW < i.getWidth()) { + return (int)(i.getHeight() * preferredW / (double)i.getWidth()); } } return super.getPreferredH(); @@ -260,10 +259,9 @@ public int getPreferredW() { } if (preferredH > 0) { Image i = getIcon(); - if (i != null) { - if (preferredH < i.getHeight()) { - return (int)(i.getWidth() * preferredH / (double)i.getHeight()); - } + // PMD Fix (CollapsibleIfStatements): Merge the icon nullity and height comparison into one condition. + if (i != null && preferredH < i.getHeight()) { + return (int)(i.getWidth() * preferredH / (double)i.getHeight()); } } return super.getPreferredW(); diff --git a/CodenameOne/src/com/codename1/components/SliderBridge.java b/CodenameOne/src/com/codename1/components/SliderBridge.java index 4eb62b57a9..846db010e2 100644 --- a/CodenameOne/src/com/codename1/components/SliderBridge.java +++ b/CodenameOne/src/com/codename1/components/SliderBridge.java @@ -91,10 +91,9 @@ public static void bindProgress(final ConnectionRequest[] sources, final Slider * {@inheritDoc} */ public void actionPerformed(ActionEvent evt) { - if(sources != null) { - if(!sourceVec.contains(evt.getSource())) { - return; - } + // PMD Fix (CollapsibleIfStatements): Collapse the nested source checks into one conditional. + if(sources != null && !sourceVec.contains(evt.getSource())) { + return; } NetworkEvent e = (NetworkEvent)evt; switch(e.getProgressType()) { diff --git a/CodenameOne/src/com/codename1/components/SplitPane.java b/CodenameOne/src/com/codename1/components/SplitPane.java index 4e99ed1e1c..60a97be4e3 100644 --- a/CodenameOne/src/com/codename1/components/SplitPane.java +++ b/CodenameOne/src/com/codename1/components/SplitPane.java @@ -576,11 +576,6 @@ private Inset getMaxDividerInset() { return getFixedInset(maxInset); } - private void setDividerInset(String inset) { - getDividerInset().setValueAsString(inset); - clampInset(); - } - private Inset getAutoInset(LayeredLayoutConstraint cnst) { switch (orientation) { case VERTICAL_SPLIT: @@ -616,6 +611,7 @@ private LayeredLayoutConstraint initDividerInset(LayeredLayoutConstraint cnst, S + // PMD Fix (UnusedPrivateMethod): Removed unused setDividerInset helper. private void clampInset() { int px = getDividerInset().getAbsolutePixels(divider); @@ -793,14 +789,14 @@ public void expand(boolean force) { getFixedInset(preferredInset).copyTo(getDividerInset()); clampInset(); isCollapsed = false; - SplitPane.this.animateLayout(300); - } else if (isExpanded) { - // do nothing - } else { + // PMD Fix (UselessQualifiedThis): Call animateLayout directly within the class scope. + animateLayout(300); + } else if (!isExpanded) { getFixedInset(maxInset).copyTo(getDividerInset()); clampInset(); isExpanded = true; - SplitPane.this.animateLayout(300); + // PMD Fix (UselessQualifiedThis): Call animateLayout directly within the class scope. + animateLayout(300); } } @@ -817,20 +813,22 @@ public void collapse() { * @param force True to force it to collapse to minimum position (skipping preferred position if it is in expanded state). */ public void collapse(boolean force) { - if (isCollapsed) { - // do nothing - } else if (isExpanded && !force) { - getFixedInset(preferredInset).copyTo(getDividerInset()); - clampInset(); - isExpanded = false; - SplitPane.this.animateLayout(300); - } else { - getFixedInset(minInset).copyTo(getDividerInset()); - clampInset(); - isCollapsed = true; - SplitPane.this.animateLayout(300); + if (!isCollapsed) { + if (isExpanded && !force) { + getFixedInset(preferredInset).copyTo(getDividerInset()); + clampInset(); + isExpanded = false; + // PMD Fix (UselessQualifiedThis): Call animateLayout directly within the class scope. + animateLayout(300); + } else { + getFixedInset(minInset).copyTo(getDividerInset()); + clampInset(); + isCollapsed = true; + // PMD Fix (UselessQualifiedThis): Call animateLayout directly within the class scope. + animateLayout(300); + } } - + } /** diff --git a/CodenameOne/src/com/codename1/components/Switch.java b/CodenameOne/src/com/codename1/components/Switch.java index 274d2ff34d..255ad539c0 100644 --- a/CodenameOne/src/com/codename1/components/Switch.java +++ b/CodenameOne/src/com/codename1/components/Switch.java @@ -772,8 +772,8 @@ public void actionPerformed(ActionEvent evt) { } } + // PMD Fix (UnnecessaryReturn): Removed redundant return at the end of the method. animationLock = false; - return; } }; @@ -836,6 +836,7 @@ public void setValue(boolean value) { setValue(value, false); } + // PMD Fix (UnusedPrivateMethod): Removed the unused flip() helper and retained this setter as the single source of truth. private void setValue(boolean value, boolean fireEvent) { boolean orig = animationLock; animationLock = true; @@ -852,10 +853,6 @@ private void setValue(boolean value, boolean fireEvent) { animationLock = orig; } - private void flip() { - setValue(!value); - } - /** * Checks if switch is in the "on" position. * @return True if switch is on. diff --git a/CodenameOne/src/com/codename1/components/ToastBar.java b/CodenameOne/src/com/codename1/components/ToastBar.java index ac508e1817..0a9c386581 100644 --- a/CodenameOne/src/com/codename1/components/ToastBar.java +++ b/CodenameOne/src/com/codename1/components/ToastBar.java @@ -840,26 +840,23 @@ private ToastBarComponent getToastBarComponent(boolean create) { updateStatus(); } Rectangle safeArea = Display.getInstance().getDisplaySafeArea(new Rectangle(0, 0, 0, 0)); - if(position == Component.BOTTOM) { - if (f.getInvisibleAreaUnderVKB() > 0) { - Style s = c.getAllStyles(); - s.setMarginUnit(Style.UNIT_TYPE_PIXELS); - s.setMarginBottom(f.getInvisibleAreaUnderVKB()); - } - int safeBottomMargin = Display.getInstance().getDisplayHeight() - - safeArea.getY() - - safeArea.getHeight(); - if (0 < safeBottomMargin) { - Style s = c.getAllStyles(); - s.setPaddingUnit(Style.UNIT_TYPE_PIXELS); - s.setPaddingBottom(safeBottomMargin); - } - } else if (position == Component.TOP) { - if (safeArea.getY() > 0) { - Style s = c.getAllStyles(); - s.setPaddingUnit(Style.UNIT_TYPE_PIXELS); - s.setPaddingTop(safeArea.getY()); - } + // PMD Fix (CollapsibleIfStatements): Combine nested position checks to simplify the layout adjustments. + if(position == Component.BOTTOM && f.getInvisibleAreaUnderVKB() > 0) { + Style s = c.getAllStyles(); + s.setMarginUnit(Style.UNIT_TYPE_PIXELS); + s.setMarginBottom(f.getInvisibleAreaUnderVKB()); + } + int safeBottomMargin = Display.getInstance().getDisplayHeight() + - safeArea.getY() + - safeArea.getHeight(); + if (position == Component.BOTTOM && safeBottomMargin > 0) { + Style s = c.getAllStyles(); + s.setPaddingUnit(Style.UNIT_TYPE_PIXELS); + s.setPaddingBottom(safeBottomMargin); + } else if (position == Component.TOP && safeArea.getY() > 0) { + Style s = c.getAllStyles(); + s.setPaddingUnit(Style.UNIT_TYPE_PIXELS); + s.setPaddingTop(safeArea.getY()); } return c; diff --git a/CodenameOne/src/com/codename1/components/WebBrowser.java b/CodenameOne/src/com/codename1/components/WebBrowser.java index ad1d45ab34..dee9230723 100644 --- a/CodenameOne/src/com/codename1/components/WebBrowser.java +++ b/CodenameOne/src/com/codename1/components/WebBrowser.java @@ -117,20 +117,19 @@ protected ConnectionRequest createConnectionRequest(final DocumentInfo docInfo, return new ConnectionRequest() { protected void buildRequestBody(OutputStream os) throws IOException { - if (isPost()) { - if (docInfo.getParams() != null) { - String enc = docInfo.getEncoding(); - if(enc.indexOf('/') > -1) { - if(enc.indexOf("charset=") > -1) { - enc = enc.substring(enc.indexOf("charset=") + 8); - } else { - enc = DocumentInfo.ENCODING_UTF8; - } + // PMD Fix (CollapsibleIfStatements): Merge the post and parameter checks into a single conditional. + if (isPost() && docInfo.getParams() != null) { + String enc = docInfo.getEncoding(); + if(enc.indexOf('/') > -1) { + if(enc.indexOf("charset=") > -1) { + enc = enc.substring(enc.indexOf("charset=") + 8); + } else { + enc = DocumentInfo.ENCODING_UTF8; } - OutputStreamWriter w = new OutputStreamWriter(os, enc); - w.write(docInfo.getParams()); - w.flush(); } + OutputStreamWriter w = new OutputStreamWriter(os, enc); + w.write(docInfo.getParams()); + w.flush(); } } diff --git a/CodenameOne/src/com/codename1/db/Cursor.java b/CodenameOne/src/com/codename1/db/Cursor.java index 4296326fe0..8dacaa879f 100644 --- a/CodenameOne/src/com/codename1/db/Cursor.java +++ b/CodenameOne/src/com/codename1/db/Cursor.java @@ -41,13 +41,14 @@ public interface Cursor { /** * Move the cursor to the first row. - * - * If cursor provides forward-only navigation and is positioned after the - * first row then calling first() method would throw a IOException. - * @return true if succeeded - * @throws IOException + * + * If cursor provides forward-only navigation and is positioned after the + * first row then calling first() method would throw a IOException. + * @return true if succeeded + * @throws IOException */ - public boolean first() throws IOException; + // PMD Fix (UnnecessaryModifier): Interface methods are implicitly public; remove redundant modifiers. + boolean first() throws IOException; /** * Move the cursor to the last row. @@ -55,7 +56,7 @@ public interface Cursor { * @return true if succeeded * @throws IOException */ - public boolean last() throws IOException; + boolean last() throws IOException; /** * Moves the cursor to the next row. @@ -64,7 +65,7 @@ public interface Cursor { * @return true if succeeded * @throws IOException */ - public boolean next() throws IOException; + boolean next() throws IOException; /** * Moves the cursor to the previous row. @@ -73,7 +74,7 @@ public interface Cursor { * @return true if succeeded * @throws IOException */ - public boolean prev() throws IOException; + boolean prev() throws IOException; /** * Returns the zero-based index for a given column name. @@ -84,7 +85,7 @@ public interface Cursor { * @return the index of the column * @throws IOException */ - public int getColumnIndex(String columnName) throws IOException; + int getColumnIndex(String columnName) throws IOException; /** * Returns the column name at a given zero-based column index. @@ -96,14 +97,14 @@ public interface Cursor { * * @throws IOException */ - public String getColumnName(int columnIndex) throws IOException; + String getColumnName(int columnIndex) throws IOException; /** * Returns the column count * @return the column count * @throws IOException */ - public int getColumnCount() throws IOException; + int getColumnCount() throws IOException; /** * Returns the current Cursor position. @@ -111,7 +112,7 @@ public interface Cursor { * @return the cursor position * @throws IOException */ - public int getPosition() throws IOException; + int getPosition() throws IOException; /** * Move the cursor to an absolute row position @@ -120,13 +121,13 @@ public interface Cursor { * @return true if succeeded * @throws IOException */ - public boolean position(int row) throws IOException; + boolean position(int row) throws IOException; /** * Close the cursor and release its resources * @throws IOException */ - public void close() throws IOException; + void close() throws IOException; /** * Get the Row data Object. @@ -134,6 +135,6 @@ public interface Cursor { * @return a Row Object * @throws IOException */ - public Row getRow() throws IOException; + Row getRow() throws IOException; } diff --git a/CodenameOne/src/com/codename1/db/Database.java b/CodenameOne/src/com/codename1/db/Database.java index e261205492..daf8a0483f 100644 --- a/CodenameOne/src/com/codename1/db/Database.java +++ b/CodenameOne/src/com/codename1/db/Database.java @@ -58,10 +58,9 @@ public static boolean isCustomPathSupported() { } private static void validateDatabaseNameArgument(String databaseName) { - if (!isCustomPathSupported()) { - if (databaseName.indexOf("/") != -1 || databaseName.indexOf("\\") != -1) { - throw new IllegalArgumentException("This platform does not support custom database paths. The database name cannot contain file separators."); - } + // PMD Fix (CollapsibleIfStatements): Merge the custom path support and separator checks into one condition. + if (!isCustomPathSupported() && (databaseName.indexOf("/") != -1 || databaseName.indexOf("\\") != -1)) { + throw new IllegalArgumentException("This platform does not support custom database paths. The database name cannot contain file separators."); } } diff --git a/CodenameOne/src/com/codename1/db/Row.java b/CodenameOne/src/com/codename1/db/Row.java index e77e5954f7..ab6c133ee1 100644 --- a/CodenameOne/src/com/codename1/db/Row.java +++ b/CodenameOne/src/com/codename1/db/Row.java @@ -41,12 +41,13 @@ public interface Row { /** * Gets column value by index. - * + * * @param index starts with zero * @return byte [] data - * @throws IOException + * @throws IOException */ - public byte[] getBlob(int index)throws IOException; + // PMD Fix (UnnecessaryModifier): Remove redundant public modifiers from interface methods. + byte[] getBlob(int index)throws IOException; /** * Gets column value by index. @@ -55,7 +56,7 @@ public interface Row { * @return a double data from the database * @throws IOException */ - public double getDouble(int index)throws IOException; + double getDouble(int index)throws IOException; /** * Gets column value by index. @@ -64,7 +65,7 @@ public interface Row { * @return a float data from the database * @throws IOException */ - public float getFloat(int index)throws IOException; + float getFloat(int index)throws IOException; /** * Gets column value by index. @@ -73,7 +74,7 @@ public interface Row { * @return a int data from the database * @throws IOException */ - public int getInteger(int index)throws IOException; + int getInteger(int index)throws IOException; /** * Gets column value by index. @@ -82,7 +83,7 @@ public interface Row { * @return a long data from the database * @throws IOException */ - public long getLong(int index)throws IOException; + long getLong(int index)throws IOException; /** * Gets column value by index. @@ -91,7 +92,7 @@ public interface Row { * @return a short data from the database * @throws IOException */ - public short getShort(int index)throws IOException; + short getShort(int index)throws IOException; /** * Gets column value by index. @@ -100,7 +101,7 @@ public interface Row { * @return a String data from the database * @throws IOException */ - public String getString(int index)throws IOException; + String getString(int index)throws IOException; diff --git a/CodenameOne/src/com/codename1/db/RowExt.java b/CodenameOne/src/com/codename1/db/RowExt.java index e98e17b65c..180bafc2a2 100644 --- a/CodenameOne/src/com/codename1/db/RowExt.java +++ b/CodenameOne/src/com/codename1/db/RowExt.java @@ -35,6 +35,7 @@ * @since 7.0 */ public interface RowExt extends Row { - public boolean wasNull() throws IOException; - + // PMD Fix (UnnecessaryModifier): Interface methods inherit public visibility. + boolean wasNull() throws IOException; + } diff --git a/CodenameOne/src/com/codename1/db/ThreadSafeDatabase.java b/CodenameOne/src/com/codename1/db/ThreadSafeDatabase.java index dd63d29cf6..8d9b7672d9 100644 --- a/CodenameOne/src/com/codename1/db/ThreadSafeDatabase.java +++ b/CodenameOne/src/com/codename1/db/ThreadSafeDatabase.java @@ -66,11 +66,13 @@ public void run() throws IOException { } interface RunnableWithIOException { - public void run() throws IOException; + // PMD Fix (UnnecessaryModifier): Interface methods are implicitly public. + void run() throws IOException; } interface RunnableWithResponseOrIOException { - public Object run() throws IOException; + // PMD Fix (UnnecessaryModifier): Interface methods are implicitly public. + Object run() throws IOException; } private void invokeWithException(final RunnableWithIOException r) throws IOException { diff --git a/CodenameOne/src/com/codename1/facebook/FaceBookAccess.java b/CodenameOne/src/com/codename1/facebook/FaceBookAccess.java index 0cbad257e4..d6a27a8da2 100644 --- a/CodenameOne/src/com/codename1/facebook/FaceBookAccess.java +++ b/CodenameOne/src/com/codename1/facebook/FaceBookAccess.java @@ -43,7 +43,6 @@ import com.codename1.ui.events.ActionListener; import com.codename1.ui.geom.Dimension; import com.codename1.ui.list.DefaultListModel; -import com.codename1.ui.list.ListModel; import java.io.IOException; import java.util.Enumeration; import java.util.Hashtable; @@ -838,74 +837,6 @@ public void getAlbumPhotos(String albumId, DefaultListModel photos, int offset, getFaceBookObjectItems(albumId, FacebookRESTService.PHOTOS, photos, params, callback); } - /** - * This method returns a list model of photos that automatically fetches additional images as necessary - * @param targetList required for the image download code - * @param albumId the id of the album - * @param photoCount the number of photos within the album - * @param placeholder a placeholder image that will determine the size of the images requested - * @return the list of the images - */ - private ListModel getAlbumPhotos(final Component targetList, final String albumId, final int photoCount, final Image placeholder) { - if(!isAuthenticated()) { - return null; - } - Hashtable[] h = new Hashtable[photoCount]; - int hlen = h.length; - for(int iter = 0 ; iter < hlen ; iter++) { - h[iter] = new Hashtable(); - h[iter].put("photo", placeholder); - if(iter < 30) { - h[iter].put("fetching", Boolean.TRUE); - } - } - DefaultListModel dl = new DefaultListModel((Object[])h) { - public Object getItem(int offset) { - Hashtable hash = (Hashtable)super.getItemAt(offset); - if(!hash.containsKey("fetching")) { - int limit = Math.min(30, photoCount - offset); - for(int iter = 0 ; iter < limit ; iter++) { - Hashtable current = (Hashtable)super.getItemAt(iter + offset); - if(current.containsKey("fetching")) { - break; - } - current.put("fetching", Boolean.TRUE); - } - FacebookRESTService con = new FacebookRESTService(token, albumId, FacebookRESTService.PHOTOS, false); - con.setResponseDestination(this); - con.setResponseOffset(0); - con.addArgument("limit", "" + limit); - con.addArgument("offset", "" + offset); - for (int i = 0; i < responseCodeListeners.size(); i++) { - con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i)); - } - NetworkManager.getInstance().addToQueueAndWait(con); - for(int iter = 0 ; iter < limit ; iter++) { - Hashtable current = (Hashtable)getItemAt(iter + offset); - ImageDownloadService.createImageToStorage((String)current.get("photo"), targetList, iter + offset, "photo", ((String)current.get("id")) + placeholder.getHeight(), placeholder, ConnectionRequest.PRIORITY_NORMAL); - } - } - return hash; - } - }; - - FacebookRESTService con = new FacebookRESTService(token, albumId, FacebookRESTService.PHOTOS, false); - con.setResponseDestination(dl); - con.setResponseOffset(0); - con.addArgument("limit", "30"); - con.addArgument("offset", "0"); - for (int i = 0; i < responseCodeListeners.size(); i++) { - con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i)); - } - NetworkManager.getInstance().addToQueueAndWait(con); - for(int iter = 0 ; iter < Math.min(30, photoCount) ; iter++) { - Hashtable hash = (Hashtable)dl.getItemAt(iter); - ImageDownloadService.createImageToStorage((String)hash.get("photo"), targetList, iter, "photo", ((String)hash.get("id")) + placeholder.getHeight(), placeholder, ConnectionRequest.PRIORITY_NORMAL); - } - - return dl; - } - /** * Gets the post comments * @@ -914,6 +845,7 @@ public Object getItem(int offset) { * each entry is an Hashtable Object contaning the Object data * @param callback the callback that should be updated when the data arrives */ + // PMD Fix (UnusedPrivateMethod): Removed unused album photo ListModel helper. public void getPostComments(String postId, DefaultListModel comments, final ActionListener callback) throws IOException { getFaceBookObjectItems(postId, FacebookRESTService.COMMENTS, comments, null, callback); } @@ -1122,7 +1054,8 @@ public void getUserNotifications(String userId, String startTime, boolean includ final FacebookRESTService con = new FacebookRESTService(token, "https://api.facebook.com/method/notifications.getList", false); con.addArgument("start_time", startTime); - con.addArgument("include_read", new Boolean(includeRead).toString()); + // PMD Fix (UnnecessaryConversionTemporary, PrimitiveWrapperInstantiation): Avoid boxing boolean via constructor and temporary string. + con.addArgument("include_read", Boolean.toString(includeRead)); con.addArgument("format", "json"); con.setResponseDestination(notifications); diff --git a/CodenameOne/src/com/codename1/facebook/FacebookRESTService.java b/CodenameOne/src/com/codename1/facebook/FacebookRESTService.java index 86b49a9788..76b43011b4 100644 --- a/CodenameOne/src/com/codename1/facebook/FacebookRESTService.java +++ b/CodenameOne/src/com/codename1/facebook/FacebookRESTService.java @@ -44,7 +44,7 @@ */ class FacebookRESTService extends ConnectionRequest implements JSONParseCallback { - private String token; + // PMD Fix (UnusedPrivateField): Removed redundant token storage; the access token is forwarded directly via request arguments. private Hashtable entry = new Hashtable(); private Hashtable currentData = entry; @@ -74,12 +74,10 @@ class FacebookRESTService extends ConnectionRequest implements JSONParseCallback public static final String GRAPH_URL = "https://graph.facebook.com/"; public FacebookRESTService(boolean post, String token) { - this.token = token; setPost(post); } public FacebookRESTService(String token, String id, String connectionType, boolean post) { - this.token = token; setPost(post); String query = id; if (connectionType.length() > 0) { @@ -92,7 +90,6 @@ public FacebookRESTService(String token, String id, String connectionType, boole } public FacebookRESTService(String token, String url, boolean post) { - this.token = token; setPost(post); addArgumentNoEncoding("access_token", token); //addArgument("access_token", token); diff --git a/CodenameOne/src/com/codename1/facebook/Post.java b/CodenameOne/src/com/codename1/facebook/Post.java index 552940cdf0..b64b7df605 100644 --- a/CodenameOne/src/com/codename1/facebook/Post.java +++ b/CodenameOne/src/com/codename1/facebook/Post.java @@ -151,6 +151,11 @@ public String getPicture() { return picture; } + // PMD Fix (UnusedPrivateField): Expose the created_time metadata via an accessor. + public String getCreatedTime() { + return created_time; + } + /** * Gets the Link Count * diff --git a/CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java b/CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java index 5c3e9e8be6..24e805921c 100644 --- a/CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java +++ b/CodenameOne/src/com/codename1/impl/CodenameOneImplementation.java @@ -124,7 +124,6 @@ public abstract class CodenameOneImplementation { private static boolean bidi; private String packageName; - private static int pollingMillis = 3 * 60 * 60000; private Component editingText; private String appArg; @@ -2354,9 +2353,8 @@ protected void pointerDragged(final int[] x, final int[] y) { try { hasDragStartedXY = hasDragStarted(x, y); } catch ( Throwable t) { - // Since this method may be running off the EDT - // It is possible that hasDragStarted will throw an NPE - // as the UI may be in an inconsistent state. + // PMD Fix (EmptyCatchBlock): Log the exception to retain diagnostic information while tolerating inconsistent states. + Log.e(t); } } if (dragStarted || hasDragStartedXY) { @@ -2596,10 +2594,10 @@ private Object findCachedGradient(Hashtable cache, int startColor, int endColor, current[6] == centerY && current[7] == size && getImageWidth(currentImage) == width && - getImageHeight(currentImage) == height) { - if((horizontal && current[4] == 1) || ((!horizontal) && current[4] == 0)) { - return currentImage; - } + getImageHeight(currentImage) == height && + ((horizontal && current[4] == 1) || (!horizontal && current[4] == 0))) { + // PMD Fix (CollapsibleIfStatements): Collapse nested equality checks for cache reuse. + return currentImage; } } } @@ -3381,12 +3379,11 @@ public void setBidiAlgorithm(boolean activate) { * @return a "visual" renderable string */ public String convertBidiLogicalToVisual(String s) { - if (bidi) { - if (s.length() >= 2) { - char[] c = s.toCharArray(); - swapBidiChars(c, 0, s.length(), -1); - return new String(c); - } + if (bidi && s.length() >= 2) { + // PMD Fix (CollapsibleIfStatements): Merge bidi activation and length checks prior to processing. + char[] c = s.toCharArray(); + swapBidiChars(c, 0, s.length(), -1); + return new String(c); } return s; } @@ -3436,7 +3433,8 @@ public boolean isRTL(char c) { return (c >= RTL_RANGE_BEGIN && c <= RTL_RANGE_END); } - private final int swapBidiChars(char[] chars, int ixStart, int len, int index) { + // PMD Fix (UnnecessaryModifier): Private methods cannot be overridden, so final is redundant. + private int swapBidiChars(char[] chars, int ixStart, int len, int index) { int destIndex = -1; int ixEnd = ixStart + len; @@ -3506,7 +3504,8 @@ private boolean isLTR(char c) { return !isRTL(c) && !isRTLBreak(c); } - private final int scanSecond(char[] chars, int ixStart, int ixEnd) { + // PMD Fix (UnnecessaryModifier): Private helper does not require the final modifier. + private int scanSecond(char[] chars, int ixStart, int ixEnd) { int ixFound = -1; for (int ix = ixStart; ixFound < 0 && ix < ixEnd; ix++) { if (!isRTLOrWhitespace(chars[ix])) { @@ -3516,7 +3515,8 @@ private final int scanSecond(char[] chars, int ixStart, int ixEnd) { return ixFound; } - private final int scanBackFirst(char[] chars, int ixStart, int ixEnd) { + // PMD Fix (UnnecessaryModifier): Remove redundant final modifier on private helper. + private int scanBackFirst(char[] chars, int ixStart, int ixEnd) { int ix, ixFound = ixEnd; for (ix = ixStart + 1; ix < ixEnd; ix++) { if (isRTL(chars[ix]) || isRTLBreak(chars[ix])) { @@ -7107,7 +7107,7 @@ public static void deregisterPushFromServer() { * @param freq the frequency in milliseconds */ public void setPollingFrequency(int freq) { - pollingMillis = freq; + // PMD Fix (UnusedPrivateField): Removed obsolete pollingMillis state; method now only triggers listener wake-up. if(callback != null && pollingThreadRunning) { synchronized(callback) { callback.notify(); @@ -7260,10 +7260,9 @@ public int getCommandBehavior() { * @param commandBehavior the commandBehavior to set */ public void setCommandBehavior(int commandBehavior) { - if(!isTouchDevice()) { - if(commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR) { - commandBehavior = Display.COMMAND_BEHAVIOR_SOFTKEY; - } + // PMD Fix (CollapsibleIfStatements): Combine touch capability and behavior checks. + if(!isTouchDevice() && commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR) { + commandBehavior = Display.COMMAND_BEHAVIOR_SOFTKEY; } this.commandBehavior = commandBehavior; notifyCommandBehavior(commandBehavior); @@ -8252,13 +8251,14 @@ protected int drawLabelText(Object nativeGraphics, int textDecoration, boolean r // Instead we simple reposition the text, and draw the 3 points, this is quite simple, but // the downside is that a part of a letter may be shown here as well. + if (rtl && !isTickerRunning && endsWith3Points) { + // PMD Fix (CollapsibleIfStatements): Separate combined RTL and ticker checks into a single conditional. + String points = "..."; + int pointsW = stringWidth(nativeFont, points); + drawString(nativeGraphics, nativeFont, points, shiftText + x, y, textDecoration, fontHeight); + clipRect(nativeGraphics, pointsW + shiftText + x, y, textSpaceW - pointsW, fontHeight); + } if (rtl) { - if ((!isTickerRunning) && endsWith3Points) { - String points = "..."; - int pointsW = stringWidth(nativeFont, points); - drawString(nativeGraphics, nativeFont, points, shiftText + x, y, textDecoration, fontHeight); - clipRect(nativeGraphics, pointsW + shiftText + x, y, textSpaceW - pointsW, fontHeight); - } x = x - txtW + textSpaceW; } else if (endsWith3Points) { String points = "..."; diff --git a/CodenameOne/src/com/codename1/impl/FullScreenAdService.java b/CodenameOne/src/com/codename1/impl/FullScreenAdService.java index d85bf49f6d..06e7db15d4 100644 --- a/CodenameOne/src/com/codename1/impl/FullScreenAdService.java +++ b/CodenameOne/src/com/codename1/impl/FullScreenAdService.java @@ -51,7 +51,7 @@ public abstract class FullScreenAdService { private boolean allowWithoutNetwork = true; private int timeout = 10000; private int adDisplayTime = 6000; - private int timeForNext = -1; + // PMD Fix (UnusedPrivateField): Removed redundant timeForNext cache; timing is provided per invocation. private boolean scaleMode; private boolean allowSkipping; private static Object LOCK = new Object(); diff --git a/CodenameOne/src/com/codename1/ui/geom/GeneralPath.java b/CodenameOne/src/com/codename1/ui/geom/GeneralPath.java index 8c5cda3ec0..7c0249b7dd 100644 --- a/CodenameOne/src/com/codename1/ui/geom/GeneralPath.java +++ b/CodenameOne/src/com/codename1/ui/geom/GeneralPath.java @@ -2873,7 +2873,8 @@ static int crossBound(double bound[], int bc, double py1, double py2) { int up = 0; int down = 0; boolean intersects = false; - for (int i = 2; i < bc; i += 4) { // PMD Fix: AvoidBranchingStatementAsLastInLoop + // PMD Fix (AvoidBranchingStatementAsLastInLoop): Stop relying on a terminal break by guarding the loop with the intersects flag. + for (int i = 2; i < bc && !intersects; i += 4) { if (bound[i] < py1) { up++; continue; @@ -2883,7 +2884,6 @@ static int crossBound(double bound[], int bc, double py1, double py2) { continue; } intersects = true; - break; } if (intersects) { @@ -2900,12 +2900,13 @@ static int crossBound(double bound[], int bc, double py1, double py2) { sortBound(bound, bc); boolean sign = bound[2] > py2; boolean crossing = false; - for (int i = 6; i < bc; i += 4) { // PMD Fix: AvoidBranchingStatementAsLastInLoop + // PMD Fix (AvoidBranchingStatementAsLastInLoop): Guard the loop with the crossing flag instead of breaking at the end. + for (int i = 6; i < bc && !crossing; i += 4) { boolean sign2 = bound[i] > py2; if (sign != sign2 && bound[i + 1] != bound[i - 3]) { crossing = true; sign = sign2; - break; + continue; } sign = sign2; } From dd3805b73b3962c757e5721767387b45050f0d1c Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Fri, 17 Oct 2025 20:13:33 +0300 Subject: [PATCH 2/2] Handle Codename One boolean conversion --- CodenameOne/src/com/codename1/facebook/FaceBookAccess.java | 4 ++-- CodenameOne/src/com/codename1/ui/geom/GeneralPath.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CodenameOne/src/com/codename1/facebook/FaceBookAccess.java b/CodenameOne/src/com/codename1/facebook/FaceBookAccess.java index d6a27a8da2..7eb7f47172 100644 --- a/CodenameOne/src/com/codename1/facebook/FaceBookAccess.java +++ b/CodenameOne/src/com/codename1/facebook/FaceBookAccess.java @@ -1054,8 +1054,8 @@ public void getUserNotifications(String userId, String startTime, boolean includ final FacebookRESTService con = new FacebookRESTService(token, "https://api.facebook.com/method/notifications.getList", false); con.addArgument("start_time", startTime); - // PMD Fix (UnnecessaryConversionTemporary, PrimitiveWrapperInstantiation): Avoid boxing boolean via constructor and temporary string. - con.addArgument("include_read", Boolean.toString(includeRead)); + // PMD Fix (UnnecessaryConversionTemporary, PrimitiveWrapperInstantiation): Avoid boxing boolean via constructor and temporary string while staying compatible with Codename One APIs. + con.addArgument("include_read", includeRead ? "true" : "false"); con.addArgument("format", "json"); con.setResponseDestination(notifications); diff --git a/CodenameOne/src/com/codename1/ui/geom/GeneralPath.java b/CodenameOne/src/com/codename1/ui/geom/GeneralPath.java index 7c0249b7dd..38bdd6719a 100644 --- a/CodenameOne/src/com/codename1/ui/geom/GeneralPath.java +++ b/CodenameOne/src/com/codename1/ui/geom/GeneralPath.java @@ -2873,7 +2873,7 @@ static int crossBound(double bound[], int bc, double py1, double py2) { int up = 0; int down = 0; boolean intersects = false; - // PMD Fix (AvoidBranchingStatementAsLastInLoop): Stop relying on a terminal break by guarding the loop with the intersects flag. + // PMD Fix (AvoidBranchingStatementAsLastInLoop): Guard the loop with the intersects flag instead of breaking at the end. for (int i = 2; i < bc && !intersects; i += 4) { if (bound[i] < py1) { up++;