LandOfSignals (Railroad Signal Mod)

LandOfSignals (Railroad Signal Mod)

45.9k Downloads

Improved errorhandling with special characters in contentpacks

Danielxs01 opened this issue ยท 3 comments

commented

Improved errorhandling with special characters in contentpacks

As mentioned under help on our discord. Special characters produce the following stacktrace:

Caused by: java.lang.RuntimeException: Could not load mod landofsignals
	at net.landofrails.landofsignals.Mod.<clinit>(Mod.java:13)
	... 38 more
Caused by: java.lang.IllegalArgumentException: MALFORMED
	at java.util.zip.ZipCoder.toString(ZipCoder.java:58)
	at java.util.zip.ZipFile.getZipEntry(ZipFile.java:567)
	at java.util.zip.ZipFile.access$900(ZipFile.java:61)
	at java.util.zip.ZipFile$ZipEntryIterator.next(ZipFile.java:525)
	at java.util.zip.ZipFile$ZipEntryIterator.next(ZipFile.java:481)
	at java.util.Iterator.forEachRemaining(Iterator.java:116)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
	at net.landofrails.landofsignals.utils.contentpacks.ContentPackHandler.loadAsset(ContentPackHandler.java:54)
	at net.landofrails.landofsignals.utils.contentpacks.ContentPackHandler.loadAssets(ContentPackHandler.java:36)
	at net.landofrails.landofsignals.utils.contentpacks.ContentPackHandler.init(ContentPackHandler.java:21)
	at net.landofrails.landofsignals.LandOfSignals.commonEvent(LandOfSignals.java:46)
	at cam72cam.mod.ModCore$Proxy.event(ModCore.java:139)
	at cam72cam.mod.ModCore$ClientProxy.event(ModCore.java:152)
	at cam72cam.mod.ModCore.register(ModCore.java:49)
	at net.landofrails.landofsignals.Mod.<clinit>(Mod.java:11)
	... 38 more

This should either be fixed or handled properly.

commented

Tested the following changes:

ContentPackHandler.java
Was before:

try (ZipFile zip = new ZipFile(asset)) {

Tested unsuccessfully:

try (ZipFile zip = new ZipFile(asset, StandardCharset.UTF_8)) {
try (ZipFile zip = new ZipFile(asset, StandardCharset.UTF_16)) {

Tested successfully:

try (ZipFile zip = new ZipFile(asset, StandardCharset.ISO_8859_1)) {
commented

Current solution

The ContentPackHandler tries opening the ContentPack with UTF-8.
If that fails it will retry with ISO_8859_1 with the following messages:

Console:

[19:45:25] [main/INFO]: [cam72cam.mod.ModCore:info:242]: INFO: Loading Asset: D:\IMPORTANT_repositories\LandOfSignals\run\.\config\landofsignals\dk_layout.zip
[19:45:25] [main/INFO]: [cam72cam.mod.ModCore:info:242]: INFO: Encoding: UTF-8
[19:45:25] [main/INFO]: [cam72cam.mod.ModCore:warn:251]: WARN: Failed loading content with UTF-8. Trying ISO_8859_1 next. Try fixing this if possible. See wiki.
[19:45:25] [main/INFO]: [cam72cam.mod.ModCore:info:242]: INFO: Loading Asset: D:\IMPORTANT_repositories\LandOfSignals\run\.\config\landofsignals\dk_layout.zip
[19:45:25] [main/INFO]: [cam72cam.mod.ModCore:info:242]: INFO: Encoding: ISO-8859-1

Item tooltip:
WARNING: This Item/Block was loaded with ISO_8859_1 encoding instead of UTF-8 due to illegal characters. This item/block may not work as intended.

commented

Done