Skip to content
Merged
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
13 changes: 11 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ permissions:

jobs:
build:
# trunk builds sourceCompatibility/targetCompatibility 17 bytecode (see build.gradle),
# but is matrix-tested on both the JDK 17 runtime it targets and the JDK 21 runtime
# it may adopt later. release* branches stay JDK 17 only until they make that same move,
# since trunk fixes must stay backportable to them.
if: ${{ !(matrix.java == 21 && ((github.event_name == 'push' && startsWith(github.ref_name, 'release')) || (github.event_name == 'pull_request' && startsWith(github.base_ref, 'release')))) }}
strategy:
fail-fast: false
matrix:
java: [ 17, 21 ]

runs-on: ubuntu-latest

Expand All @@ -40,10 +49,10 @@ jobs:
- name: Check out OFBiz sources
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Set up JDK 17
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@0f481fcb613427c0f801b606911222b5b6f3083a # v5.5.0
with:
java-version: 17
java-version: ${{ matrix.java }}
distribution: temurin
cache: 'gradle'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ public static Map<String, Object> processWorkEffortEventReminders(DispatchContex
}
continue;
}
@SuppressWarnings("deprecation")
Locale locale = reminder.getString("localeId") == null ? Locale.getDefault() : new Locale(reminder.getString("localeId"));
TimeZone timeZone = reminder.getString("timeZoneId") == null ? TimeZone.getDefault()
: TimeZone.getTimeZone(reminder.getString("timeZoneId"));
Expand Down
21 changes: 19 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,16 @@ application {
mainClass = 'org.apache.ofbiz.base.start.Start'
applicationDefaultJvmArgs = project.hasProperty('jvmArgs')
? jvmArgs.tokenize()
: ['-Xms128M','-Xmx1024M',
: ['-Xms128M', '-Xmx1024M',
'-Djdk.serialFilter=maxarray=100000;maxdepth=20;maxrefs=1000;maxbytes=500000', // OFBIZ-12592 and OFBIZ-12716
'--add-opens=java.base/java.util=ALL-UNNAMED' // OFBIZ-12726
// Required for embedded Tomcat 10.1 and libraries (Groovy 5, Spring 6) under Java 17+ strong encapsulation
'--add-opens=java.base/java.lang=ALL-UNNAMED',
'--add-opens=java.base/java.io=ALL-UNNAMED',
'--add-opens=java.base/java.util=ALL-UNNAMED', // OFBIZ-12726
'--add-opens=java.base/java.util.concurrent=ALL-UNNAMED',
'--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED',
// Allow libraries using the stable Foreign Function & Memory API (Apache SSHD, Tika)
'--enable-native-access=ALL-UNNAMED',
]
}

Expand Down Expand Up @@ -163,6 +170,12 @@ tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:all'
// Exclude varargs warnings which are not silenced by @SafeVarargs.
options.compilerArgs << '-Xlint:-varargs'
// this-escape lint was introduced in JDK 21's javac and is an invalid flag on JDK 17,
// so only pass it when compiling with a JDK that recognizes it.
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_21)) {
// Exclude this-escape warnings pending proper refactoring of widget/service classes.
options.compilerArgs << '-Xlint:-this-escape'
}
}
}

Expand Down Expand Up @@ -363,6 +376,10 @@ tasks.eclipse.dependsOn(cleanEclipse)
test {
useJUnitPlatform()
jvmArgs "-javaagent:${classpath.find { it.name.contains('jmockit') }.absolutePath}"
// Required for JMockit instrumentation, Mockito, and Spring Test under Java 21
jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED'
jvmArgs '--add-opens=java.base/java.lang.reflect=ALL-UNNAMED'
jvmArgs '--enable-native-access=ALL-UNNAMED'
testLogging {
events "passed", "skipped", "failed"
}
Expand Down
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ dependencies {
runtimeOnly 'org.apache.geronimo.specs:geronimo-jaxrpc_1.1_spec:2.1'
runtimeOnly 'org.apache.logging.log4j:log4j-1.2-api:2.25.4' // for external jars using the old log4j1.2: routes logging to log4j 2
runtimeOnly 'org.apache.logging.log4j:log4j-jul:2.25.4' // for external jars using the java.util.logging: routes logging to log4j 2
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.25.4' // for external jars using slf4j: routes logging to log4j 2
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j2-impl:2.25.4' // for external jars using slf4j 2.x: routes logging to log4j 2
runtimeOnly 'org.apache.logging.log4j:log4j-web:2.25.4' //???
runtimeOnly 'org.apache.logging.log4j:log4j-jcl:2.25.4' // need to constrain to version to avoid classpath conflict (ReflectionUtil)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
@SuppressWarnings("rawtypes")
public class UtilCodec {
private static final String MODULE = UtilCodec.class.getName();
// sentinel locale used because labels are not available in the testClasses Gradle task
@SuppressWarnings("deprecation")
private static final Locale TEST_LOCALE = new Locale("test");
private static final HtmlEncoder HTML_ENCODER = new HtmlEncoder();
private static final XmlEncoder XML_ENCODER = new XmlEncoder();
private static final StringEncoder STRING_ENCODER = new StringEncoder();
Expand Down Expand Up @@ -435,7 +438,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(TEST_LOCALE)) {
issueMsg = "In field [" + valueName + "] found character escaping (mixed or double) "
+ "that is not allowed or other format consistency error: ";
} else {
Expand All @@ -448,7 +451,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(TEST_LOCALE)) {
issueMsg = "In field [" + valueName + "] less-than (<) and greater-than (>) symbols are not allowed.";
} else {
issueMsg = UtilProperties.getMessage("SecurityUiLabels", "PolicyNoneLess-thanGreater-than",
Expand All @@ -463,7 +466,7 @@ public static String checkStringForHtmlStrictNone(String valueName, String value
if (JS_EVENT_LIST.stream().anyMatch(s -> s.toLowerCase(Locale.ROOT).contains(onEventLower))
|| value.contains("seekSegmentTime")) {
String issueMsg = null;
if (locale.equals(new Locale("test"))) { // labels are not available in testClasses Gradle task
if (locale.equals(TEST_LOCALE)) {
issueMsg = "In field [" + valueName + "] Javascript events are not allowed.";
} else {
issueMsg = UtilProperties.getMessage("SecurityUiLabels", "PolicyNoneJsEvents",
Expand Down Expand Up @@ -501,7 +504,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(TEST_LOCALE)) {
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 @@ -566,7 +569,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(TEST_LOCALE)) {
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 @@ -550,6 +550,7 @@ public static <K> void addToDoubleInMap(Map<K, Object> theMap, K key, Double val
* @param localeString The locale string (en_US)
* @return Locale The new Locale object or null if no valid locale can be interpreted
*/
@SuppressWarnings("deprecation")
public static Locale parseLocale(String localeString) {
if (UtilValidate.isEmpty(localeString)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ 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);
@SuppressWarnings("deprecation") Locale thLocale = new Locale("th");
@SuppressWarnings("deprecation") Locale enInLocale = new Locale("en", "IN");
rbnfRuleSets.put(thLocale, RULE_SET_TH_TH);
rbnfRuleSets.put(enInLocale, RULE_SET_EN_IN);
}

private UtilNumber() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ public static Locale getFallbackLocale() {
* a list containing <code>en_US</code> and <code>en</code>.
* @return A list of candidate locales.
*/
@SuppressWarnings("deprecation")
public static List<Locale> localeToCandidateList(Locale locale) {
List<Locale> localeList = new LinkedList<>();
localeList.add(locale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.util.LinkedList;
Expand Down Expand Up @@ -417,7 +418,7 @@ public static Document readXmlDocument(URL url, boolean validate, boolean withPo
innerUrlStr = innerUrlStr.substring(0, bangIdx);
}
try {
urlHost = new URL(innerUrlStr).getHost();
urlHost = URI.create(innerUrlStr).toURL().getHost();
} catch (java.net.MalformedURLException e) {
throw new IOException("Cannot determine host from jar URL: " + url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

public class UtilCodecTests {

// sentinel locale used because labels are not available in the testClasses Gradle task
@SuppressWarnings("deprecation")
private static final Locale TEST_LOCALE = new Locale("test");

@Test
public void canonicalizeRevealsEscapedXSS() {
String xssVector = "&lt;script&gtalert(\"XSS vector\");&lt;/script&gt;";
Expand All @@ -42,7 +46,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
TEST_LOCALE);
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 +95,7 @@ private static void checkStringForHtmlStrictNoneTest(String label, String fixed,
String... wantedMessages) {
List<String> gottenMessages = new ArrayList<>();
assertEquals(fixed, UtilCodec.checkStringForHtmlStrictNone(label, input, gottenMessages,
new Locale("test")), label); // labels are not available in testClasses Gradle task
TEST_LOCALE), label);
assertEquals(Arrays.asList(wantedMessages), gottenMessages, label);
}

Expand All @@ -100,7 +104,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
TEST_LOCALE, true);
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,6 +35,7 @@ public class UtilPropertiesTests {

private static final String COUNTRY = "AU";
private static final String LANGUAGE = "en";
@SuppressWarnings("deprecation")
private final Locale locale = new Locale(LANGUAGE, COUNTRY);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,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 @@ -847,6 +847,7 @@ protected void setFetchSize(Statement stmt, int fetchSize) throws SQLException {
}
}

@SuppressWarnings("deprecation")
private void checkLockWaitInfo(Exception sqle) {
String eMsg = sqle.getMessage();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ protected static void removeSuspendedTransaction(Transaction t) {
// =======================================
// TRANSACTION BEGIN STACK
// =======================================
@SuppressWarnings("deprecation")
private static void pushTransactionBeginStackSave(Exception e) {
// use the ThreadLocal one because it is more reliable than the all threads Map
List<Exception> el = transactionBeginStackSave.get();
Expand All @@ -670,6 +671,7 @@ private static void pushTransactionBeginStackSave(Exception e) {
}
}

@SuppressWarnings("deprecation")
private static Exception popTransactionBeginStackSave() {
if (Debug.infoOn()) {
// do the unofficial all threads Map one first, and don't do a real return
Expand Down Expand Up @@ -741,6 +743,7 @@ private static void setTransactionBeginStack() {
setTransactionBeginStack(e);
}

@SuppressWarnings("deprecation")
private static void setTransactionBeginStack(Exception newExc) {
if (transactionBeginStack.get() != null) {
Exception e = transactionBeginStack.get();
Expand All @@ -756,6 +759,7 @@ private static void setTransactionBeginStack(Exception newExc) {
}
}

@SuppressWarnings("deprecation")
private static Exception clearTransactionBeginStack() {
if (Debug.infoOn()) {
Long curThreadId = Thread.currentThread().getId();
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 = 0;

if (dataUrl == null) {
String errMsg = "Cannot load data, dataUrl was null";
Expand All @@ -264,7 +264,7 @@ public static int loadData(URL dataUrl, String helperName, Delegator delegator,
reader.setCreateDummyFks(dummyFks);
reader.setMaintainTxStamps(maintainTxs);
reader.setContinueOnFail(continueOnFail);
rowsChanged += (int) reader.parse(dataUrl);
rowsChanged += reader.parse(dataUrl);
} catch (IOException | SAXException e) {
String xmlError = "[loadData]: Error loading XML Resource \"" + dataUrl.toExternalForm() + "\"; Error was: " + e.getMessage();
errorMessages.add(xmlError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,13 @@ private static void loadData(Delegator delegator, Delegator baseDelegator,
List<URL> urlList = prepareDataUrls(delegator, baseDelegator, allComponents, helperInfo, loadDataProps);
List<String> infoMessages = new ArrayList<>();
List<Object> errorMessages = new ArrayList<>();
int totalRowsChanged = 0;
long totalRowsChanged = 0;

logDataLoadingPlan(urlList, delegator.getDelegatorName());

for (URL dataUrl: urlList) {
try {
int rowsChanged = EntityDataLoader.loadData(dataUrl, helperInfo.getHelperBaseName(),
long rowsChanged = EntityDataLoader.loadData(dataUrl, helperInfo.getHelperBaseName(),
delegator, errorMessages, txTimeout, useDummyFks, maintainTxs, tryInserts, continueOnFail);
totalRowsChanged += rowsChanged;
infoMessages.add(createDataLoadMessage(dataUrl, rowsChanged, totalRowsChanged));
Expand Down Expand Up @@ -570,7 +570,7 @@ private static void logDataLoadingPlan(List<URL> urlList, String delegatorName)
}
}

private static String createDataLoadMessage(URL dataUrl, int rowsChanged, int totalRowsChanged) {
private static String createDataLoadMessage(URL dataUrl, long rowsChanged, long totalRowsChanged) {
NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setMinimumIntegerDigits(5);
formatter.setGroupingUsed(false);
Expand All @@ -580,7 +580,7 @@ private static String createDataLoadMessage(URL dataUrl, int rowsChanged, int to
}

private static void logDataLoadingResults(List<String> infoMessages,
List<Object> errorMessages, int totalRowsChanged) {
List<Object> errorMessages, long totalRowsChanged) {

if (UtilValidate.isNotEmpty(infoMessages)) {
Debug.logImportant("=-=-=-=-=-=-= Here is a summary of the data load:", MODULE);
Expand Down
Loading
Loading