Categories
Java

Java + LetsEncrypt certificate giving SunCertPathBuilderException

During testing some java code i have for doing a check against check.torproject.org i got an exception is have not seen before:

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

After digging around i realised that the site in question has started using certificates from Lets Encrypt.

Java keeps their known certificate providers bundled with the installation, so if your JRE/JDK installation is not quite up to date, it will be as simple as to simply upgrade to the latest release. (Anything >= Oracle Java 8u101 has Lets Encrypt root cert bundled)

Categories
Development Java

Java: How to get access to ClassLoader from static function

If you need access to the ClassLoader from a static function, for example in order to access a file inside your jar. You can get hold of it simply bu calling “YourClassname.class.getClassLoader()” 🙂

Categories
Development Java

GWT: Getting rid of iframe borders in IE8

IE8 defaults to displaying a frame border on iframes, this can be overridden by using the IFrameElement class.

Example:

IFrameElement.as(yourFrameClass.getElement()).setFrameBorder(0);
Categories
Development Java

java.io.file renameTo return false

Had a issue today where a java function which moves files stopped working. I realised that Java`s io.file.renameTo only throws Exceptions for some scenarios. For some errors, it will only return false when something goes wrong.

Only getting true/false on a rather vital operation is rather silly, so my “fix” was to move over to a library from Apache, aka FileUtils.

So now i simply do this: FileUtils.moveFile(oldFile, newFile);

That function actually throws exceptions when something fails 🙂

Categories
Development Java

GWT: “For security purposes, this type will not be serialized.”

The full error message you can get is: “Foo was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.”

This is normally caused by using a non-serializable class, which can happen if your class does not implement serializable or if you have forgotten to add a empty constructor.