Skip to content

Commit

Permalink
use isEmpty (NPE safe) instead of length check
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Mar 15, 2024
1 parent e50fa18 commit de06631
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/lucee/commons/cli/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private static void populateList(StringBuilder sb, ArrayList<String> list) {

String tmp = sb.toString();
tmp = tmp.trim();
if (tmp.length() > 0) list.add(tmp);
if (!StringUtil.isEmpty(tmp)) list.add(tmp);
sb.delete(0, sb.length());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public static void compressZip(Resource[] sources, ZipOutputStream zos, Resource
}

private static void compressZip(String parent, Resource[] sources, ZipOutputStream zos, ResourceFilter filter) throws IOException {
if (parent.length() > 0) parent += "/";
if (!StringUtil.isEmpty(parent)) parent += "/";
if (sources != null) {
for (int i = 0; i < sources.length; i++) {
compressZip(parent + sources[i].getName(), sources[i], zos, filter);
Expand Down Expand Up @@ -581,7 +581,7 @@ public static void compressTar(Resource[] sources, OutputStream target, int mode

public static void compressTar(String parent, Resource[] sources, TarArchiveOutputStream tos, int mode) throws IOException {

if (parent.length() > 0) parent += "/";
if (!StringUtil.isEmpty(parent)) parent += "/";
if (sources != null) {
for (int i = 0; i < sources.length; i++) {
compressTar(parent + sources[i].getName(), sources[i], tos, mode);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/lucee/commons/io/compress/ZipUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public final class ZipUtil {

public static void unzip(Resource zip, Resource dir) throws IOException {
if (zip.length() > 0 && (dir.exists() || dir.mkdirs())) {
if (zip != null && zip.length() > 0 && (dir.exists() || dir.mkdirs())) {
if ("Mac OS X".equalsIgnoreCase(System.getProperty("os.name"))) {
try {
// Command.execute("unzip "+zip+" -d "+dir);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/commons/lang/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -904,11 +904,11 @@ public static int indexOfIgnoreCase(String haystack, String needle, int offset)
* @return is first of given type
*/
public static boolean startsWith(String str, char prefix) {
return str != null && str.length() > 0 && str.charAt(0) == prefix;
return !StringUtil.isEmpty(str) && str.charAt(0) == prefix;
}

public static boolean startsWith(String str, char prefix1, char prefix2) {
return str != null && str.length() > 0 && (str.charAt(0) == prefix1 || str.charAt(0) == prefix2);
return !StringUtil.isEmpty(str) && (str.charAt(0) == prefix1 || str.charAt(0) == prefix2);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/lucee/runtime/ComponentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties

if (top.properties.modifier != Member.MODIFIER_NONE)
table.appendRow(1, new SimpleDumpData("Modifier"), new SimpleDumpData(ComponentUtil.toModifier(top.properties.modifier, "")));
if (top.properties.hint.trim().length() > 0) table.appendRow(1, new SimpleDumpData("Hint"), new SimpleDumpData(top.properties.hint));
if (!StringUtil.isEmpty(top.properties.hint, true)) table.appendRow(1, new SimpleDumpData("Hint"), new SimpleDumpData(top.properties.hint));

// this
DumpTable thisScope = thisScope(top, pageContext, maxlevel, dp, access);
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/lucee/runtime/ComponentPageImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ else if ((method = getURLorForm(pc, KeyConstants._method, null)) != null) {
// DUMP
if (!req.getServletPath().equalsIgnoreCase("/Web." + (lucee.runtime.config.Constants.getCFMLComponentExtension()))) {
String cdf = pc.getConfig().getComponentDumpTemplate();

if (cdf != null && cdf.trim().length() > 0) {
if (!StringUtil.isEmpty(cdf, true)) {
pc.variablesScope().set(KeyConstants._component, component);
pc.doInclude(cdf, false);
}
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/lucee/runtime/InterfacePageImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package lucee.runtime;

import lucee.commons.lang.ExceptionUtil;
import lucee.commons.lang.StringUtil;
import lucee.runtime.dump.DumpUtil;
import lucee.runtime.dump.DumpWriter;
import lucee.runtime.exp.ApplicationException;
Expand All @@ -31,10 +32,12 @@
*/
public abstract class InterfacePageImpl extends InterfacePage implements PagePro {

@Override
public int getHash() {
return 0;
}

@Override
public long getSourceLength() {
return 0;
}
Expand Down Expand Up @@ -76,7 +79,7 @@ else if (qs != null && qs.trim().equalsIgnoreCase("wsdl"))
// DUMP
// TODO component.setAccess(pc,Component.ACCESS_PUBLIC);
String cdf = pc.getConfig().getComponentDumpTemplate();
if (cdf != null && cdf.trim().length() > 0) {
if (!StringUtil.isEmpty(cdf)) {
pc.variablesScope().set(KeyConstants._component, interf);
pc.doInclude(cdf, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public QueryColumn getColumn(String key, QueryColumn defaultValue) {
@Override

public QueryColumn getColumn(Key key, QueryColumn defaultValue) {
if (key.getString().length() > 0) {
if (!StringUtil.isEmpty(key.getString())) {
char c = key.lowerCharAt(0);
if (c == 'r') {
if (key.equals(KeyConstants._RECORDCOUNT)) return new QueryColumnRef(this, key, Types.INTEGER);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/lucee/runtime/type/util/ArrayUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ else if (o instanceof char[]) {
char[] arr = ((char[]) o);
if (arr.length > index) {
String str = Caster.toString(value, null);
if (str != null && str.length() > 0) {
if (!StringUtil.isEmpty(str)) {
char c = str.charAt(0);
arr[index] = c;
return str;
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/lucee/runtime/type/util/ListUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public static Array listToArrayTrim(String list, String delimiter) {
char c;

// remove at start
outer: while (list.length() > 0) {
outer: while (!StringUtil.isEmpty(list)) {
c = list.charAt(0);
for (int i = 0; i < del.length; i++) {
if (c == del[i]) {
Expand All @@ -390,7 +390,7 @@ public static Array listToArrayTrim(String list, String delimiter) {
}

int len;
outer: while (list.length() > 0) {
outer: while (!StringUtil.isEmpty(list)) {
c = list.charAt(list.length() - 1);
for (int i = 0; i < del.length; i++) {
if (c == del[i]) {
Expand Down Expand Up @@ -420,7 +420,7 @@ public static Array listToArrayTrim(String list, String delimiter, int[] info) {
char c;

// remove at start
outer: while (list.length() > 0) {
outer: while (!StringUtil.isEmpty(list)) {
c = list.charAt(0);
for (int i = 0; i < del.length; i++) {
if (c == del[i]) {
Expand All @@ -433,7 +433,7 @@ public static Array listToArrayTrim(String list, String delimiter, int[] info) {
}

int len;
outer: while (list.length() > 0) {
outer: while (!StringUtil.isEmpty(list)) {
c = list.charAt(list.length() - 1);
for (int i = 0; i < del.length; i++) {
if (c == del[i]) {
Expand Down Expand Up @@ -543,7 +543,7 @@ public static String listInsertAt(String list, int pos, String value, String del

// remove at start
if (ignoreEmpty) {
outer: while (list.length() > 0) {
outer: while (!StringUtil.isEmpty(list)) {
c = list.charAt(0);
for (int i = 0; i < del.length; i++) {
if (c == del[i]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;

import lucee.commons.lang.ExceptionUtil;
import lucee.commons.lang.StringUtil;
import lucee.runtime.Component;
import lucee.runtime.exp.PageException;
import lucee.runtime.exp.PageRuntimeException;
Expand Down Expand Up @@ -1126,7 +1127,7 @@ private LitNumber number(Data data) throws TemplateException {
if (data.srcCode.forwardIfCurrent('.')) {
rtn.append('.');
String rightSite = digit(data);
if (rightSite.length() > 0 && data.srcCode.forwardIfCurrent('e')) {
if (!StringUtil.isEmpty(rightSite) && data.srcCode.forwardIfCurrent('e')) {
Boolean expOp = null;
if (data.srcCode.forwardIfCurrent('+')) expOp = Boolean.TRUE;
else if (data.srcCode.forwardIfCurrent('-')) expOp = Boolean.FALSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ public static Expression attributeValue(Data data, TagLibTag tag, String type, b
}
else expr = transfomer.transform(data);
}
if (type.length() > 0) {
if (!StringUtil.isEmpty(type)) {
expr = data.factory.toExpression(expr, type);
}
}
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.1.0.74-SNAPSHOT"/>
<property name="version" value="6.1.0.75-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.1.0.74-SNAPSHOT</version>
<version>6.1.0.75-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down
4 changes: 2 additions & 2 deletions loader/src/main/java/coldfusion/cfc/CFCProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.Map;
import java.util.Map.Entry;

import /* JAVJAK */ javax.servlet.http.HttpServletRequest;
import /* JAVJAK */ javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lucee.loader.engine.CFMLEngine;
import lucee.loader.engine.CFMLEngineFactory;
Expand Down

0 comments on commit de06631

Please sign in to comment.