JNBridgePro and Java 8

Java 8 has a couple of new features (particularly, static and default methods in interfaces) that create problems for our current JNBridgePro 7.1. We will be coming out shortly with a new version that supports Java 8 along with previous versions of Java, but if you’re currently using JNBridgePro 7.1 and are having problems with Java 8, contact us and we’ll send you a patch.

JNBridgePro v7.2, adapters v3.2 released

Today we’ve announced the release of JNBridgePro version 7.2, which supports Java 8 (in addition to still supporting Java 5, 6, and 7). JNBridgePro v7.2 adds support for, among other new Java 8 features, static and default methods in interfaces. In addition, v7.2 includes substantial performance improvements in .NET applications that create very large numbers (in the millions, for example) of instances of a single Java class.

In addition, we’ve announced new version 3.2 releases of our JMS adapters for BizTalk Server and .NET. In addition to using the new JNBridgePro 7.2 components, the new adapters contain enhanced diagnostics to help track down configuration and performance issues.

For more information, please see the announcement. The new releases can be downloaded here.

New Java 8 features in JNBridgePro 7.2

Usually, when new versions of Java are released, we at JNBridge don’t have much to do.  The features generally don’t have an impact on what JNBridgePro does, and things just work.  Sometimes, as with variable-length argument lists (introduced in Java 5), they are simply syntactic sugar and are automatically proxied into their underlying form (an array).  Other times, new features occur behind the scenes (for example, lambda expressions in Java 8) and are never exposed to .NET users through proxies, so JNBridgePro doesn’t need to worry about them.

Java 8, however, contains two new features, static interface methods and default interface methods, that do affect JNBridgePro functionality. Both features are designed to improve usability of the language (whether or not they do is debatable, but that’s a topic for another blog post).  Static methods in interfaces are designed to add additional functionality to an interface, in the same way that static field constants have existed in Java interfaces in the past.  Default interface methods are intended to spare users from having to incorporate common implementations of certain interface methods; only unusual implementations need to be supplied.  Both static and default interface methods cause interfaces to act like abstract classes, with greater flexibility.

For JNBridgePro, the problem is that interfaces in most .NET languages (including C#) do not have these features, and attempting to map these features directly during proxy generation will cause exceptions to be thrown, or will cause DLLs to fail verification at run time.  In order to make these new Java 8 features available to .NET developers, we had to make some changes in the way that these new members of Java interfaces are mapped to their .NET proxies.

It was easy to determine how to map static interface methods. We’ve already had to deal with the problem with mapping static interface constants to proxied .NET interfaces, because most .NET languages don’t allow these, either.  For each proxied Java interface, we automatically create an associated helper class (called IConstants, when the original interface is I), which contains the static constants. Starting with JNBridgePro 7.2, static interface methods are also proxied into those same helper classes.

Handling default interface classes is a bit more involved. Not only are C# interfaces not permitted to include actual method implementations, “default” or not, but any C# class implementing an interface must account for every method in the interface, even if a Java class implementing the underlying interface doesn’t need to account for default interface methods.  This means that when we proxy a Java class that implements an interface with default methods, and that uses the default method, the proxied class will fail .NET verification because it doesn’t account for all methods in the implemented interface. To remedy this, starting with JNBridgePro 7.2 if a Java class relies on a default interface method and doesn’t actually provide an implementation of its own, then the .NET proxy will include an implementation of the method, which when called will result in a call to the default method. This should be transparent to the user.

Exception: “You need to install the Visual C++ runtime library”

In Java-to-.NET projects, you get the following exception message:

Couldn’t start up .NET side. Please verify that the files jnbshare.dll, jnbsharedmem.dll, and jnbjavaentry2.dll are in the GAC or are in the folder pointed to by the dotNetSide.appBase property. If that is the case, then you need to install the Visual C/C++ 9.0, 10.0, or 11.0 runtime library. In order to use shared memory communications, this JNBridge product requires that the Visual C/C++ 9.0, 10.0, or 11.0 runtime be installed. You can download a copy from https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

The shared memory communications mechanism references the Visual C++ runtime library, and the C++ runtime library of the appropriate version and bitness must be installed on the machine. In most cases, this library is already installed by some other product — often a Microsoft product. If the machine is relatively new and clean, the library will be missing, and you will see this error.

You can download the appropriate Visual C++ runtime library from Microsoft here.

If your application targets .NET Framework 2.0, 3.0, or 3.5, download and install version 9.0 of the Visual C++ (VC++) runtime library, associated with Visual Studio 2008. If your application targets .NET Framework 4.0, 4.5, 4.6, or 4.7, download and install version 10.0 of the VC++ runtime library, associated with Visual Studio 2010. In some cases, this is not sufficient to resolve the problem, and you should install version 11.0 of the VC++ runtime library, associated with Visual Studio 2012. In all cases, download the library of the appropriate bitness: if your application runs in a 32-bit process, download the 32-bit (x86) version; if your application runs in a 64-bit process, download the 64-bit (x64) version. In all cases, you can download the library from the link given above.