Problem:
- Product Name: VisiBroker for Java
- Product Version: 7.0, 8.0
- Product Component: vbjc compiler
- Platform/OS version: All
- JDK: Java 5 & later
The following warning messages are encountered when compiling the "Bank Agent" example in JDK 5 & later.
The "Bank Agent" example can be found in the directory: "/examples/vbroker/basic/bank_agent".
>vbmake Building the basic/bank_agent example ... Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
To find out more about the warning messages, edit the vbmake file to add in the option "-Xlint:unchecked" to the vbjc command.
Example:
vbjc -Xlint:unchecked Client.java
vbjc -Xlint:unchecked Server.java
Next, run "vbmake clean", followed by "vbmake".
>vbmake
Building the basic/bank_agent example ...
.\\Bank\\AccountManagerPOA.java:38: warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Dictionary
_methods.put("open", new int[] { 0, 0 });
^
.\\AccountManagerImpl.java:25: warning: [unchecked] unchecked call to put(K,V) as
a member of the raw type java.util.Dictionary
_accounts.put(name, account);
^
.\\Bank\\AccountPOA.java:38: warning: [unchecked] unchecked call to put(K,V) as amember of the raw type java.util.Dictionary
_methods.put("balance", new int[] { 0, 0 });
^
3 warnings
Resolution:
Sun Microsystems introduce Generic classes in Java 5 & later.
The "unchecked or unsafe operations" warning is due to a missing type declaration.
For example:
ArrayList mylist = new ArrayList();
The above statement will generate a warning, there is no type declaration for ArrayList.
If the following is used, this statement will not generate a warning.
ArrayList<String> mylist = new ArrayList<String>();
The AccountManagerPOA.java (as well as the other POA java classes) which is generated by idl2java (a VisiBroker tool), will contain the declaration:
private static java.util.Dictionary _methods = new java.util.Hashtable();
Since there is no type declaration for java.util.Dictionary, this statement will generate a warning from the compiler.
The following provides a workaround,
1. Generating the xxxPOA files using "idl2java Bank.idl".
2. Edit the xxxPOA java files to add in the @SuppressWarnings("unchecked") string. The code provides a hint to the compiler to suppress the unchecked warnings.
Example: AccountManagerPOA.java
@SuppressWarnings("unchecked")
public abstract class AccountManagerPOA extends org.omg.PortableServer.Servant implements
org.omg.CORBA.portable.InvokeHandler, Bank.AccountManagerOperations {
...
}
#VisiBroker
#Security