replace "".equals(string) with string.isEmpty() to avoid null strings silently evaluating to false; most code should probably check string for null if it is not already
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1812476 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
aba704b928
commit
5fb4887907
@ -420,7 +420,7 @@ public class Variant
|
||||
}
|
||||
|
||||
name += numberToName.get(vt);
|
||||
return !"".equals(name) ? name : "unknown variant type";
|
||||
return !name.isEmpty() ? name : "unknown variant type";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -379,7 +379,7 @@ public class CryptoFunctions {
|
||||
// SET Verifier TO 0x0000
|
||||
short verifier = 0;
|
||||
|
||||
if (!"".equals(password)) {
|
||||
if (!password.isEmpty()) {
|
||||
// FOR EACH PasswordByte IN PasswordArray IN REVERSE ORDER
|
||||
for (int i = arrByteChars.length-1; i >= 0; i--) {
|
||||
// SET Verifier TO Intermediate3 BITWISE XOR PasswordByte
|
||||
@ -418,7 +418,7 @@ public class CryptoFunctions {
|
||||
//Maximum length of the password is 15 chars.
|
||||
final int maxPasswordLength = 15;
|
||||
|
||||
if (!"".equals(password)) {
|
||||
if (!password.isEmpty()) {
|
||||
// Truncate the password to 15 characters
|
||||
password = password.substring(0, Math.min(password.length(), maxPasswordLength));
|
||||
|
||||
|
@ -356,7 +356,7 @@ public class DataSpaceMapUtils {
|
||||
}
|
||||
|
||||
public static void writeUtf8LPP4(LittleEndianOutput os, String str) {
|
||||
if (str == null || "".equals(str)) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
os.writeInt(str == null ? 0 : 4);
|
||||
os.writeInt(0);
|
||||
} else {
|
||||
|
@ -257,7 +257,7 @@ public class DrawTextParagraph implements Drawable {
|
||||
fact.fixFonts(graphics);
|
||||
StringBuilder text = new StringBuilder();
|
||||
AttributedString at = getAttributedString(graphics, text);
|
||||
boolean emptyParagraph = ("".equals(text.toString().trim()));
|
||||
boolean emptyParagraph = text.toString().trim().isEmpty();
|
||||
|
||||
AttributedCharacterIterator it = at.getIterator();
|
||||
LineBreakMeasurer measurer = new LineBreakMeasurer(it, graphics.getFontRenderContext());
|
||||
|
@ -54,7 +54,7 @@ public final class Countblank extends Fixed1ArgFunction {
|
||||
return valueEval == BlankEval.instance ||
|
||||
// see https://support.office.com/en-us/article/COUNTBLANK-function-6a92d772-675c-4bee-b346-24af6bd3ac22
|
||||
// "Cells with formulas that return "" (empty text) are also counted."
|
||||
(valueEval instanceof StringEval && "".equals(((StringEval)valueEval).getStringValue()));
|
||||
(valueEval instanceof StringEval && ((StringEval)valueEval).getStringValue().isEmpty());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ public class FractionFormat extends Format {
|
||||
}
|
||||
|
||||
//if whole part has to go into the numerator
|
||||
if ("".equals(wholePartFormatString)){
|
||||
if (wholePartFormatString.isEmpty()){
|
||||
int trueNum = (fract.getDenominator()*(int)wholePart)+fract.getNumerator();
|
||||
sb.append(trueNum).append("/").append(fract.getDenominator());
|
||||
return sb.toString();
|
||||
|
@ -348,7 +348,7 @@ public class StringUtil {
|
||||
* @see <a href="http://www.alanwood.net/demos/symbol.html">Symbol font - Unicode alternatives for Greek and special characters in HTML</a>
|
||||
*/
|
||||
public static String mapMsCodepointString(String string) {
|
||||
if (string == null || "".equals(string)) return string;
|
||||
if (string == null || string.isEmpty()) return string;
|
||||
initMsCodepointMap();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
@ -242,7 +242,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
|
||||
*/
|
||||
public static OPCPackage open(String path, PackageAccess access)
|
||||
throws InvalidFormatException, InvalidOperationException {
|
||||
if (path == null || "".equals(path.trim())) {
|
||||
if (path == null || path.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("'path' must be given");
|
||||
}
|
||||
|
||||
@ -459,7 +459,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
|
||||
try {
|
||||
l.writeLock().lock();
|
||||
if (this.originalPackagePath != null
|
||||
&& !"".equals(this.originalPackagePath.trim())) {
|
||||
&& !this.originalPackagePath.trim().isEmpty()) {
|
||||
File targetFile = new File(this.originalPackagePath);
|
||||
if (!targetFile.exists()
|
||||
|| !(this.originalPackagePath
|
||||
|
@ -260,7 +260,7 @@ public final class PackagePartName implements Comparable<PackagePartName> {
|
||||
+ partUri.getPath());
|
||||
}
|
||||
|
||||
if ("".equals(seg.replaceAll("\\\\.", ""))) {
|
||||
if (seg.replaceAll("\\\\.", "").isEmpty()) {
|
||||
// Normally will never been invoked with the previous
|
||||
// implementation rule [M1.9]
|
||||
throw new InvalidFormatException(
|
||||
|
@ -430,7 +430,7 @@ public final class ZipPackage extends OPCPackage {
|
||||
// Flush the package
|
||||
flush();
|
||||
|
||||
if (this.originalPackagePath == null || "".equals(this.originalPackagePath)) {
|
||||
if (this.originalPackagePath == null || this.originalPackagePath.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ public class OOXMLURIDereferencer implements URIDereferencer, SignatureConfigura
|
||||
LOG.log(POILogger.DEBUG, "dereference", uri);
|
||||
|
||||
String path = uri.getPath();
|
||||
if (path == null || "".equals(path)) {
|
||||
if (path == null || path.isEmpty()) {
|
||||
LOG.log(POILogger.DEBUG, "illegal part name (expected)", uri);
|
||||
return null;
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ public class RelationshipTransformService extends TransformService {
|
||||
String id = el.getAttribute("Id");
|
||||
if (sourceIds.contains(id)) {
|
||||
String targetMode = el.getAttribute("TargetMode");
|
||||
if ("".equals(targetMode)) {
|
||||
if (targetMode.isEmpty()) {
|
||||
el.setAttribute("TargetMode", "Internal");
|
||||
}
|
||||
rsList.put(id, el);
|
||||
|
@ -138,14 +138,14 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
|
||||
String extension = (filename == null || filename.lastIndexOf('.') == -1) ? ".bin" : filename.substring(filename.lastIndexOf('.'));
|
||||
|
||||
// try to find an alternative name
|
||||
if (filename == null || "".equals(filename) || filename.startsWith("MBD") || filename.startsWith("Root Entry")) {
|
||||
if (filename == null || filename.isEmpty() || filename.startsWith("MBD") || filename.startsWith("Root Entry")) {
|
||||
filename = shape.getShapeName();
|
||||
if (filename != null) {
|
||||
filename += extension;
|
||||
}
|
||||
}
|
||||
// default to dummy name
|
||||
if (filename == null || "".equals(filename)) {
|
||||
if (filename == null || filename.isEmpty()) {
|
||||
filename = "picture_" + embeddings.size() + extension;
|
||||
}
|
||||
filename = filename.trim();
|
||||
|
@ -51,7 +51,7 @@ public class XSLFHyperlink implements Hyperlink<XSLFShape,XSLFTextParagraph> {
|
||||
@Override
|
||||
public String getAddress() {
|
||||
String id = _link.getId();
|
||||
if (id == null || "".equals(id)) {
|
||||
if (id == null || id.isEmpty()) {
|
||||
return _link.getAction();
|
||||
}
|
||||
|
||||
|
@ -845,7 +845,7 @@ public class XSLFTextRun implements TextRun {
|
||||
}
|
||||
// SYMBOL is missing
|
||||
|
||||
if (font == null || !font.isSetTypeface() || "".equals(font.getTypeface())) {
|
||||
if (font == null || !font.isSetTypeface() || font.getTypeface().isEmpty()) {
|
||||
font = coll.getLatin();
|
||||
}
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
|
||||
|
||||
pivotField.setAxis(STAxis.AXIS_COL);
|
||||
pivotField.setShowAll(false);
|
||||
if (valueFormat != null && !"".equals(valueFormat.trim())) {
|
||||
if (valueFormat != null && !valueFormat.trim().isEmpty()) {
|
||||
DataFormat df = parentSheet.getWorkbook().createDataFormat();
|
||||
pivotField.setNumFmtId(df.getFormat(valueFormat));
|
||||
}
|
||||
@ -440,7 +440,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
|
||||
cell.setCellType(CellType.STRING);
|
||||
dataField.setName(valueFieldName);
|
||||
dataField.setFld(columnIndex);
|
||||
if (valueFormat != null && !"".equals(valueFormat.trim())) {
|
||||
if (valueFormat != null && !valueFormat.trim().isEmpty()) {
|
||||
DataFormat df = parentSheet.getWorkbook().createDataFormat();
|
||||
dataField.setNumFmtId(df.getFormat(valueFormat));
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public final class XSSFPasswordHelper {
|
||||
|
||||
|
||||
private static QName getAttrName(String prefix, String name) {
|
||||
if (prefix == null || "".equals(prefix)) {
|
||||
if (prefix == null || prefix.isEmpty()) {
|
||||
return new QName(name);
|
||||
} else {
|
||||
return new QName(prefix+Character.toUpperCase(name.charAt(0))+name.substring(1));
|
||||
|
@ -230,7 +230,7 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
|
||||
if(sh instanceof HSLFTextShape){
|
||||
HSLFTextShape hsh = (HSLFTextShape)sh;
|
||||
final String text = hsh.getText();
|
||||
if (text == null || "".equals(text) || "*".equals(text)) {
|
||||
if (text == null || text.isEmpty() || "*".equals(text)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ public class HSLFFontInfo implements FontInfo {
|
||||
|
||||
@Override
|
||||
public void setTypeface(String typeface){
|
||||
if (typeface == null || "".equals(typeface)) {
|
||||
if (typeface == null || typeface.isEmpty()) {
|
||||
throw new IllegalArgumentException("typeface can't be null nor empty");
|
||||
}
|
||||
this.typeface = typeface;
|
||||
|
@ -323,7 +323,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<H
|
||||
}
|
||||
|
||||
name = name.replace("adj", "");
|
||||
if ("".equals(name)) {
|
||||
if (name.isEmpty()) {
|
||||
name = "1";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user