Bugfix: Replace removed sun.misc Base64 classes with java.util.Base64 - #942
Bugfix: Replace removed sun.misc Base64 classes with java.util.Base64#942bdthombre wants to merge 1 commit into
sun.misc Base64 classes with java.util.Base64#942Conversation
…e64`
`sun.misc.BASE64Decoder` and `sun.misc.BASE64Encoder` are internal JDK classes
that were removed in Java 9. Matlab versions shipping a newer JRE (e.g. R2026a,
Java 11) fail to even parse the files that import them:
Error: File: import_label.m Line: 27 Column: 8
Unable to find or import 'sun.misc.BASE64Decoder'.
This breaks importing any anatomy with FreeSurfer/CAT12 labels, reading and
writing GIFTI surfaces, and the snapshots in HTML reports.
Added `bst_base64()` in toolbox/misc, which uses `java.util.Base64` (Java >= 8)
and falls back to `matlab.net.base64decode/encode` (Matlab >= R2016b) and then
to the old `sun.misc` classes, so older installations keep working.
Like the previous decoder, it tolerates line breaks and white spaces in the
encoded string, and it strips the line breaks when encoding.
Updated the callers:
- import_label.m, in_tess_gii.m: removed the unused imports
- in_gii.m: decoding of Base64Binary / GZipBase64Binary data arrays
- out_tess_gii.m: encoding of the vertices and faces
- bst_report.m: encoding of the PNG snapshots
Tested with Matlab R2026a (Java 11): Base64 round-trip on random bytes, on
known test vectors and on line-wrapped input; and read/write round-trip of a
GZipBase64Binary .gii surface (7861 vertices, 15359 faces) returning identical
vertices and faces.
|
@bdthombre thank you for your contribution! This is issue has been already reported in the forum:
In those cases we pointed the user to install JDK8 and set Matlab to use it. The proposed wrapper in this PR can help with this, so the user will not need to manually install and set JDK8. Indeed, I made a proof-of-concept that was not merged: rcassani@e5dfb01 We will thoroughly test the proposed changes, this may take a bit because there are multiple places where Brainstorm uses the JDK. Moreover, Brainstorm runs in multiple versions of Matlab, different OS and CPU architectures. In the mean while you can setup JDK8 manually. I think this is an issue only for Matlab macOS, and not only for 2026a, but earlier versions (as per the forum posts). AFAIK in Linux and Windows, Matlab is still shipped with JKD8. |
|
Thanks. Please do what is best for your project, locally this solution is working without any issues so far since then for me, just to keep you informed. If any issues comes I'll post. |
Fixes #941
Problem
sun.misc.BASE64Decoderandsun.misc.BASE64Encoderare JDK-internal classes that were removed in Java 9. Matlab versions shipping a newer JRE (R2026a uses Java 11) cannot even parse the files that import them:Because an
importis resolved when the function is parsed, even the two files that never use the decoder crash. This breaks importing any anatomy with FreeSurfer/CAT12 labels, reading and writing GIFTI surfaces, and the snapshots in HTML reports.Changes
Added
bst_base64()intoolbox/misc, so the Java dependency lives in a single place:It uses
java.util.Base64(Java >= 8), and falls back tomatlab.net.base64decode/encode(Matlab >= R2016b) and then to the oldsun.miscclasses, so older installations keep working unchanged.To keep the behaviour identical to the previous code, the helper:
decodeBufferdid),int8when decoding (asdecodeBufferdid), so the existingtypecast()anddunzip()calls are unchanged,Updated callers:
toolbox/io/import_label.mimporttoolbox/io/in_tess_gii.mimporttoolbox/io/in_gii.mBase64Binary/GZipBase64Binarydata arraystoolbox/io/out_tess_gii.mtoolbox/process/bst_report.mTesting
Matlab R2026a Update 4 (Java 11.0.32), macOS:
float32arrays, on known test vectors (Brainstorm<->QnJhaW5zdG9ybQ==), and on CRLF-wrapped input: all exactin_gii/in_tess_giion aGZipBase64Binarysurface (external/ImaGIN/private/SEEG_cortex_hip_amy_8196.surf.gii): 7861 vertices, 15359 faces decoded correctlyin_tess_gii->out_tess_gii->in_tess_giiround-trip: faces identical, vertex max difference 0Happy to adjust the naming or the location of the helper if you prefer something else.