Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (context.delivProductId && (parameters.partyId || parameters.contentLocale))

Locale contentLocale = null
if (parameters.contentLocale) {
contentLocale = new Locale(parameters.contentLocale)
contentLocale = Locale.of(parameters.contentLocale)
}
delivProductContentsForLocaleAndUser = []
delivProductContents.each { delivProductContent ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ public static Map<String, Object> processWorkEffortEventReminders(DispatchContex
}
continue;
}
Locale locale = reminder.getString("localeId") == null ? Locale.getDefault() : new Locale(reminder.getString("localeId"));
Locale locale = reminder.getString("localeId") == null ? Locale.getDefault() : Locale.of(reminder.getString("localeId"));
TimeZone timeZone = reminder.getString("timeZoneId") == null ? TimeZone.getDefault()
: TimeZone.getTimeZone(reminder.getString("timeZoneId"));
Map<String, Object> parameters = UtilMisc.toMap("locale", locale, "timeZone", timeZone, "workEffortId", reminder.get("workEffortId"));
Expand Down
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ javadoc {
title="OFBiz " + getCurrentGitBranch() + " API"
failOnError = true
options {
source '17'
source '21'
encoding 'UTF-8'
charSet 'UTF-8'
// Those external Javadoc links should correspond to the actual
// versions declared in the 'dependencies' block.
links(
'https://docs.oracle.com/javase/17/docs/api',
'https://docs.oracle.com/javase/21/docs/api',
'https://tomcat.apache.org/tomcat-10.1-doc/servletapi/',
'http://docs.groovy-lang.org/docs/groovy-4.0.22/html/api',
'https://commons.apache.org/proper/commons-cli/apidocs'
Expand All @@ -153,8 +153,8 @@ javadoc {
}

java {
sourceCompatibility(JavaVersion.VERSION_17)
targetCompatibility(JavaVersion.VERSION_17)
sourceCompatibility(JavaVersion.VERSION_21)
targetCompatibility(JavaVersion.VERSION_21)
}

// Java compile options, syntax gradlew -PXlint:none build
Expand All @@ -164,6 +164,7 @@ tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:all'
// Exclude varargs warnings which are not silenced by @SafeVarargs.
options.compilerArgs << '-Xlint:-varargs'
options.compilerArgs << '-Xlint:-this-escape'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public static String checkStringForHtmlStrictNone(String valueName, String value
Debug.logError("Canonicalization (format consistency, character escaping that is mixed or double, etc) "
+ "error for attribute named [" + valueName + "], String [" + value + "]: " + e.toString(), MODULE);
String issueMsg = null;
if (locale.equals(new Locale("test"))) { // labels are not available in testClasses Gradle task
if (locale.equals(Locale.of("test"))) { // labels are not available in testClasses Gradle task
issueMsg = "In field [" + valueName + "] found character escaping (mixed or double) "
+ "that is not allowed or other format consistency error: ";
} else {
Expand All @@ -448,7 +448,7 @@ public static String checkStringForHtmlStrictNone(String valueName, String value
// check for "<", ">"
if (value.indexOf("<") >= 0 || value.indexOf(">") >= 0) {
String issueMsg = null;
if (locale.equals(new Locale("test"))) { // labels are not available in testClasses Gradle task
if (locale.equals(Locale.of("test"))) { // labels are not available in testClasses Gradle task
issueMsg = "In field [" + valueName + "] less-than (<) and greater-than (>) symbols are not allowed.";
} else {
issueMsg = UtilProperties.getMessage("SecurityUiLabels", "PolicyNoneLess-thanGreater-than",
Expand All @@ -462,7 +462,7 @@ public static String checkStringForHtmlStrictNone(String valueName, String value
if (JS_EVENT_LIST.stream().anyMatch(str -> StringUtils.containsIgnoreCase(str, onEvent))
|| value.contains("seekSegmentTime")) {
String issueMsg = null;
if (locale.equals(new Locale("test"))) { // labels are not available in testClasses Gradle task
if (locale.equals(Locale.of("test"))) { // labels are not available in testClasses Gradle task
issueMsg = "In field [" + valueName + "] Javascript events are not allowed.";
} else {
issueMsg = UtilProperties.getMessage("SecurityUiLabels", "PolicyNoneJsEvents",
Expand Down Expand Up @@ -500,7 +500,7 @@ public static String checkStringForHtmlSafe(String valueName, String value, List
PolicyFactory policy = null;
try {
Class<?> customPolicyClass = null;
if (locale.equals(new Locale("test"))) { // labels are not available in testClasses Gradle task
if (locale.equals(Locale.of("test"))) { // labels are not available in testClasses Gradle task
customPolicyClass = Class.forName("org.apache.ofbiz.base.html.CustomSafePolicy");
} else {
customPolicyClass = Class.forName(UtilProperties.getPropertyValue("owasp", "sanitizer.custom.safe.policy.class"));
Expand Down Expand Up @@ -565,7 +565,7 @@ public void closeDocument() {
// Maybe later we will figure out that some more HTML entities will need to be added to here, see OFBIZ-12691
if (filtered != null && !value.replace("&#39;", "'").replace("&#34;", "\"").replace("&#64;", "@").equals(unescapeEcmaScriptAndHtml4)) {
String issueMsg = null;
if (locale.equals(new Locale("test"))) { // labels are not available in testClasses Gradle task
if (locale.equals(Locale.of("test"))) { // labels are not available in testClasses Gradle task
issueMsg = "In field [" + valueName + "] by our input policy, your input has not been accepted "
+ "for security reason. Please check and modify accordingly, thanks.";
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ public static Locale parseLocale(String localeString) {
String language = localeString.substring(0, 2);
String country = localeString.substring(3, 5);
String extension = localeString.substring(6);
locale = new Locale(language, country, extension);
locale = Locale.of(language, country, extension);
} else {
Debug.logWarning("Do not know what to do with the localeString [" + localeString + "], should be length 2, 5, or greater than 6, "
+ "returning null", MODULE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ public final class UtilNumber {
static {
rbnfRuleSets = new HashMap<>();
rbnfRuleSets.put(Locale.US, RULE_SET_EN_US);
rbnfRuleSets.put(new Locale("th"), RULE_SET_TH_TH);
rbnfRuleSets.put(new Locale("en", "IN"), RULE_SET_EN_IN);
rbnfRuleSets.put(Locale.of("th"), RULE_SET_TH_TH);
rbnfRuleSets.put(Locale.of("en", "IN"), RULE_SET_EN_IN);
}

private UtilNumber() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ public static List<Locale> localeToCandidateList(Locale locale) {
int pos = localeString.lastIndexOf("_", localeString.length());
while (pos != -1) {
localeString = localeString.substring(0, pos);
localeList.add(new Locale(localeString));
localeList.add(Locale.of(localeString));
pos = localeString.lastIndexOf("_", localeString.length());
}
return localeList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
import java.util.Locale;
import java.util.Map;

import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.StringUtil;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.apache.ofbiz.base.util.UtilMisc;
import org.apache.ofbiz.base.util.collections.LocalizedMap;

import jakarta.el.ArrayELResolver;
import jakarta.el.BeanELResolver;
import jakarta.el.CompositeELResolver;
Expand All @@ -40,12 +46,6 @@
import jakarta.el.ValueExpression;
import jakarta.el.VariableMapper;

import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.StringUtil;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.apache.ofbiz.base.util.UtilMisc;
import org.apache.ofbiz.base.util.collections.LocalizedMap;

/** Implements the Unified Expression Language (JSR-245). */
public final class UelUtil {
private static final String MODULE = UelUtil.class.getName();
Expand Down Expand Up @@ -225,9 +225,10 @@ public Class<?> getType(ELContext context) {
return this.getExpectedType();
}

@SuppressWarnings("unchecked")
@Override
public Object getValue(ELContext context) {
return this.object;
public <T> T getValue(ELContext context) {
return (T) this.object;
}

@Override
Expand Down Expand Up @@ -292,9 +293,10 @@ public boolean equals(Object obj) {
public int hashCode() {
return this.varName.hashCode();
}
@SuppressWarnings("unchecked")
@Override
public Object getValue(ELContext context) {
return this.elContext.variables.get(this.varName);
public <T> T getValue(ELContext context) {
return (T) this.elContext.variables.get(this.varName);
}
@Override
public String getExpressionString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void checkStringForHtmlStrictNoneDetectsXSS() {
String xssVector = "&lt;script&gtalert(\"XSS vector\");&lt;/script&gt;";
List<String> errorList = new ArrayList<>();
String canonicalizedXssVector = UtilCodec.checkStringForHtmlStrictNone("fieldName", xssVector, errorList,
new Locale("test")); // labels are not available in testClasses Gradle task
Locale.of("test")); // labels are not available in testClasses Gradle task
assertEquals("<script>alert(\"XSS vector\");</script>", canonicalizedXssVector);
assertEquals(1, errorList.size());
assertEquals("In field [fieldName] less-than (<) and greater-than (>) symbols are not allowed.",
Expand Down Expand Up @@ -91,7 +91,7 @@ private static void checkStringForHtmlStrictNoneTest(String label, String fixed,
String... wantedMessages) {
List<String> gottenMessages = new ArrayList<>();
assertEquals(label, fixed, UtilCodec.checkStringForHtmlStrictNone(label, input, gottenMessages,
new Locale("test"))); // labels are not available in testClasses Gradle task
Locale.of("test"))); // labels are not available in testClasses Gradle task
assertEquals(label, Arrays.asList(wantedMessages), gottenMessages);
}

Expand All @@ -100,7 +100,7 @@ public void testCheckStringForHtmlSafe() {
String xssVector = "<script>alert('XSS vector');</script>";
List<String> errorList = new ArrayList<>();
String canonicalizedXssVector = UtilCodec.checkStringForHtmlSafe("fieldName", xssVector, errorList,
new Locale("test"), true); // labels are not available in testClasses Gradle task
Locale.of("test"), true); // labels are not available in testClasses Gradle task
assertEquals("<script>alert('XSS vector');</script>", canonicalizedXssVector);
assertEquals(1, errorList.size());
assertEquals("In field [fieldName] by our input policy, your input has not been accepted for security reason. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class UtilPropertiesTests {

private static final String COUNTRY = "AU";
private static final String LANGUAGE = "en";
private final Locale locale = new Locale(LANGUAGE, COUNTRY);
private final Locale locale = Locale.of(LANGUAGE, COUNTRY);

/**
* Old style xml:lang attribute value was of form en_AU. Test this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.junit.Test;

public class FlexibleMapAccessorTests {
private static final Locale LOCALE_TO_TEST = new Locale("en", "US");
private static final Locale LOCALE_TO_TEST = Locale.of("en", "US");
private static FlexibleMapAccessor<?> fmaEmpty = FlexibleMapAccessor.getInstance("");
private static FlexibleMapAccessor<?> fmaNull = FlexibleMapAccessor.getInstance(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import org.junit.Test;

public class FlexibleStringExpanderTests {
private static final Locale LOCALE_TO_TEST = new Locale("en", "US");
private static final Locale BAD_LOCALE = new Locale("fr");
private static final Locale LOCALE_TO_TEST = Locale.of("en", "US");
private static final Locale BAD_LOCALE = Locale.of("fr");
private static final TimeZone TIME_ZONE_TO_TEST = TimeZone.getTimeZone("PST");
private static final TimeZone BAD_TIME_ZONE = TimeZone.getTimeZone("GMT");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
import java.util.Map;

import javax.imageio.ImageIO;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
Expand All @@ -62,6 +59,10 @@
import org.apache.ofbiz.widget.model.ThemeFactory;
import org.apache.ofbiz.widget.renderer.VisualTheme;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

/**
* Common Services
*/
Expand Down Expand Up @@ -438,7 +439,7 @@ public static String openSourceFile(HttpServletRequest request, HttpServletRespo
String cmd = (String) FlexibleStringExpander.getInstance(cmdTemplate).expand(sourceMap);
// run command
Debug.logInfo("Run command: " + cmd, MODULE);
Process process = Runtime.getRuntime().exec(cmd);
Process process = Runtime.getRuntime().exec(new String[]{cmd});
// print result
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ private void checkLockWaitInfo(Exception sqle) {
// the string for Derby is "A lock could not be obtained within the time requested"
// the string for MySQL is "Lock wait timeout exceeded; try restarting transaction"
if (eMsg.contains("A lock could not be obtained within the time requested") || eMsg.contains("Lock wait timeout exceeded")) {
Debug.logWarning(sqle, "Lock wait timeout error found in thread [" + Thread.currentThread().getId() + "]: (" + eMsg
Debug.logWarning(sqle, "Lock wait timeout error found in thread [" + Thread.currentThread().threadId() + "]: (" + eMsg
+ ") when executing the SQL [" + sql + "]", MODULE);
TransactionUtil.printAllThreadsTransactionBeginStacks();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ private static void pushTransactionBeginStackSave(Exception e) {
el.add(0, e);

if (Debug.infoOn()) {
Long curThreadId = Thread.currentThread().getId();
Long curThreadId = Thread.currentThread().threadId();
List<Exception> ctEl = allThreadsTransactionBeginStackSave.get(curThreadId);
if (ctEl == null) {
ctEl = new LinkedList<>();
Expand All @@ -673,7 +673,7 @@ private static void pushTransactionBeginStackSave(Exception e) {
private static Exception popTransactionBeginStackSave() {
if (Debug.infoOn()) {
// do the unofficial all threads Map one first, and don't do a real return
Long curThreadId = Thread.currentThread().getId();
Long curThreadId = Thread.currentThread().threadId();
List<Exception> ctEl = allThreadsTransactionBeginStackSave.get(curThreadId);
if (UtilValidate.isNotEmpty(ctEl)) {
ctEl.remove(0);
Expand Down Expand Up @@ -751,14 +751,14 @@ private static void setTransactionBeginStack(Exception newExc) {
}
transactionBeginStack.set(newExc);
if (Debug.infoOn()) {
Long curThreadId = Thread.currentThread().getId();
Long curThreadId = Thread.currentThread().threadId();
allThreadsTransactionBeginStack.put(curThreadId, newExc);
}
}

private static Exception clearTransactionBeginStack() {
if (Debug.infoOn()) {
Long curThreadId = Thread.currentThread().getId();
Long curThreadId = Thread.currentThread().threadId();
allThreadsTransactionBeginStack.remove(curThreadId);
}
Exception e = transactionBeginStack.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,23 +225,23 @@ public static List<URL> getUrlByComponentList(String helperName, List<String> co
return getUrlByComponentList(helperName, components, readerNames);
}

public static int loadData(URL dataUrl, String helperName, Delegator delegator, List<Object> errorMessages) throws GenericEntityException {
public static long loadData(URL dataUrl, String helperName, Delegator delegator, List<Object> errorMessages) throws GenericEntityException {
return loadData(dataUrl, helperName, delegator, errorMessages, -1);
}

public static int loadData(URL dataUrl, String helperName, Delegator delegator, List<Object> errorMessages, int txTimeout)
public static long loadData(URL dataUrl, String helperName, Delegator delegator, List<Object> errorMessages, int txTimeout)
throws GenericEntityException {
return loadData(dataUrl, helperName, delegator, errorMessages, txTimeout, false, false, false);
}

public static int loadData(URL dataUrl, String helperName, Delegator delegator, List<Object> errorMessages, int txTimeout, boolean dummyFks,
public static long loadData(URL dataUrl, String helperName, Delegator delegator, List<Object> errorMessages, int txTimeout, boolean dummyFks,
boolean maintainTxs, boolean tryInsert) throws GenericEntityException {
return loadData(dataUrl, helperName, delegator, errorMessages, txTimeout, false, false, false, true);
}

public static int loadData(URL dataUrl, String helperName, Delegator delegator, List<Object> errorMessages, int txTimeout, boolean dummyFks,
public static long loadData(URL dataUrl, String helperName, Delegator delegator, List<Object> errorMessages, int txTimeout, boolean dummyFks,
boolean maintainTxs, boolean tryInsert, boolean continueOnFail) throws GenericEntityException {
int rowsChanged = 0;
Long rowsChanged = (long) 0;

if (dataUrl == null) {
String errMsg = "Cannot load data, dataUrl was null";
Expand Down
Loading
Loading