avoid unchecked casts due by premature casting of Class objects

master
Stephen Gold 5 years ago
parent 297443ada4
commit 88c9371a4d
  1. 5
      jme3-android/src/main/java/com/jme3/app/AndroidHarness.java
  2. 5
      jme3-android/src/main/java/com/jme3/app/AndroidHarnessFragment.java
  3. 4
      jme3-desktop/src/main/java/com/jme3/app/AppletHarness.java
  4. 15
      jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java
  5. 4
      jme3-examples/src/main/java/jme3test/awt/AppHarness.java
  6. 4
      jme3-examples/src/main/java/jme3test/awt/TestApplet.java
  7. 4
      jme3-examples/src/main/java/jme3test/awt/TestCanvas.java

@ -239,9 +239,8 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
// Create application instance
try {
if (app == null) {
@SuppressWarnings("unchecked")
Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
app = clazz.newInstance();
Class clazz = Class.forName(appClass);
app = (LegacyApplication)clazz.newInstance();
}
app.setSettings(settings);

@ -257,9 +257,8 @@ public class AndroidHarnessFragment extends Fragment implements
// Create application instance
try {
if (app == null) {
@SuppressWarnings("unchecked")
Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
app = clazz.newInstance();
Class clazz = Class.forName(appClass);
app = (LegacyApplication)clazz.newInstance();
}
app.setSettings(settings);

@ -103,8 +103,8 @@ public class AppletHarness extends Applet {
JmeSystem.setLowPermissions(true);
try{
Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
app = clazz.newInstance();
Class clazz = Class.forName(appClass);
app = (LegacyApplication) clazz.newInstance();
}catch (ClassNotFoundException ex){
ex.printStackTrace();
}catch (InstantiationException ex){

@ -193,22 +193,22 @@ public class JmeDesktopSystem extends JmeSystemDelegate {
private JmeContext newContextLwjgl(AppSettings settings, JmeContext.Type type) {
try {
Class<? extends JmeContext> ctxClazz = null;
Class ctxClazz = null;
switch (type) {
case Canvas:
ctxClazz = (Class<? extends JmeContext>) Class.forName("com.jme3.system.lwjgl.LwjglCanvas");
ctxClazz = Class.forName("com.jme3.system.lwjgl.LwjglCanvas");
break;
case Display:
ctxClazz = (Class<? extends JmeContext>) Class.forName("com.jme3.system.lwjgl.LwjglDisplay");
ctxClazz = Class.forName("com.jme3.system.lwjgl.LwjglDisplay");
break;
case OffscreenSurface:
ctxClazz = (Class<? extends JmeContext>) Class.forName("com.jme3.system.lwjgl.LwjglOffscreenBuffer");
ctxClazz = Class.forName("com.jme3.system.lwjgl.LwjglOffscreenBuffer");
break;
default:
throw new IllegalArgumentException("Unsupported context type " + type);
}
return ctxClazz.newInstance();
return (JmeContext) ctxClazz.newInstance();
} catch (InstantiationException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex);
} catch (IllegalAccessException ex) {
@ -225,9 +225,8 @@ public class JmeDesktopSystem extends JmeSystemDelegate {
try {
String className = settings.getRenderer().substring("CUSTOM".length());
Class<? extends JmeContext> ctxClazz = null;
ctxClazz = (Class<? extends JmeContext>) Class.forName(className);
return ctxClazz.newInstance();
Class ctxClazz = Class.forName(className);
return (JmeContext) ctxClazz.newInstance();
} catch (InstantiationException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex);
} catch (IllegalAccessException ex) {

@ -79,8 +79,8 @@ public class AppHarness extends Applet {
JmeSystem.setLowPermissions(true);
try{
Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
app = clazz.newInstance();
Class clazz = Class.forName(appClass);
app = (LegacyApplication) clazz.newInstance();
}catch (ClassNotFoundException ex){
ex.printStackTrace();
}catch (InstantiationException ex){

@ -62,8 +62,8 @@ public class TestApplet extends Applet {
JmeSystem.setLowPermissions(true);
try{
Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
app = clazz.newInstance();
Class clazz = Class.forName(appClass);
app = (LegacyApplication) clazz.newInstance();
}catch (ClassNotFoundException ex){
ex.printStackTrace();
}catch (InstantiationException ex){

@ -209,8 +209,8 @@ public class TestCanvas {
settings.setHeight(480);
try{
Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
app = clazz.newInstance();
Class clazz = Class.forName(appClass);
app = (LegacyApplication)clazz.newInstance();
}catch (ClassNotFoundException ex){
ex.printStackTrace();
}catch (InstantiationException ex){

Loading…
Cancel
Save