From a80c72edbd2108bdcc5b8b8bce5e9f4a9167d754 Mon Sep 17 00:00:00 2001 From: ehennestad Date: Wed, 21 Oct 2026 20:14:44 +0200 Subject: [PATCH] fix: error early when an .mltbx license dialog cannot be shown Before R2026b, matlab.addons.install shows the license agreement of an .mltbx add-on in a dialog unless agreeToLicense is true. With no display, as on a CI runner, R2023a to R2024b throw java.awt.HeadlessException, and on R2025a to R2026a the install did not return. installFexPackage passes false when AgreeToLicense is omitted, so installRequirements failed or stalled for any File Exchange requirement served as .mltbx. installFexPackage now raises MatBox:Setup:LicenseDialogUnavailable before downloading such an add-on when the license is not accepted and Java is headless, and says to pass AgreeToLicense=true. SetupTest installs its requirements with AgreeToLicenses=true, and a new test checks the error where no display is available. The test requirement fex://160058-recursively-list-files-and-folders exposed this when version 1.0.4 started being served as .mltbx; 1.0.0 to 1.0.3 resolve to a zip and install as a folder. Co-Authored-By: Claude Opus 5.5 --- .../+setup/+internal/installFexPackage.m | 22 ++++++++++++++++++- .../tests/+matboxtools/+unittest/SetupTest.m | 21 ++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/code/+matbox/+setup/+internal/installFexPackage.m b/code/+matbox/+setup/+internal/installFexPackage.m index eef2f47..4730ebc 100644 --- a/code/+matbox/+setup/+internal/installFexPackage.m +++ b/code/+matbox/+setup/+internal/installFexPackage.m @@ -105,8 +105,17 @@ end elseif endsWith(addonUrl, '/mltbx') - [tempFilepath, C] = matbox.setup.internal.utility.tempsave(addonUrl, [toolboxIdentifier, '_temp.mltbx']); isLicenseOptionSupported = isMATLABReleaseOlderThan("R2026b"); + if isLicenseOptionSupported && ~isLicenseAgreed && ~canShowLicenseDialog() + fprintf(newline) + error("MatBox:Setup:LicenseDialogUnavailable", ... + ['Installing "%s" shows its license agreement in a dialog, and ', ... + 'this MATLAB session cannot display one. Pass AgreeToLicense=true ', ... + '(AgreeToLicenses=true in installRequirements) to accept the ', ... + 'license without the dialog.'], toolboxName) + end + + [tempFilepath, C] = matbox.setup.internal.utility.tempsave(addonUrl, [toolboxIdentifier, '_temp.mltbx']); if isLicenseOptionSupported installedAddon = matlab.addons.install(tempFilepath, isLicenseAgreed); else @@ -142,6 +151,17 @@ end end +function tf = canShowLicenseDialog() +% canShowLicenseDialog - Whether this session can display the add-on license dialog +% +% Before R2026b, matlab.addons.install shows the license agreement of an +% .mltbx add-on in a Java Swing dialog unless agreeToLicense is true. +% Java is headless when there is no display, as on a CI runner, and +% creating the dialog then throws java.awt.HeadlessException. + + tf = usejava("jvm") && ~java.awt.GraphicsEnvironment.isHeadless(); +end + function toolboxName = retrieveToolboxName(toolboxIdentifier) fex = matlab.addons.repositories.FileExchangeRepository(); diff --git a/tools/tests/+matboxtools/+unittest/SetupTest.m b/tools/tests/+matboxtools/+unittest/SetupTest.m index aca8cbe..a8996d9 100644 --- a/tools/tests/+matboxtools/+unittest/SetupTest.m +++ b/tools/tests/+matboxtools/+unittest/SetupTest.m @@ -64,6 +64,18 @@ function testOmittedAgreeToLicenseDoesNotWarn(testCase) [~, lastWarningId] = lastwarn(); testCase.verifyNotEqual(lastWarningId, 'MatBox:Setup:AgreeToLicenseIgnored') end + + function testOmittedAgreeToLicenseWithoutDisplayErrors(testCase) + testCase.assumeTrue(isMATLABReleaseOlderThan("R2026b"), ... + "From R2026b MATLAB installs an add-on without a license dialog.") + testCase.assumeTrue(usejava("jvm") && java.awt.GraphicsEnvironment.isHeadless(), ... + "This session can display the license dialog.") + testCase.uninstallFexAddon(testCase.FexMltbxUri) + + testCase.verifyError( ... + @() matbox.setup.installFromSourceUri(testCase.FexMltbxUri, "InstallationLocation", pwd), ... + "MatBox:Setup:LicenseDialogUnavailable") + end end methods @@ -88,11 +100,16 @@ function installRequirements(testCase, options) pathStr = matboxtools.projectdir(); requirementsPath = fullfile(pathStr, "tools", "tests", "test_resources"); + % The requirements include an .mltbx add-on. Before R2026b, + % installing one without accepting its license shows a dialog, + % which a session without a display, such as CI, cannot show. try if options.Update - matbox.installRequirements(requirementsPath, "u", "InstallationLocation", pwd) + matbox.installRequirements(requirementsPath, "u", ... + "InstallationLocation", pwd, "AgreeToLicenses", true) else - matbox.installRequirements(requirementsPath, "InstallationLocation", pwd) + matbox.installRequirements(requirementsPath, ... + "InstallationLocation", pwd, "AgreeToLicenses", true) end catch ME testCase.verifyFail(ME.message)