You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2026/10/11 08:04:17 UTC
svn commit: r1939003 - pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function
Author: tilman
Date: Sun Oct 11 08:04:17 2026
New Revision: 1939003
Log:
PDFBOX-5660: Sonar fix, avoid NPE, improve javadoc
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java Sun Oct 11 08:04:13 2026 (r1939002)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java Sun Oct 11 08:04:17 2026 (r1939003)
@@ -17,10 +17,12 @@
package org.apache.pdfbox.pdmodel.common.function;
import java.io.IOException;
+import java.util.List;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSInteger;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSObject;
import org.apache.pdfbox.cos.COSStream;
@@ -174,9 +176,8 @@ public abstract class PDFunction impleme
}
/**
- * This will get the range for a certain output parameters. This is will never
- * return null. If it is not present then the range 0 to 0 will
- * be returned.
+ * This will get the range for a certain output parameters. This will never return null. If it
+ * is not present then the range 0 to 0 will be returned.
*
* @param n The output parameter number to get the range for.
*
@@ -185,7 +186,12 @@ public abstract class PDFunction impleme
public PDRange getRangeForOutput(int n)
{
COSArray rangeValues = getRangeValues();
- return new PDRange( rangeValues, n );
+ if (rangeValues == null)
+ {
+ COSArray array = new COSArray(List.of(COSInteger.ZERO, COSInteger.ZERO));
+ return new PDRange(array);
+ }
+ return new PDRange(rangeValues, n);
}
/**
@@ -200,34 +206,43 @@ public abstract class PDFunction impleme
}
/**
- * This will get the number of input parameters that
- * have a domain specified.
+ * This will get the number of input parameters that have a domain specified.
*
- * @return The number of input parameters that have a domain
- * specified.
+ * @return The number of input parameters that have a domain specified.
*/
public int getNumberOfInputParameters()
{
if (numberOfInputValues == -1)
{
COSArray array = getDomainValues();
- numberOfInputValues = array.size() / 2;
+ if (array == null)
+ {
+ numberOfInputValues = 0;
+ }
+ else
+ {
+ numberOfInputValues = array.size() / 2;
+ }
}
return numberOfInputValues;
}
/**
- * This will get the range for a certain input parameter. This is will never
- * return null. If it is not present then the range 0 to 0 will
- * be returned.
+ * This will get the range for a certain input parameter. This will never return null. If it is
+ * not present then the range 0 to 0 will be returned.
*
- * @param n The parameter number to get the domain for.
+ * @param n The 0-based parameter number to get the domain for.
*
* @return The domain range for this component.
*/
- public PDRange getDomainForInput(int n)
+ public PDRange getDomainForInput(int n)
{
COSArray domainValues = getDomainValues();
+ if (domainValues == null)
+ {
+ COSArray array = new COSArray(List.of(COSInteger.ZERO, COSInteger.ZERO));
+ return new PDRange(array);
+ }
return new PDRange( domainValues, n );
}
@@ -257,13 +272,14 @@ public abstract class PDFunction impleme
public abstract float[] eval(float[] input) throws IOException;
/**
- * Returns all ranges for the output values as COSArray .
- * Required for type 0 and type 4 functions
- * @return the ranges array.
+ * Returns all ranges for the output values as a COSArray. Required for type 0 and type 4
+ * functions.
+ *
+ * @return the ranges array or null if it is missing.
*/
- protected COSArray getRangeValues()
+ protected COSArray getRangeValues()
{
- if (range == null)
+ if (range == null)
{
range = getCOSObject().getCOSArray(COSName.RANGE);
}
@@ -271,9 +287,9 @@ public abstract class PDFunction impleme
}
/**
- * Returns all domains for the input values as COSArray.
- * Required for all function types.
- * @return the domains array.
+ * Returns all domains for the input values as COSArray. Required for all function types.
+ *
+ * @return the domains array or null if it is missing.
*/
private COSArray getDomainValues()
{