'Keytool - java.lang.ExceptionInInitializerError

I have installed IBM Java 8 and I am getting below exception when trying to run keytool command. Its even happening when just executing ./keytool.

Exception in thread "main" java.lang.ExceptionInInitializerError
        at java.lang.J9VMInternals.ensureError(J9VMInternals.java:147)
        at java.lang.J9VMInternals.recordInitializationFailure(J9VMInternals.java:136)
Caused by: java.lang.NullPointerException
        at com.ibm.oti.vm.AbstractClassLoader.findResourceImpl(AbstractClassLoader.java:210)
        at com.ibm.oti.vm.AbstractClassLoader.access$100(AbstractClassLoader.java:41)
        at com.ibm.oti.vm.AbstractClassLoader$2.run(AbstractClassLoader.java:250)
        at java.security.AccessController.doPrivileged(AccessController.java:678)
        at com.ibm.oti.vm.AbstractClassLoader.findResources(AbstractClassLoader.java:246)
        at java.lang.ClassLoader.getResources(ClassLoader.java:683)
        at java.lang.ClassLoader.getResources(ClassLoader.java:680)
        at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:359)
        at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:404)
        at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:485)
        at sun.util.locale.provider.SPILocaleProviderAdapter$1.run(SPILocaleProviderAdapter.java:92)
        at sun.util.locale.provider.SPILocaleProviderAdapter$1.run(SPILocaleProviderAdapter.java:86)
        at java.security.AccessController.doPrivileged(AccessController.java:734)
        at sun.util.locale.provider.SPILocaleProviderAdapter.findInstalledProvider(SPILocaleProviderAdapter.java:86)
        at sun.util.locale.provider.AuxLocaleProviderAdapter.getLocaleServiceProvider(AuxLocaleProviderAdapter.java:82)
        at sun.util.locale.provider.LocaleProviderAdapter.findAdapter(LocaleProviderAdapter.java:296)
        at sun.util.locale.provider.LocaleProviderAdapter.getAdapter(LocaleProviderAdapter.java:266)
        at java.text.Collator.getInstance(Collator.java:274)
        at java.text.Collator.getInstance(Collator.java:238)
        at com.ibm.crypto.tools.KeyTool.<clinit>(Unknown Source)


Solution 1:[1]

I write a demo to convert byte[] image to file and save.

Manage Nuget Packages: System.Drawing.Common ;

public IActionResult Index(byte[] fileBytes)
        {
            
            //Convert byte type pictures into files to save
            var im = new System.IO.MemoryStream(fileBytes);
            var img = Image.FromStream(im);

            //save the file
            img.Save(@"C:\Users\CS\Documents\FedexLabel.png");
    

            //......

        }

Solution 2:[2]

I still use this code

byte[] image2 = response.Shipments[0].ShippingLabel.ToArray();
MemoryStream memoryStream = new MemoryStream(image2);

BinaryReader rd = new BinaryReader(memoryStream);

string filename = "C:/Users/CS/Documents/FedexLabel.png";

byte[] buffer = new byte[1024];
FileStream outFile = new FileStream(filename, FileMode.Create);

int bytesRead;

while ((bytesRead = memoryStream.Read(buffer, 0, buffer.Length)) != 0)
    outFile.Write(buffer, 0, bytesRead);

outFile.Close();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Ramil Aliyev