Category: Java/C++ Runtime


My proxy classes were generated for a Java version other than the one I want to run with. Will that work?


The version of Java that was used to generate the C++ proxy classes is mostly irrelevant at runtime. Clearly, if you generated a C++ proxy type for a (new to) Java5 type and you deploy and run your C++ process with a JRE 1.4, you cannot expect to use the proxy type for the Java5 class successfully. While you have a beautiful C++ type you can call, there will be no corresponding Java type at runtime and any use of the C++ type will cause a ClassNotFoundException to be thrown.

The same issue can be harder to diagnose when the type in question already existed in the older version of Java but underwent changes, for example methods or fields were added or the inheritance hierarchy was changed.

The relatively simple compatibility rules are:

  1. Try to generate against the same version of the JRE that you're planning to run with.
    You will never have any JRE version problems that way.
  2. If you cannot ensure that, generate against the oldest version of the JRE that you have to support.
    You might not have access to all the latest JRE types, but typically you don't need that anyway; the JRE types only play a supportive role to your integration effort.
  3. If you cannot do even that and you have a proxy API that includes functionality from a later JRE, you can safely use all version compatible features.
    The only things that will cause you grief are the features that are changed or not present. In this case, you will have an Exception or an Error thrown.

There is one complication to these simple rules, and it involves callbacks. Callbacks require the code generator to not just generate a C++ proxy type but also a Java type. That Java type is "injected" into the running JRE when it is first needed. If that Java type was compiled using a Java5 compiler, it would not work with a pre-Java5 JRE because its embedded classfile version number would make it incompatible with earlier JREs.

With callbacks, it becomes imperative to either use the proper Java compiler for callbacks or to specify a target version number for the generated bytecode.

Copyright 2006-2011 by Codemesh, Inc., ALL RIGHTS RESERVED

frequently asked questions
home products support customers partners newsroom about us contact us