Java compiler lint warnings fixes in test code

Fixes:
[cast] redundant cast
[rawtypes] found raw type
[serial] serializable class has no definition of serialVersionUID

Also suppress warning: auxiliary class TargetLanguageBase in ./inherit_target_language.java should not be accessed from outside its own source file
This commit is contained in:
William S Fulton 2025-03-28 21:43:14 +00:00
parent a16e3cb8ce
commit c2ad64d0a8
20 changed files with 52 additions and 39 deletions

View File

@ -46,7 +46,7 @@ public class runme {
System.out.println( "ucvar =" + example.getUcvar() );
System.out.println( "fvar =" + example.getFvar() );
System.out.println( "dvar =" + example.getDvar() );
System.out.println( "cvar =" + (char)example.getCvar() );
System.out.println( "cvar =" + example.getCvar() );
System.out.println( "strvar =" + example.getStrvar() );
System.out.println( "cstrvar =" + example.getCstrvar() );
System.out.println( "iptrvar =" + Long.toHexString(SWIGTYPE_p_int.getCPtr(example.getIptrvar())) );
@ -62,7 +62,7 @@ public class runme {
System.out.println( " Trying to set 'path'" );
try {
Method m = example.class.getDeclaredMethod("setPath", new Class[] {String.class});
Method m = example.class.getDeclaredMethod("setPath", String.class);
m.invoke(example.class, new Object[] {"Whoa!"} );
System.out.println( "Hey, what's going on?!?! This shouldn't work" );
}
@ -75,7 +75,7 @@ public class runme {
System.out.println( " Trying to set 'status'" );
try {
Method m = example.class.getDeclaredMethod("setStatus", new Class[] {Integer.class});
Method m = example.class.getDeclaredMethod("setStatus", int.class);
m.invoke(example.class, new Object[] {Integer.valueOf(0)} );
System.out.println( "Hey, what's going on?!?! This shouldn't work" );
}

View File

@ -129,7 +129,7 @@ public class CommentParser implements Doclet {
while (it.hasNext()) {
Entry<String, String> e = (Entry<String, String>) it.next();
Entry<String, String> e = it.next();
String actualStr = e.getValue();
String wantedStr = wantedComments.get(e.getKey());
// this may be weird, but I don't know any more effective solution
@ -222,7 +222,7 @@ public class CommentParser implements Doclet {
while (it.hasNext()) {
Entry<String, String> e = (Entry<String, String>) it.next();
Entry<String, String> e = it.next();
String commentText = e.getValue();
commentText = commentText.replace("\\", "\\\\");
commentText = commentText.replace("\"", "\\\"");

View File

@ -82,6 +82,9 @@ SWIGOPT += $(JAVA_PACKAGEOPT)
# Ensure testsuite remains free from SWIG warnings.
SWIGOPT += -Werror
# Suppress -Xlint
inherit_target_language.%: JAVAC_OPTIONS=
# Custom tests - tests with additional commandline options
cpp17_nspace_nested_namespaces.%: JAVA_PACKAGE = $*Package
director_nspace.%: JAVA_PACKAGE = $*Package

View File

@ -12,45 +12,43 @@ public class argcargvtest_runme {
}
public static void main(String argv[]) {
argcargvtest test = new argcargvtest();
String[] largs = {"hi", "hola", "hello"};
if (test.mainc(largs) != 3)
if (argcargvtest.mainc(largs) != 3)
throw new RuntimeException("bad main typemap");
String[] targs = {"hi", "hola"};
if (!test.mainv(targs, 0).equals("hi"))
if (!argcargvtest.mainv(targs, 0).equals("hi"))
throw new RuntimeException("bad main typemap");
if (!test.mainv(targs, 1).equals("hola"))
if (!argcargvtest.mainv(targs, 1).equals("hola"))
throw new RuntimeException("bad main typemap");
if (!test.mainv(targs, 2).equals("<<NULL>>"))
if (!argcargvtest.mainv(targs, 2).equals("<<NULL>>"))
throw new RuntimeException("bad main typemap");
// For dynamically typed languages we test this throws an exception or similar
// at runtime, but for Java this doesn't even compile (but we can't easily
// test for that here).
// test.mainv("hello", 1);
// argcargvtest.mainv("hello", 1);
test.initializeApp(largs);
argcargvtest.initializeApp(largs);
// Check that an empty array works.
String[] empty_args = {};
if (test.mainc(empty_args) != 0)
if (argcargvtest.mainc(empty_args) != 0)
throw new RuntimeException("bad main typemap");
if (!test.mainv(empty_args, 0).equals("<<NULL>>"))
if (!argcargvtest.mainv(empty_args, 0).equals("<<NULL>>"))
throw new RuntimeException("bad main typemap");
// Check that empty strings are handled.
String[] empty_string = {"hello", "", "world"};
if (test.mainc(empty_string) != 3)
if (argcargvtest.mainc(empty_string) != 3)
throw new RuntimeException("bad main typemap");
if (!test.mainv(empty_string, 0).equals("hello"))
if (!argcargvtest.mainv(empty_string, 0).equals("hello"))
throw new RuntimeException("bad main typemap");
if (!test.mainv(empty_string, 1).equals(""))
if (!argcargvtest.mainv(empty_string, 1).equals(""))
throw new RuntimeException("bad main typemap");
if (!test.mainv(empty_string, 2).equals("world"))
if (!argcargvtest.mainv(empty_string, 2).equals("world"))
throw new RuntimeException("bad main typemap");
if (!test.mainv(empty_string, 3).equals("<<NULL>>"))
if (!argcargvtest.mainv(empty_string, 3).equals("<<NULL>>"))
throw new RuntimeException("bad main typemap");
}
}

View File

@ -24,9 +24,9 @@ public class cpp11_constexpr_runme {
check(cpp11_constexpr.DDD(), 40);
ConstExpressions ce = new ConstExpressions(0);
check(ce.JJJ, 100);
check(ce.KKK, 200);
check(ce.LLL, 300);
check(ConstExpressions.JJJ, 100);
check(ConstExpressions.KKK, 200);
check(ConstExpressions.LLL, 300);
check(ce.MMM(), 400);
check(ce.NNN(), 500);
}

View File

@ -156,8 +156,8 @@ public class cpp11_director_using_constructor_runme {
// Introspection to make sure these are actually generated in the derived class
try {
TemplateConstructor1Derived.class.getDeclaredMethod("normal_method", (java.lang.Class[])null);
TemplateConstructor1Derived.class.getDeclaredMethod("template_method", new java.lang.Class[]{String.class, String.class});
TemplateConstructor1Derived.class.getDeclaredMethod("template_method", new java.lang.Class[]{int.class, String.class});
TemplateConstructor1Derived.class.getDeclaredMethod("template_method", String.class, String.class);
TemplateConstructor1Derived.class.getDeclaredMethod("template_method", int.class, String.class);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}

View File

@ -69,7 +69,7 @@ public class cpp11_std_array_runme {
// out of range errors
try {
ai.set((int)ai.size(), 0);
ai.set(ai.size(), 0);
throw new RuntimeException("Out of range exception not caught");
} catch(IndexOutOfBoundsException e) {
}

View File

@ -155,8 +155,8 @@ public class cpp11_using_constructor_runme {
// Introspection to make sure these are actually generated in the derived class
try {
TemplateConstructor1Derived.class.getDeclaredMethod("normal_method", (java.lang.Class[])null);
TemplateConstructor1Derived.class.getDeclaredMethod("template_method", new java.lang.Class[]{String.class, String.class});
TemplateConstructor1Derived.class.getDeclaredMethod("template_method", new java.lang.Class[]{int.class, String.class});
TemplateConstructor1Derived.class.getDeclaredMethod("template_method", String.class, String.class);
TemplateConstructor1Derived.class.getDeclaredMethod("template_method", int.class, String.class);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}

View File

@ -139,7 +139,7 @@ public class director_classes_runme {
}
// Same as Class.getSimpleName() which is not present in all jdks
static String getSimpleName(Class klass) {
static String getSimpleName(Class<?> klass) {
String fullName = klass.getName();
Package packag = klass.getPackage();
String simpleName = null;

View File

@ -28,8 +28,8 @@ public class java_constants_runme {
}
// Check the altered constants interface access modifier
Class[] cls = java_constants.class.getInterfaces();
Class constantsInterface = cls[0];
Class<?>[] cls = java_constants.class.getInterfaces();
Class<?> constantsInterface = cls[0];
int modifiers = constantsInterface.getModifiers();
boolean isDefaultAccessModifier = !(Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers) || Modifier.isPrivate(modifiers));
if (!isDefaultAccessModifier)

View File

@ -18,6 +18,7 @@ class java_director_exception_feature_nspace_Consts {
// an exception not mentioned or wrapped by the swig interface,
// to reconstruct using generic DirectorException handling
@SuppressWarnings("serial")
class java_director_exception_feature_nspace_NewCheckedException extends Exception {
public java_director_exception_feature_nspace_NewCheckedException(String s) {
super(s);
@ -26,6 +27,7 @@ class java_director_exception_feature_nspace_NewCheckedException extends Excepti
// an exception not mentioned or wrapped by the swig interface,
// to reconstruct using generic DirectorException handling
@SuppressWarnings("serial")
class java_director_exception_feature_nspace_NewUncheckedException extends RuntimeException {
public java_director_exception_feature_nspace_NewUncheckedException(String s) {
super(s);
@ -34,6 +36,7 @@ class java_director_exception_feature_nspace_NewUncheckedException extends Runti
// an exception not constructible from a string,
// to test DirectorException fallback reconstruction
@SuppressWarnings("serial")
class java_director_exception_feature_nspace_UnconstructibleException extends Exception {
private int extrastate;
public java_director_exception_feature_nspace_UnconstructibleException(int a, String s) {

View File

@ -19,6 +19,7 @@ class java_director_exception_feature_Consts {
// an exception not mentioned or wrapped by the swig interface,
// to reconstruct using generic DirectorException handling
@SuppressWarnings("serial")
class NewCheckedException extends Exception {
public NewCheckedException(String s) {
super(s);
@ -27,6 +28,7 @@ class NewCheckedException extends Exception {
// an exception not mentioned or wrapped by the swig interface,
// to reconstruct using generic DirectorException handling
@SuppressWarnings("serial")
class NewUncheckedException extends RuntimeException {
public NewUncheckedException(String s) {
super(s);
@ -35,6 +37,7 @@ class NewUncheckedException extends RuntimeException {
// an exception not constructable from a string,
// to test DirectorException fallback reconstruction
@SuppressWarnings("serial")
class UnconstructableException extends Exception {
private int extrastate;
public UnconstructableException(int a, String s) {

View File

@ -609,7 +609,7 @@ public class li_boost_shared_ptr_runme {
throw new RuntimeException("verify value failed. Expected: " + expected + " Got: " + got);
}
private void verifyCount(int expected, Klass k) {
int got = (int)li_boost_shared_ptr.use_count(k);
int got = li_boost_shared_ptr.use_count(k);
if (expected != got)
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
}

View File

@ -97,7 +97,7 @@ public class long_long_runme {
boolean failed = false;
for (int i=0; i<bigIntegers.size(); ++i) {
BigInteger bi = (BigInteger)bigIntegers.get(i);
BigInteger bi = bigIntegers.get(i);
long longReturn = long_long.UnsignedToSigned(bi);
if (bi.longValue() != longReturn) {
System.err.println("Conversion to long failed, in:" + bi + " out:" + longReturn);

View File

@ -12,11 +12,11 @@ public class multiple_inheritance_interfaces_runme {
}
}
private static void checkBaseAndInterfaces(Class cls, boolean interfaceExpected, String base, String[] interfaces) {
private static void checkBaseAndInterfaces(Class<?> cls, boolean interfaceExpected, String base, String[] interfaces) {
String[] expectedInterfaces = new String[interfaces.length];
for (int i=0; i<interfaces.length; ++i)
expectedInterfaces[i] = "interface multiple_inheritance_interfaces." + interfaces[i];
Class[] actualInterfaces = cls.getInterfaces();
Class<?>[] actualInterfaces = cls.getInterfaces();
String expectedInterfacesString = Arrays.toString(expectedInterfaces);
String actualInterfacesString = Arrays.toString(actualInterfaces);
if (!expectedInterfacesString.equals(actualInterfacesString))

View File

@ -16,7 +16,7 @@ public class nested_inheritance_interface_runme {
}
public static void main(String argv[]) {
Class[] BNInterfaces = B.N.class.getInterfaces();
Class<?>[] BNInterfaces = B.N.class.getInterfaces();
String expectedInterfacesString = "[interface nested_inheritance_interface.IASwigInterface]";
String actualInterfacesString = Arrays.toString(BNInterfaces);
if (!expectedInterfacesString.equals(actualInterfacesString))

View File

@ -134,6 +134,9 @@
%feature("director") Foo;
%typemap(javaclassmodifiers) MyNS::Exception1, MyNS::Exception2, MyNS::Unexpected %{@SuppressWarnings("serial")
public class%}
// Rename exceptions on java side to make translation of exceptions more clear
%rename(MyJavaException1) MyNS::Exception1;
%rename(MyJavaException2) MyNS::Exception2;

View File

@ -141,6 +141,9 @@
%feature("director") Foo;
%typemap(javaclassmodifiers) MyNS::Exception1, MyNS::Exception2, MyNS::Unexpected %{@SuppressWarnings("serial")
public class%}
// Rename exceptions on java side to make translation of exceptions more clear
%rename(MyJavaException1) MyNS::Exception1;
%rename(MyJavaException2) MyNS::Exception2;

View File

@ -68,7 +68,7 @@ public:
$result = bar::Ptr< bar::Baz >(*( bar::Baz**)&$input);
}
%typemap(javadirectorin) bar::Ptr< bar::Baz > %{
((long)$jniinput == 0) ? null : new $typemap(jstype, bar::Baz)($jniinput, false)
($jniinput == 0) ? null : new $typemap(jstype, bar::Baz)($jniinput, false)
%}
%typemap(javadirectorout) bar::Ptr< bar::Baz > "$typemap(jstype, bar::Baz).getCPtr($javacall)"

View File

@ -5,7 +5,7 @@
%include "std_vector.i"
%define VECTOR_DOUBLE_JAVAIN_POST
" int count$javainput = (int)d$javainput.size();
" int count$javainput = d$javainput.size();
$javainput = new double[count$javainput];
for (int i=0; i<count$javainput; ++i) {
$javainput[i] = d$javainput.get(i);
@ -27,7 +27,7 @@
"$javaclassname.getCPtr(d$javainput)"
// post only in javain typemap
%typemap(javain, post=" int size = (int)$javainput.size();\n for (int i=0; i<size; ++i) {\n $javainput.set(i, $javainput.get(i)/100);\n }") std::vector<double> &vpost
%typemap(javain, post=" int size = $javainput.size();\n for (int i=0; i<size; ++i) {\n $javainput.set(i, $javainput.get(i)/100);\n }") std::vector<double> &vpost
"$javaclassname.getCPtr($javainput)"
%inline %{