From ebb1ec249d51a835363c24a84f81d5dbb81d2d18 Mon Sep 17 00:00:00 2001 From: Karthik D Date: Sun, 13 Oct 2024 23:53:25 -0400 Subject: [PATCH 01/43] Refactoring the Variable Name to Standard Naming Practices - Issue #1 --- .../com/jme3/system/JmeDesktopSystem.java | 2 +- .../java/com/jme3/system/NativeLibraries.java | 20 +++++++++---------- .../java/jme3test/audio/TestMusicPlayer.java | 4 ++-- .../com/jme3/system/lwjgl/LwjglContext.java | 8 ++++---- .../com/jme3/system/lwjgl/LwjglContextVR.java | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java b/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java index 81c197a3c..cee6570e4 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java +++ b/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java @@ -287,7 +287,7 @@ public void initialize(AppSettings settings) { logger.log(Level.INFO, getBuildInfo()); if (!lowPermissions) { if (NativeLibraryLoader.isUsingNativeBullet()) { - NativeLibraryLoader.loadNativeLibrary(NativeLibraries.BulletJme.getName(), true); + NativeLibraryLoader.loadNativeLibrary(NativeLibraries.BULLET_JME.getName(), true); } } } diff --git a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraries.java b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraries.java index b64a2fa84..c2a4c0ff1 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraries.java +++ b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraries.java @@ -50,7 +50,7 @@ public enum NativeLibraries { /** * Native lwjgl libraries for LWJGL 2 required by jme3-lwjgl backend. */ - Lwjgl(new LibraryInfo("lwjgl", libPath -> + LWJGL(new LibraryInfo("lwjgl", libPath -> // Delegate loading to lwjgl. System.setProperty("org.lwjgl.librarypath", Paths.get(libPath).getParent().toAbsolutePath().toString())) @@ -67,7 +67,7 @@ public enum NativeLibraries { /** * Native OpenAL audio libraries for LWJGL 2 required by jme3-lwjgl backend. */ - OpenAL(new LibraryInfo("openal") + OPEN_AL(new LibraryInfo("openal") .addNativeVariant(Platform.Windows32, "OpenAL32.dll") .addNativeVariant(Platform.Windows64, "OpenAL64.dll") .addNativeVariant(Platform.Linux32, "libopenal.so") @@ -79,7 +79,7 @@ public enum NativeLibraries { /** * Native bullet physics libraries required by Minie library. */ - BulletJme(new LibraryInfo("bulletjme") + BULLET_JME(new LibraryInfo("bulletjme") .addNativeVariant(Platform.Windows32, "native/windows/x86/bulletjme.dll", "bulletjme-x86.dll") .addNativeVariant(Platform.Windows64, "native/windows/x86_64/bulletjme.dll", "bulletjme-x86_64.dll") .addNativeVariant(Platform.Windows_ARM64, "native/windows/arm64/bulletjme.dll", "bulletjme-arm64.dll") @@ -96,7 +96,7 @@ public enum NativeLibraries { /** * Native JInput joystick libraries required by jme3-lwjgl backend. */ - JInput(new LibraryInfo("jinput", libPath -> + J_INPUT(new LibraryInfo("jinput", libPath -> // Delegate loading to jinput. System.setProperty("net.java.games.input.librarypath", Paths.get(libPath).getParent().toAbsolutePath().toString())) @@ -112,7 +112,7 @@ public enum NativeLibraries { * Native JInput DirectX 8 auxiliary libraries required by jme3-lwjgl backend. * (only required on Windows) */ - JInputDX8(new LibraryInfo("jinput-dx8") + J_INPUT_DX_8(new LibraryInfo("jinput-dx8") .addNativeVariant(Platform.Windows32, "jinput-dx8.dll", null) .addNativeVariant(Platform.Windows64, "jinput-dx8_64.dll", null) .addNativeVariant(Platform.Linux32, null) @@ -133,11 +133,11 @@ public enum NativeLibraries { * later on via {@link NativeLibraryLoader#loadNativeLibrary(String, boolean)}. */ public static void registerDefaultLibraries() { - Lwjgl.registerLibrary(); - OpenAL.registerLibrary(); - BulletJme.registerLibrary(); - JInput.registerLibrary(); - JInputDX8.registerLibrary(); + LWJGL.registerLibrary(); + OPEN_AL.registerLibrary(); + BULLET_JME.registerLibrary(); + J_INPUT.registerLibrary(); + J_INPUT_DX_8.registerLibrary(); } public LibraryInfo getLibrary() { diff --git a/jme3-examples/src/main/java/jme3test/audio/TestMusicPlayer.java b/jme3-examples/src/main/java/jme3test/audio/TestMusicPlayer.java index da6b4e9a2..dfd8c8f40 100644 --- a/jme3-examples/src/main/java/jme3test/audio/TestMusicPlayer.java +++ b/jme3-examples/src/main/java/jme3test/audio/TestMusicPlayer.java @@ -62,8 +62,8 @@ public class TestMusicPlayer extends javax.swing.JFrame { // started, but in this test we do not create a LwjglContext, // so we should handle loading natives ourselves if running // with lwjgl 2. - NativeLibraryLoader.loadNativeLibrary(NativeLibraries.Lwjgl.getName(), false); - NativeLibraryLoader.loadNativeLibrary(NativeLibraries.OpenAL.getName(), false); + NativeLibraryLoader.loadNativeLibrary(NativeLibraries.LWJGL.getName(), false); + NativeLibraryLoader.loadNativeLibrary(NativeLibraries.OPEN_AL.getName(), false); } public TestMusicPlayer() { diff --git a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java index b436806dc..8e884e81c 100644 --- a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java +++ b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java @@ -236,13 +236,13 @@ protected void loadNatives() { return; } if (AppSettings.LWJGL_OPENAL.equals(settings.getAudioRenderer())) { - NativeLibraryLoader.loadNativeLibrary(NativeLibraries.OpenAL.getName(), true); + NativeLibraryLoader.loadNativeLibrary(NativeLibraries.OPEN_AL.getName(), true); } if (settings.useJoysticks()) { - NativeLibraryLoader.loadNativeLibrary(NativeLibraries.JInput.getName(), true); - NativeLibraryLoader.loadNativeLibrary(NativeLibraries.JInputDX8.getName(), true); + NativeLibraryLoader.loadNativeLibrary(NativeLibraries.J_INPUT.getName(), true); + NativeLibraryLoader.loadNativeLibrary(NativeLibraries.J_INPUT_DX_8.getName(), true); } - NativeLibraryLoader.loadNativeLibrary(NativeLibraries.Lwjgl.getName(), true); + NativeLibraryLoader.loadNativeLibrary(NativeLibraries.LWJGL.getName(), true); } protected int getNumSamplesToUse() { int samples = 0; diff --git a/jme3-vr/src/main/java/com/jme3/system/lwjgl/LwjglContextVR.java b/jme3-vr/src/main/java/com/jme3/system/lwjgl/LwjglContextVR.java index 0ec3f7498..0100bd032 100644 --- a/jme3-vr/src/main/java/com/jme3/system/lwjgl/LwjglContextVR.java +++ b/jme3-vr/src/main/java/com/jme3/system/lwjgl/LwjglContextVR.java @@ -120,7 +120,7 @@ protected void loadNatives() { } if (NativeLibraryLoader.isUsingNativeBullet()) { - NativeLibraryLoader.loadNativeLibrary(NativeLibraries.BulletJme.getName(), true); + NativeLibraryLoader.loadNativeLibrary(NativeLibraries.BULLET_JME.getName(), true); } } From a96510741360a78b53a74888fbdf0ef4d703e617 Mon Sep 17 00:00:00 2001 From: apurba-das Date: Mon, 14 Oct 2024 19:19:22 -0400 Subject: [PATCH 02/43] Resolved code smell by defining a constant instead of duplicating the literal Color 4 times --- .../main/java/jme3test/android/TestAndroidSensors.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java b/jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java index b38bba76c..953b4765e 100644 --- a/jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java +++ b/jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java @@ -88,6 +88,7 @@ public void simpleInitApp() { // useAbsolute = true; // enableRumble = true; + private static final String COLOR = "Color"; if (enableFlyByCameraRotation) { flyCam.setEnabled(true); @@ -101,21 +102,21 @@ public void simpleInitApp() { Geometry geoX = new Geometry("X", lineX); Material matX = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - matX.setColor("Color", ColorRGBA.Red); + matX.setColor(COLOR, ColorRGBA.Red); matX.getAdditionalRenderState().setLineWidth(30); geoX.setMaterial(matX); rootNode.attachChild(geoX); Geometry geoY = new Geometry("Y", lineY); Material matY = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - matY.setColor("Color", ColorRGBA.Green); + matY.setColor(COLOR, ColorRGBA.Green); matY.getAdditionalRenderState().setLineWidth(30); geoY.setMaterial(matY); rootNode.attachChild(geoY); Geometry geoZ = new Geometry("Z", lineZ); Material matZ = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - matZ.setColor("Color", ColorRGBA.Blue); + matZ.setColor(COLOR, ColorRGBA.Blue); matZ.getAdditionalRenderState().setLineWidth(30); geoZ.setMaterial(matZ); rootNode.attachChild(geoZ); @@ -123,7 +124,7 @@ public void simpleInitApp() { Box b = new Box(1, 1, 1); geomZero = new Geometry("Box", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - mat.setColor("Color", ColorRGBA.Yellow); + mat.setColor(COLOR, ColorRGBA.Yellow); Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg"); mat.setTexture("ColorMap", tex_ml); geomZero.setMaterial(mat); From b70f67bb130e39b9fb91436a109d60a25128d21a Mon Sep 17 00:00:00 2001 From: apurba-das Date: Mon, 14 Oct 2024 19:27:36 -0400 Subject: [PATCH 03/43] Resolved code smell by defining a constant instead of duplicating this literal MouseClick 3 times --- .../main/java/jme3test/android/TestAndroidSensors.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java b/jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java index 953b4765e..a1da1b68a 100644 --- a/jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java +++ b/jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java @@ -77,6 +77,8 @@ public class TestAndroidSensors extends SimpleApplication implements ActionListe // toggle to enable controlling geometry rotation boolean enableGeometryRotation = true; + private static final String MOUSECLICK = "MouseClick"; + // Make sure to set joystickEventsEnabled = true in MainActivity for Android private float toDegrees(float rad) { @@ -135,8 +137,8 @@ public void simpleInitApp() { // Touch (aka MouseInput.BUTTON_LEFT) is used to record the starting // orientation when using absolute rotations - inputManager.addMapping("MouseClick", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); - inputManager.addListener(this, "MouseClick"); + inputManager.addMapping(MOUSECLICK, new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); + inputManager.addListener(this, MOUSECLICK); Joystick[] joysticks = inputManager.getJoysticks(); if (joysticks == null || joysticks.length < 1) { @@ -231,7 +233,7 @@ public void simpleUpdate(float tpf) { @Override public void onAction(String string, boolean pressed, float tpf) { - if (string.equalsIgnoreCase("MouseClick") && pressed) { + if (string.equalsIgnoreCase(MOUSECLICK) && pressed) { // Calibrate the axis (set new zero position) if the axis // is a sensor joystick axis for (IntMap.Entry entry : joystickMap) { From ff15f1869c14ee27d1aca1ad8599a759187de4ca Mon Sep 17 00:00:00 2001 From: mohsin-681 Date: Tue, 15 Oct 2024 04:06:36 -0400 Subject: [PATCH 04/43] Removed unnecessary import --- .../src/main/java/com/jme3/app/state/AWTComponentAppState.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java index db42f9050..c4a5589ca 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java @@ -34,8 +34,6 @@ import java.awt.Component; import com.jme3.app.Application; -import com.jme3.app.state.AbstractAppState; -import com.jme3.app.state.AppStateManager; import com.jme3.system.AWTFrameProcessor; import com.jme3.system.AWTTaskExecutor; From c27ae8fa318cfd832a00d5fcd600d221c54cbc0d Mon Sep 17 00:00:00 2001 From: mohsin-681 Date: Tue, 15 Oct 2024 04:37:07 -0400 Subject: [PATCH 05/43] Unnecessary Import Fixed --- .../src/main/java/com/jme3/app/state/AWTComponentAppState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java index c4a5589ca..c50e1d6c7 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java @@ -4,7 +4,7 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are - * met: + * met * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. From 2058125a14eae5d01ac699cdbb64423851230baf Mon Sep 17 00:00:00 2001 From: mohsin-681 Date: Tue, 15 Oct 2024 04:46:27 -0400 Subject: [PATCH 06/43] Unnecessary import removed. --- .../main/java/com/jme3/app/state/AWTComponentAppState.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java index c50e1d6c7..8008d0094 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java @@ -4,7 +4,7 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are - * met + * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. @@ -38,7 +38,7 @@ import com.jme3.system.AWTTaskExecutor; /** - * An app state dedicated to the rendering of a JMonkey application within an AWT component. + * An to the rendering of a JMonkey application within an AWT component. * @author Julien Seinturier - COMEX SA - http://www.seinturier.fr */ public class AWTComponentAppState extends AbstractAppState { From 3bfd6b3206dd78d2e5226a3f24d032453d54c063 Mon Sep 17 00:00:00 2001 From: mohsin-681 Date: Tue, 15 Oct 2024 04:51:21 -0400 Subject: [PATCH 07/43] Removed unnecessary import #5 --- .../src/main/java/com/jme3/app/state/AWTComponentAppState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java index 8008d0094..fe1ec7404 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java @@ -38,7 +38,7 @@ import com.jme3.system.AWTTaskExecutor; /** - * An to the rendering of a JMonkey application within an AWT component. + * An to the of a JMonkey application within an AWT component. * @author Julien Seinturier - COMEX SA - http://www.seinturier.fr */ public class AWTComponentAppState extends AbstractAppState { From 18a53d26a9ab8ec7d35c3b182c1053ab98ae5995 Mon Sep 17 00:00:00 2001 From: mohsin-681 Date: Tue, 15 Oct 2024 04:57:07 -0400 Subject: [PATCH 08/43] Issue fixed --- .../src/main/java/com/jme3/app/state/AWTComponentAppState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java index fe1ec7404..37c37d2d3 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java @@ -38,7 +38,7 @@ import com.jme3.system.AWTTaskExecutor; /** - * An to the of a JMonkey application within an AWT component. + * An to the o a JMonkey application within an AWT component. * @author Julien Seinturier - COMEX SA - http://www.seinturier.fr */ public class AWTComponentAppState extends AbstractAppState { From b76306ae8957059936f53db69d24d4039b803c79 Mon Sep 17 00:00:00 2001 From: mohsin-681 Date: Tue, 15 Oct 2024 05:02:50 -0400 Subject: [PATCH 09/43] Removed unnecessary import --- .../src/main/java/com/jme3/app/state/AWTComponentAppState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java index 37c37d2d3..12e7045b2 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java @@ -38,7 +38,7 @@ import com.jme3.system.AWTTaskExecutor; /** - * An to the o a JMonkey application within an AWT component. + * An to the o JMonkey application within an AWT component. * @author Julien Seinturier - COMEX SA - http://www.seinturier.fr */ public class AWTComponentAppState extends AbstractAppState { From 74e70e1add5951868236fab310e546fe2a93688b Mon Sep 17 00:00:00 2001 From: mohsin-681 Date: Tue, 15 Oct 2024 05:06:44 -0400 Subject: [PATCH 10/43] Removed unnecessary import --- .../src/main/java/com/jme3/app/state/AWTComponentAppState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java index 12e7045b2..c418dca6c 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java @@ -38,7 +38,7 @@ import com.jme3.system.AWTTaskExecutor; /** - * An to the o JMonkey application within an AWT component. + * An to the JMonkey application within an AWT component. * @author Julien Seinturier - COMEX SA - http://www.seinturier.fr */ public class AWTComponentAppState extends AbstractAppState { From 9f4d557326ab28e105d1ec73ecf74ba176004583 Mon Sep 17 00:00:00 2001 From: apurba-das Date: Tue, 15 Oct 2024 09:44:45 -0400 Subject: [PATCH 11/43] Changed file to be the same as main branch --- .../jme3test/android/TestAndroidSensors.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java b/jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java index a1da1b68a..b38bba76c 100644 --- a/jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java +++ b/jme3-android-examples/src/main/java/jme3test/android/TestAndroidSensors.java @@ -77,8 +77,6 @@ public class TestAndroidSensors extends SimpleApplication implements ActionListe // toggle to enable controlling geometry rotation boolean enableGeometryRotation = true; - private static final String MOUSECLICK = "MouseClick"; - // Make sure to set joystickEventsEnabled = true in MainActivity for Android private float toDegrees(float rad) { @@ -90,7 +88,6 @@ public void simpleInitApp() { // useAbsolute = true; // enableRumble = true; - private static final String COLOR = "Color"; if (enableFlyByCameraRotation) { flyCam.setEnabled(true); @@ -104,21 +101,21 @@ public void simpleInitApp() { Geometry geoX = new Geometry("X", lineX); Material matX = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - matX.setColor(COLOR, ColorRGBA.Red); + matX.setColor("Color", ColorRGBA.Red); matX.getAdditionalRenderState().setLineWidth(30); geoX.setMaterial(matX); rootNode.attachChild(geoX); Geometry geoY = new Geometry("Y", lineY); Material matY = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - matY.setColor(COLOR, ColorRGBA.Green); + matY.setColor("Color", ColorRGBA.Green); matY.getAdditionalRenderState().setLineWidth(30); geoY.setMaterial(matY); rootNode.attachChild(geoY); Geometry geoZ = new Geometry("Z", lineZ); Material matZ = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - matZ.setColor(COLOR, ColorRGBA.Blue); + matZ.setColor("Color", ColorRGBA.Blue); matZ.getAdditionalRenderState().setLineWidth(30); geoZ.setMaterial(matZ); rootNode.attachChild(geoZ); @@ -126,7 +123,7 @@ public void simpleInitApp() { Box b = new Box(1, 1, 1); geomZero = new Geometry("Box", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - mat.setColor(COLOR, ColorRGBA.Yellow); + mat.setColor("Color", ColorRGBA.Yellow); Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg"); mat.setTexture("ColorMap", tex_ml); geomZero.setMaterial(mat); @@ -137,8 +134,8 @@ public void simpleInitApp() { // Touch (aka MouseInput.BUTTON_LEFT) is used to record the starting // orientation when using absolute rotations - inputManager.addMapping(MOUSECLICK, new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); - inputManager.addListener(this, MOUSECLICK); + inputManager.addMapping("MouseClick", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); + inputManager.addListener(this, "MouseClick"); Joystick[] joysticks = inputManager.getJoysticks(); if (joysticks == null || joysticks.length < 1) { @@ -233,7 +230,7 @@ public void simpleUpdate(float tpf) { @Override public void onAction(String string, boolean pressed, float tpf) { - if (string.equalsIgnoreCase(MOUSECLICK) && pressed) { + if (string.equalsIgnoreCase("MouseClick") && pressed) { // Calibrate the axis (set new zero position) if the axis // is a sensor joystick axis for (IntMap.Entry entry : joystickMap) { From 2b53cfa70ae6ff50b175bc047e49b2495e1417e5 Mon Sep 17 00:00:00 2001 From: apurba-das Date: Tue, 15 Oct 2024 12:46:49 -0400 Subject: [PATCH 12/43] Remove the useless parentheses in AWTComponentRenderer --- .scannerwork/.sonar_lock | 0 .scannerwork/report-task.txt | 6 ++++++ build.gradle | 4 ++++ .../src/main/java/com/jme3/system/AWTComponentRenderer.java | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .scannerwork/.sonar_lock create mode 100644 .scannerwork/report-task.txt diff --git a/.scannerwork/.sonar_lock b/.scannerwork/.sonar_lock new file mode 100644 index 000000000..e69de29bb diff --git a/.scannerwork/report-task.txt b/.scannerwork/report-task.txt new file mode 100644 index 000000000..ea9845063 --- /dev/null +++ b/.scannerwork/report-task.txt @@ -0,0 +1,6 @@ +projectKey=jmonkeyengineFall2024 +serverUrl=http://localhost:9000 +serverVersion=10.7.0.96327 +dashboardUrl=http://localhost:9000/dashboard?id=jmonkeyengineFall2024 +ceTaskId=8d24eeb9-3cab-4fce-b728-43cbab265d63 +ceTaskUrl=http://localhost:9000/api/ce/task?id=8d24eeb9-3cab-4fce-b728-43cbab265d63 diff --git a/build.gradle b/build.gradle index 6e8e919e5..8f0a77730 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,10 @@ buildscript { } } +plugins { + id "org.sonarqube" version "5.1.0.4882" +} + allprojects { repositories { mavenCentral() diff --git a/jme3-desktop/src/main/java/com/jme3/system/AWTComponentRenderer.java b/jme3-desktop/src/main/java/com/jme3/system/AWTComponentRenderer.java index bfb0e85e3..7f5e4d7ff 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/AWTComponentRenderer.java +++ b/jme3-desktop/src/main/java/com/jme3/system/AWTComponentRenderer.java @@ -328,7 +328,7 @@ protected void writeFrame() { imageDataBuffer[i] = ((0xff & byteBuffer[i*4+3]) << 24) // Alpha | ((0xff & byteBuffer[i*4]) << 16) // Red | ((0xff & byteBuffer[i*4+1]) << 8) // Green - | ((0xff & byteBuffer[i*4+2])); // BLue + | (0xff & byteBuffer[i*4+2]); // BLue } } From 69d73d90a86e441e60f67d0f4ef4405eb4aef288 Mon Sep 17 00:00:00 2001 From: Khushi Date: Tue, 15 Oct 2024 13:16:47 -0400 Subject: [PATCH 13/43] issue #9. Changed fcc4 to be a static final constant. --- .scannerwork/.sonar_lock | 0 .scannerwork/report-task.txt | 6 ++++++ build.gradle | 8 +++++++- .../src/main/java/com/jme3/app/state/MjpegFileWriter.java | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .scannerwork/.sonar_lock create mode 100644 .scannerwork/report-task.txt diff --git a/.scannerwork/.sonar_lock b/.scannerwork/.sonar_lock new file mode 100644 index 000000000..e69de29bb diff --git a/.scannerwork/report-task.txt b/.scannerwork/report-task.txt new file mode 100644 index 000000000..a2c8e691c --- /dev/null +++ b/.scannerwork/report-task.txt @@ -0,0 +1,6 @@ +projectKey=jmonkeyengineFall2024 +serverUrl=http://localhost:9000 +serverVersion=10.7.0.96327 +dashboardUrl=http://localhost:9000/dashboard?id=jmonkeyengineFall2024 +ceTaskId=a4474288-3df7-46dd-bbd5-3b13c62a72a2 +ceTaskUrl=http://localhost:9000/api/ce/task?id=a4474288-3df7-46dd-bbd5-3b13c62a72a2 diff --git a/build.gradle b/build.gradle index 56b5f0366..791e8f1be 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,9 @@ buildscript { classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.18" } } - +plugins { + id "org.sonarqube" version "5.1.0.4882" +} allprojects { repositories { mavenCentral() @@ -251,3 +253,7 @@ retrolambda { incremental true jvmArgs '-noverify' } +<<<<<<< Updated upstream +======= + +>>>>>>> Stashed changes diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java index dcb7e68bc..e4930dbab 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java @@ -196,7 +196,7 @@ private class RIFFHeader { public byte[] fcc2 = new byte[]{'A', 'V', 'I', ' '}; public byte[] fcc3 = new byte[]{'L', 'I', 'S', 'T'}; public int listSize = 200; - public byte[] fcc4 = new byte[]{'h', 'd', 'r', 'l'}; + private static final byte[] fcc4 = new byte[]{'h', 'd', 'r', 'l'}; public RIFFHeader() { } From a103eb21402061c8b9bb658927ffd1cd2421a834 Mon Sep 17 00:00:00 2001 From: Khushi Date: Tue, 15 Oct 2024 14:13:24 -0400 Subject: [PATCH 14/43] Revert "issue #9. Changed fcc4 to be a static final constant." This reverts commit 69d73d90a86e441e60f67d0f4ef4405eb4aef288. --- .scannerwork/.sonar_lock | 0 .scannerwork/report-task.txt | 6 ------ build.gradle | 8 +------- .../src/main/java/com/jme3/app/state/MjpegFileWriter.java | 2 +- 4 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 .scannerwork/.sonar_lock delete mode 100644 .scannerwork/report-task.txt diff --git a/.scannerwork/.sonar_lock b/.scannerwork/.sonar_lock deleted file mode 100644 index e69de29bb..000000000 diff --git a/.scannerwork/report-task.txt b/.scannerwork/report-task.txt deleted file mode 100644 index a2c8e691c..000000000 --- a/.scannerwork/report-task.txt +++ /dev/null @@ -1,6 +0,0 @@ -projectKey=jmonkeyengineFall2024 -serverUrl=http://localhost:9000 -serverVersion=10.7.0.96327 -dashboardUrl=http://localhost:9000/dashboard?id=jmonkeyengineFall2024 -ceTaskId=a4474288-3df7-46dd-bbd5-3b13c62a72a2 -ceTaskUrl=http://localhost:9000/api/ce/task?id=a4474288-3df7-46dd-bbd5-3b13c62a72a2 diff --git a/build.gradle b/build.gradle index 791e8f1be..56b5f0366 100644 --- a/build.gradle +++ b/build.gradle @@ -15,9 +15,7 @@ buildscript { classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.18" } } -plugins { - id "org.sonarqube" version "5.1.0.4882" -} + allprojects { repositories { mavenCentral() @@ -253,7 +251,3 @@ retrolambda { incremental true jvmArgs '-noverify' } -<<<<<<< Updated upstream -======= - ->>>>>>> Stashed changes diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java index e4930dbab..dcb7e68bc 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java @@ -196,7 +196,7 @@ private class RIFFHeader { public byte[] fcc2 = new byte[]{'A', 'V', 'I', ' '}; public byte[] fcc3 = new byte[]{'L', 'I', 'S', 'T'}; public int listSize = 200; - private static final byte[] fcc4 = new byte[]{'h', 'd', 'r', 'l'}; + public byte[] fcc4 = new byte[]{'h', 'd', 'r', 'l'}; public RIFFHeader() { } From 8fb674e7a3c1c51da16bc0ca0f496ff2533a5444 Mon Sep 17 00:00:00 2001 From: Khushi Date: Tue, 15 Oct 2024 14:19:19 -0400 Subject: [PATCH 15/43] issue #9. Changed fcc4 to be a static final constant and also resolved conflicts --- .../src/main/java/com/jme3/app/state/MjpegFileWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java index dcb7e68bc..e4930dbab 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java @@ -196,7 +196,7 @@ private class RIFFHeader { public byte[] fcc2 = new byte[]{'A', 'V', 'I', ' '}; public byte[] fcc3 = new byte[]{'L', 'I', 'S', 'T'}; public int listSize = 200; - public byte[] fcc4 = new byte[]{'h', 'd', 'r', 'l'}; + private static final byte[] fcc4 = new byte[]{'h', 'd', 'r', 'l'}; public RIFFHeader() { } From 5f98865d95b343c8b47f9abe347930988445d33e Mon Sep 17 00:00:00 2001 From: SladeJustinFerrao Date: Tue, 15 Oct 2024 17:30:28 -0400 Subject: [PATCH 16/43] Threw a dedicated exception instead of a generic one to resolve #13 --- .../java/com/jme3/app/state/MjpegFileWriter.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java index ae1d6b3b5..c82efbd8b 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java @@ -70,11 +70,11 @@ public class MjpegFileWriter implements AutoCloseable { long position = 0; AVIIndexList indexlist = null; - public MjpegFileWriter(File aviFile, int width, int height, double framerate) throws Exception { + public MjpegFileWriter(File aviFile, int width, int height, double framerate) throws IOException { this(aviFile, width, height, framerate, 0); } - public MjpegFileWriter(File aviFile, int width, int height, double framerate, int numFrames) throws Exception { + public MjpegFileWriter(File aviFile, int width, int height, double framerate, int numFrames) throws IOException { this.aviFile = aviFile; this.width = width; this.height = height; @@ -101,15 +101,15 @@ public MjpegFileWriter(File aviFile, int width, int height, double framerate, in position = headerBytes.length + listBytes.length; } - public void addImage(Image image) throws Exception { + public void addImage(Image image) throws IOException { addImage(image, 0.8f); } - public void addImage(Image image, float quality) throws Exception { + public void addImage(Image image, float quality) throws IOException { addImage(writeImageToBytes(image, quality)); } - public void addImage(byte[] imageData) throws Exception { + public void addImage(byte[] imageData) throws IOException { byte[] fcc = new byte[]{'0', '0', 'd', 'b'}; int useLength = imageData.length; int extra = (useLength + (int) position) % 4; @@ -541,7 +541,7 @@ public byte[] toBytes() throws IOException { } } - public byte[] writeImageToBytes(Image image, float quality) throws Exception { + public byte[] writeImageToBytes(Image image, float quality) throws IOException { BufferedImage bi; if (image instanceof BufferedImage && ((BufferedImage) image).getType() == BufferedImage.TYPE_INT_RGB) { bi = (BufferedImage) image; From 3e8738c6e49d70c1a1f74c3a52eb32ff1b8adfda Mon Sep 17 00:00:00 2001 From: apurba-das <61978827+apurba-das@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:44:25 -0400 Subject: [PATCH 17/43] Delete .scannerwork directory --- .scannerwork/.sonar_lock | 0 .scannerwork/report-task.txt | 6 ------ 2 files changed, 6 deletions(-) delete mode 100644 .scannerwork/.sonar_lock delete mode 100644 .scannerwork/report-task.txt diff --git a/.scannerwork/.sonar_lock b/.scannerwork/.sonar_lock deleted file mode 100644 index e69de29bb..000000000 diff --git a/.scannerwork/report-task.txt b/.scannerwork/report-task.txt deleted file mode 100644 index ea9845063..000000000 --- a/.scannerwork/report-task.txt +++ /dev/null @@ -1,6 +0,0 @@ -projectKey=jmonkeyengineFall2024 -serverUrl=http://localhost:9000 -serverVersion=10.7.0.96327 -dashboardUrl=http://localhost:9000/dashboard?id=jmonkeyengineFall2024 -ceTaskId=8d24eeb9-3cab-4fce-b728-43cbab265d63 -ceTaskUrl=http://localhost:9000/api/ce/task?id=8d24eeb9-3cab-4fce-b728-43cbab265d63 From 3c517a62ef4aa603e1eeff08d603671a6f699d96 Mon Sep 17 00:00:00 2001 From: SladeJustinFerrao Date: Tue, 15 Oct 2024 19:16:45 -0400 Subject: [PATCH 18/43] Threw an UnsupportedOperationException in empty methods to resolve #16 --- .../src/main/java/com/jme3/app/state/MjpegFileWriter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java index c82efbd8b..68b79dbe4 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java @@ -306,6 +306,7 @@ private class AVIStreamList { public byte[] fcc2 = new byte[]{'s', 't', 'r', 'l'}; public AVIStreamList() { + throw new UnsupportedOperationException("AVIStreamList constructor is not supported."); } public byte[] toBytes() throws IOException { @@ -472,6 +473,7 @@ private class AVIIndexList { public List ind = new ArrayList<>(); public AVIIndexList() { + throw new UnsupportedOperationException("AVIIndexList constructor is not supported."); } @SuppressWarnings("unused") From 6a67eb021f347af50e37711f4043f8d19e0c3fbf Mon Sep 17 00:00:00 2001 From: apurba-das <61978827+apurba-das@users.noreply.github.com> Date: Tue, 15 Oct 2024 20:58:18 -0400 Subject: [PATCH 19/43] Update build.gradle --- build.gradle | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 8f0a77730..56b5f0366 100644 --- a/build.gradle +++ b/build.gradle @@ -16,10 +16,6 @@ buildscript { } } -plugins { - id "org.sonarqube" version "5.1.0.4882" -} - allprojects { repositories { mavenCentral() @@ -254,4 +250,4 @@ retrolambda { javaVersion JavaVersion.VERSION_1_7 incremental true jvmArgs '-noverify' -} \ No newline at end of file +} From f59a95da2a5d046342d8046d470b682c118f62f9 Mon Sep 17 00:00:00 2001 From: apurba-das <61978827+apurba-das@users.noreply.github.com> Date: Tue, 15 Oct 2024 20:58:38 -0400 Subject: [PATCH 20/43] Delete .scannerwork directory --- .scannerwork/.sonar_lock | 0 .scannerwork/report-task.txt | 6 ------ 2 files changed, 6 deletions(-) delete mode 100644 .scannerwork/.sonar_lock delete mode 100644 .scannerwork/report-task.txt diff --git a/.scannerwork/.sonar_lock b/.scannerwork/.sonar_lock deleted file mode 100644 index e69de29bb..000000000 diff --git a/.scannerwork/report-task.txt b/.scannerwork/report-task.txt deleted file mode 100644 index ea9845063..000000000 --- a/.scannerwork/report-task.txt +++ /dev/null @@ -1,6 +0,0 @@ -projectKey=jmonkeyengineFall2024 -serverUrl=http://localhost:9000 -serverVersion=10.7.0.96327 -dashboardUrl=http://localhost:9000/dashboard?id=jmonkeyengineFall2024 -ceTaskId=8d24eeb9-3cab-4fce-b728-43cbab265d63 -ceTaskUrl=http://localhost:9000/api/ce/task?id=8d24eeb9-3cab-4fce-b728-43cbab265d63 From 7b29c63382b1eb68189da1d87fcf2660d7185569 Mon Sep 17 00:00:00 2001 From: SladeJustinFerrao Date: Tue, 15 Oct 2024 21:07:53 -0400 Subject: [PATCH 21/43] Reverted unnecessary changes --- .../src/main/java/com/jme3/app/state/AWTComponentAppState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java index c418dca6c..c4a5589ca 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java @@ -38,7 +38,7 @@ import com.jme3.system.AWTTaskExecutor; /** - * An to the JMonkey application within an AWT component. + * An app state dedicated to the rendering of a JMonkey application within an AWT component. * @author Julien Seinturier - COMEX SA - http://www.seinturier.fr */ public class AWTComponentAppState extends AbstractAppState { From 7a2a8ab555cea27a06833d34d8bde8eb05faeac1 Mon Sep 17 00:00:00 2001 From: SladeJustinFerrao Date: Tue, 15 Oct 2024 22:14:04 -0400 Subject: [PATCH 22/43] File Update --- .../src/main/java/com/jme3/app/state/MjpegFileWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java index 85c30c5df..6e98a4172 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java @@ -196,7 +196,7 @@ private class RIFFHeader { public byte[] fcc2 = new byte[]{'A', 'V', 'I', ' '}; public byte[] fcc3 = new byte[]{'L', 'I', 'S', 'T'}; public int listSize = 200; - private static final byte[] fcc4 = new byte[]{'h', 'd', 'r', 'l'}; + private byte[] fcc4 = new byte[]{'h', 'd', 'r', 'l'}; public RIFFHeader() { } From 502296307f9f8e710a728fa6ab6302366726448e Mon Sep 17 00:00:00 2001 From: apurba-das <61978827+apurba-das@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:17:30 -0500 Subject: [PATCH 23/43] Refactor AwtMouseInput.java to remove clone Clones location: Starting at line 241 of jmonkeyengineFall2024-master\jme3-desktop\src\main\java\com\jme3\input\awt\AwtMouseInput.java Starting at line 251 of jmonkeyengineFall2024-master\jme3-desktop\src\main\java\com\jme3\input\awt\AwtMouseInput.java --- .../com/jme3/input/awt/AwtMouseInput.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/input/awt/AwtMouseInput.java b/jme3-desktop/src/main/java/com/jme3/input/awt/AwtMouseInput.java index 80101df89..7abcd2131 100644 --- a/jme3-desktop/src/main/java/com/jme3/input/awt/AwtMouseInput.java +++ b/jme3-desktop/src/main/java/com/jme3/input/awt/AwtMouseInput.java @@ -234,25 +234,24 @@ public void mouseClicked(MouseEvent awtEvt) { // listener.onMouseButtonEvent(evt); } - @Override - public void mousePressed(MouseEvent awtEvt) { - // Must flip Y! + // New helper method to handle mouse button events + private void handleMouseButtonEvent(MouseEvent awtEvt, boolean isPressed) { int y = component.getHeight() - awtEvt.getY(); - MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(awtEvt), true, awtEvt.getX(), y); + MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(awtEvt), isPressed, awtEvt.getX(), y); evt.setTime(awtEvt.getWhen()); synchronized (eventQueue) { eventQueue.add(evt); } } + @Override + public void mousePressed(MouseEvent awtEvt) { + handleMouseButtonEvent(awtEvt, true); + } + @Override public void mouseReleased(MouseEvent awtEvt) { - int y = component.getHeight() - awtEvt.getY(); - MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(awtEvt), false, awtEvt.getX(), y); - evt.setTime(awtEvt.getWhen()); - synchronized (eventQueue) { - eventQueue.add(evt); - } + handleMouseButtonEvent(awtEvt, false); } @Override From 3af96a3883532c8122dab46409ef490d0ab8232f Mon Sep 17 00:00:00 2001 From: KarthikCU1054 Date: Mon, 11 Nov 2024 12:38:32 -0500 Subject: [PATCH 24/43] Refactored the code to remove a clone in the methods "keyPressed" and "keyReleased". --- .../java/com/jme3/input/awt/AwtKeyInput.java | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/input/awt/AwtKeyInput.java b/jme3-desktop/src/main/java/com/jme3/input/awt/AwtKeyInput.java index 1ce0aeb69..fb1a4b5fa 100644 --- a/jme3-desktop/src/main/java/com/jme3/input/awt/AwtKeyInput.java +++ b/jme3-desktop/src/main/java/com/jme3/input/awt/AwtKeyInput.java @@ -117,34 +117,30 @@ public void keyTyped(KeyEvent evt) { // key code is zero for typed events } - @Override - public void keyPressed(KeyEvent evt) { + private void keyPressedReleased(KeyEvent evt, boolean pressed){ int code = convertAwtKey(evt.getKeyCode()); - - // Check if key was already pressed + if (!keyStateSet.get(code)){ keyStateSet.set(code); - KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), true, false); + KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), pressed, false); keyEvent.setTime(evt.getWhen()); synchronized (eventQueue){ eventQueue.add(keyEvent); - } + } } } + @Override + public void keyPressed(KeyEvent evt) { + + // Check if key was already pressed + keyPressedReleased(evt, true); + } + @Override public void keyReleased(KeyEvent evt) { - int code = convertAwtKey(evt.getKeyCode()); - - // Check if key was already released - if (keyStateSet.get(code)) { - keyStateSet.clear(code); - KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), false, false); - keyEvent.setTime(evt.getWhen()); - synchronized (eventQueue){ - eventQueue.add(keyEvent); - } - } + // Check if key was already pressed + keyPressedReleased(evt, false); } /** From 362683a8b9baa46bd6852f46471843889a61df93 Mon Sep 17 00:00:00 2001 From: SladeJustinFerrao Date: Mon, 11 Nov 2024 16:35:34 -0500 Subject: [PATCH 25/43] Removed the clones existing at lines 287 and 502 of MjpegFileWriter.java --- .../com/jme3/app/state/MjpegFileWriter.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java index b99dad18e..d2cf46d6b 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java @@ -277,6 +277,15 @@ public byte[] toBytes() throws IOException { } } + public static byte[] baosWrite(byte[] byteSet1, byte[] byteSet2, int size) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + baos.write(byteSet1); + baos.write(intBytes(swapInt(size))); + baos.write(byteSet2); + + return baos.toByteArray(); + } + private class AVIStreamList { public byte[] fcc = new byte[]{'L', 'I', 'S', 'T'}; @@ -288,12 +297,7 @@ public AVIStreamList() { } public byte[] toBytes() throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - baos.write(fcc); - baos.write(intBytes(swapInt(size))); - baos.write(fcc2); - - return baos.toByteArray(); + return baosWrite(fcc, fcc2, size); } } @@ -503,12 +507,7 @@ public AVIJunk() { } public byte[] toBytes() throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - baos.write(fcc); - baos.write(intBytes(swapInt(size))); - baos.write(data); - - return baos.toByteArray(); + return baosWrite(fcc, data, size); } } From f611095cdbce5108091dbf16d838cf4b95c7885f Mon Sep 17 00:00:00 2001 From: Khushi Date: Mon, 11 Nov 2024 23:52:57 -0500 Subject: [PATCH 26/43] Refactored duplicate code to retrieve file name in NativeLibraryLoader.java (issue #69) --- .../com/jme3/system/NativeLibraryLoader.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java index c0eb8613e..e315a3c8f 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java +++ b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java @@ -408,12 +408,7 @@ public static void extractNativeLibrary(Platform platform, String name, File tar return; } - String loadedAsFileName; - if (library.getExtractedAsName() != null) { - loadedAsFileName = library.getExtractedAsName(); - } else { - loadedAsFileName = Paths.get(pathInJar).getFileName().toString(); - } + String loadedAsFileName= getLoadedFileName(library, pathInJar); URLConnection conn = url.openConnection(); @@ -481,13 +476,7 @@ public static void loadNativeLibrary(String name, boolean isRequired) { // The library has been found and is ready to be extracted. // Determine what filename it should be extracted as. - String loadedAsFileName; - if (library.getExtractedAsName() != null) { - loadedAsFileName = library.getExtractedAsName(); - } else { - // Just use the original filename as it is in the JAR. - loadedAsFileName = Paths.get(pathInJar).getFileName().toString(); - } + String loadedAsFileName= getLoadedFileName(library, pathInJar); File extractionDirectory = getExtractionFolder(); URLConnection conn; @@ -563,4 +552,12 @@ private static boolean isExtractingRequired(URLConnection conn, File targetFile) // a newer version of library, downgraded to an older version // which will make above check invalid and extract it again. } -} + private static String getLoadedFileName(NativeLibrary library, String pathInJar) { + if (library.getExtractedAsName() != null) { + return library.getExtractedAsName(); + } else { + return Paths.get(pathInJar).getFileName().toString(); + } + } + +} \ No newline at end of file From 10ce4a287e4736f8c32e46c79cf01080ad727485 Mon Sep 17 00:00:00 2001 From: Khushi Date: Mon, 11 Nov 2024 23:57:31 -0500 Subject: [PATCH 27/43] Fixed error in MjpegFileWriter --- .../src/main/java/com/jme3/app/state/MjpegFileWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java index e4930dbab..a0be9fffb 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/MjpegFileWriter.java @@ -196,7 +196,7 @@ private class RIFFHeader { public byte[] fcc2 = new byte[]{'A', 'V', 'I', ' '}; public byte[] fcc3 = new byte[]{'L', 'I', 'S', 'T'}; public int listSize = 200; - private static final byte[] fcc4 = new byte[]{'h', 'd', 'r', 'l'}; + private byte[] fcc4 = new byte[]{'h', 'd', 'r', 'l'}; public RIFFHeader() { } From b266595eabd8e766457dde18df0569ebbd67c2c9 Mon Sep 17 00:00:00 2001 From: mohsin-681 Date: Tue, 12 Nov 2024 03:43:25 -0500 Subject: [PATCH 28/43] Refactored code to remove clones in JmeDesktopSystem.java file lines 179 and 198 --- .../com/jme3/system/JmeDesktopSystem.java | 57 ++++++++----------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java b/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java index 2a9f5d207..37e912cf9 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java +++ b/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java @@ -158,24 +158,10 @@ private JmeContext newContextLwjgl(AppSettings settings, JmeContext.Type type) { return null; } - @SuppressWarnings("unchecked") - private JmeContext newContextJogl(AppSettings settings, JmeContext.Type type) { + // Helper method to avoid repetition + private JmeContext createContext(String className) { try { - Class ctxClazz = null; - switch (type) { - case Display: - ctxClazz = Class.forName("com.jme3.system.jogl.JoglNewtDisplay"); - break; - case Canvas: - ctxClazz = Class.forName("com.jme3.system.jogl.JoglNewtCanvas"); - break; - case OffscreenSurface: - ctxClazz = Class.forName("com.jme3.system.jogl.JoglOffscreenBuffer"); - break; - default: - throw new IllegalArgumentException("Unsupported context type " + type); - } - + Class ctxClazz = Class.forName(className); return (JmeContext) ctxClazz.getDeclaredConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException @@ -183,28 +169,35 @@ private JmeContext newContextJogl(AppSettings settings, JmeContext.Type type) { logger.log(Level.SEVERE, "Failed to create context", ex); } catch (ClassNotFoundException ex) { logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!\n" - + "Make sure jme3-jogl is on the classpath.", ex); + + "Make sure the appropriate context jar is on the classpath.", ex); } - return null; } @SuppressWarnings("unchecked") - private JmeContext newContextCustom(AppSettings settings, JmeContext.Type type) { - try { - String className = settings.getRenderer().substring("CUSTOM".length()); - - Class ctxClazz = Class.forName(className); - return (JmeContext) ctxClazz.getDeclaredConstructor().newInstance(); - } catch (InstantiationException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException - | NoSuchMethodException | SecurityException ex) { - logger.log(Level.SEVERE, "Failed to create context", ex); - } catch (ClassNotFoundException ex) { - logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!", ex); + private JmeContext newContextJogl(AppSettings settings, JmeContext.Type type) { + String className = null; + switch (type) { + case Display: + className = "com.jme3.system.jogl.JoglNewtDisplay"; + break; + case Canvas: + className = "com.jme3.system.jogl.JoglNewtCanvas"; + break; + case OffscreenSurface: + className = "com.jme3.system.jogl.JoglOffscreenBuffer"; + break; + default: + throw new IllegalArgumentException("Unsupported context type " + type); } - return null; + return createContext(className); + } + + @SuppressWarnings("unchecked") + private JmeContext newContextCustom(AppSettings settings, JmeContext.Type type) { + String className = settings.getRenderer().substring("CUSTOM".length()); + return createContext(className); } @Override From c98af3774e4165933b20b9e152367f822ca4a2e0 Mon Sep 17 00:00:00 2001 From: apurba-das <61978827+apurba-das@users.noreply.github.com> Date: Sat, 30 Nov 2024 21:25:39 -0500 Subject: [PATCH 29/43] Update XMLImporter.java to fix XML External Entity (XXE) Injection vulnerability --- .../xml/java/com/jme3/export/xml/XMLImporter.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java b/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java index 7cf2a98cb..7ff368e98 100644 --- a/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java +++ b/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java @@ -98,7 +98,17 @@ public Savable load(File f) throws IOException { public Savable load(InputStream f) throws IOException { try { - domIn = new DOMInputCapsule(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(f), this); + // Create a secure DocumentBuilderFactory + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + + // Disable external entity processing to prevent XXE attacks + factory.setFeature("http://xml.org/sax/features/external-general-entities", false); + factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + factory.setExpandEntityReferences(false); + + // Parse the XML securely + domIn = new DOMInputCapsule(factory.newDocumentBuilder().parse(f), this); return domIn.readSavable(null, null); } catch (SAXException | ParserConfigurationException e) { IOException ex = new IOException(); @@ -106,7 +116,7 @@ public Savable load(InputStream f) throws IOException { throw ex; } } - + @Override public InputCapsule getCapsule(Savable id) { return domIn; From d3d9211fda91b48d7a0dc722d9913ccfbf5bd524 Mon Sep 17 00:00:00 2001 From: Khushi Date: Sun, 1 Dec 2024 00:26:37 -0500 Subject: [PATCH 30/43] Update SocketConnecter to resolve #132 issue Replaced plain socket connection with SSL socket --- .../jme3/network/kernel/tcp/SocketConnector.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/jme3-networking/src/main/java/com/jme3/network/kernel/tcp/SocketConnector.java b/jme3-networking/src/main/java/com/jme3/network/kernel/tcp/SocketConnector.java index be4682bd9..ebb2ce4db 100644 --- a/jme3-networking/src/main/java/com/jme3/network/kernel/tcp/SocketConnector.java +++ b/jme3-networking/src/main/java/com/jme3/network/kernel/tcp/SocketConnector.java @@ -42,6 +42,9 @@ import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicBoolean; +import javax.net.ssl.SSLSocket; +import javax.net.ssl.SSLSocketFactory; + /** * A straight forward socket-based connector implementation that @@ -69,8 +72,16 @@ public SocketConnector( InetAddress address, int port ) throws IOException // put it there. sock.setTcpNoDelay(true); - in = sock.getInputStream(); - out = sock.getOutputStream(); + SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); + SSLSocket sslSocket = (SSLSocket) factory.createSocket(address, port); + + sslSocket.setEnabledProtocols(new String[]{"TLSv1.2", "TLSv1.3"}); + + // Start SSL handshake + sslSocket.startHandshake(); + + in = sslSocket.getInputStream(); + out = sslSocket.getOutputStream(); connected.set(true); } From 089295d2e3f5b4f9ff4aaef49914e17b16405d7c Mon Sep 17 00:00:00 2001 From: Khushi <145604225+Kewcat@users.noreply.github.com> Date: Sun, 1 Dec 2024 01:58:33 -0500 Subject: [PATCH 31/43] Revert "Update SocketConnecter to resolve #132 issue" --- .../jme3/network/kernel/tcp/SocketConnector.java | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/jme3-networking/src/main/java/com/jme3/network/kernel/tcp/SocketConnector.java b/jme3-networking/src/main/java/com/jme3/network/kernel/tcp/SocketConnector.java index ebb2ce4db..be4682bd9 100644 --- a/jme3-networking/src/main/java/com/jme3/network/kernel/tcp/SocketConnector.java +++ b/jme3-networking/src/main/java/com/jme3/network/kernel/tcp/SocketConnector.java @@ -42,9 +42,6 @@ import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicBoolean; -import javax.net.ssl.SSLSocket; -import javax.net.ssl.SSLSocketFactory; - /** * A straight forward socket-based connector implementation that @@ -72,16 +69,8 @@ public SocketConnector( InetAddress address, int port ) throws IOException // put it there. sock.setTcpNoDelay(true); - SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); - SSLSocket sslSocket = (SSLSocket) factory.createSocket(address, port); - - sslSocket.setEnabledProtocols(new String[]{"TLSv1.2", "TLSv1.3"}); - - // Start SSL handshake - sslSocket.startHandshake(); - - in = sslSocket.getInputStream(); - out = sslSocket.getOutputStream(); + in = sock.getInputStream(); + out = sock.getOutputStream(); connected.set(true); } From a5fe97589ffc82ec17ca9a90d868d4d435c15f07 Mon Sep 17 00:00:00 2001 From: Khushi Date: Sun, 1 Dec 2024 02:56:41 -0500 Subject: [PATCH 32/43] Update NativeLibraryLoader to address issue #132 --- .../main/java/com/jme3/system/NativeLibraryLoader.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java index e315a3c8f..3a8f4f113 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java +++ b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java @@ -467,9 +467,11 @@ public static void loadNativeLibrary(String name, boolean isRequired) { "The required native library '" + library.getName() + "'" + " was not found in the classpath via '" + pathInJar); } else if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "The optional native library ''{0}''" + - " was not found in the classpath via ''{1}''.", - new Object[]{library.getName(), pathInJar}); + logger.log(Level.FINE, + "The optional native library ''{0}''" + + " was not found in the classpath via ''{1}''.", + new Object[] { library.getName().replaceAll("[\\r\\n]", ""), + pathInJar.replaceAll("[\\r\\n]", "") }); } return; } From b6f26f5a25309e03ab55f58043dceec9cf182b85 Mon Sep 17 00:00:00 2001 From: mohsin-681 Date: Sun, 1 Dec 2024 03:38:41 -0500 Subject: [PATCH 33/43] Fix Path Traversal Vulnerability --- build.gradle | 4 ++- .../com/jme3/system/NativeLibraryLoader.java | 29 +++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 6e8e919e5..5b7895a8d 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,9 @@ buildscript { classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.18" } } - +plugins { + id "org.sonarqube" version "5.1.0.4882" +} allprojects { repositories { mavenCentral() diff --git a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java index e315a3c8f..3fc95ac0d 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java +++ b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java @@ -43,6 +43,10 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import com.jme3.util.res.Resources; @@ -319,15 +323,28 @@ public static File[] getJarsWithNatives() { } public static void extractNativeLibraries(Platform platform, File targetDir) throws IOException { - for (Map.Entry lib : nativeLibraryMap.entrySet()) { - if (lib.getValue().getPlatform() == platform) { - if (!targetDir.exists()) { - targetDir.mkdirs(); - } - extractNativeLibrary(platform, lib.getValue().getName(), targetDir); + // Ensure the target directory is canonicalized and sanitized + Path canonicalTargetDir = targetDir.toPath().toRealPath(); // Resolves any symlinks or relative paths + + for (Map.Entry lib : nativeLibraryMap.entrySet()) { + if (lib.getValue().getPlatform() == platform) { + // Validate the directory before proceeding + Path entryPath = new File(targetDir, lib.getValue().getName()).toPath().normalize(); + + // Ensure the entryPath is within the canonicalTargetDir + if (!entryPath.startsWith(canonicalTargetDir)) { + throw new IOException("Path traversal detected: " + entryPath); } + + if (!targetDir.exists()) { + targetDir.mkdirs(); + } + + extractNativeLibrary(platform, lib.getValue().getName(), targetDir); } } +} + /** * Removes platform-specific portions of a library file name so From d2b6c30d9d8f864150f8ed27a8742a9513d37bfb Mon Sep 17 00:00:00 2001 From: apurba-das <61978827+apurba-das@users.noreply.github.com> Date: Sun, 1 Dec 2024 19:20:34 -0500 Subject: [PATCH 34/43] Revert "Fixed XML External Entity (XXE) Injection vulnerability in XMLImporter.java" --- .../xml/java/com/jme3/export/xml/XMLImporter.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java b/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java index 7ff368e98..7cf2a98cb 100644 --- a/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java +++ b/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java @@ -98,17 +98,7 @@ public Savable load(File f) throws IOException { public Savable load(InputStream f) throws IOException { try { - // Create a secure DocumentBuilderFactory - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - - // Disable external entity processing to prevent XXE attacks - factory.setFeature("http://xml.org/sax/features/external-general-entities", false); - factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); - factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); - factory.setExpandEntityReferences(false); - - // Parse the XML securely - domIn = new DOMInputCapsule(factory.newDocumentBuilder().parse(f), this); + domIn = new DOMInputCapsule(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(f), this); return domIn.readSavable(null, null); } catch (SAXException | ParserConfigurationException e) { IOException ex = new IOException(); @@ -116,7 +106,7 @@ public Savable load(InputStream f) throws IOException { throw ex; } } - + @Override public InputCapsule getCapsule(Savable id) { return domIn; From 34c5d66136dcda778d2bb29517c9599efeeccab4 Mon Sep 17 00:00:00 2001 From: apurba-das <61978827+apurba-das@users.noreply.github.com> Date: Sun, 1 Dec 2024 22:48:09 -0500 Subject: [PATCH 35/43] Revert "Revert "Fixed XML External Entity (XXE) Injection vulnerability in XMLImporter.java"" --- .../xml/java/com/jme3/export/xml/XMLImporter.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java b/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java index 7cf2a98cb..7ff368e98 100644 --- a/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java +++ b/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java @@ -98,7 +98,17 @@ public Savable load(File f) throws IOException { public Savable load(InputStream f) throws IOException { try { - domIn = new DOMInputCapsule(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(f), this); + // Create a secure DocumentBuilderFactory + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + + // Disable external entity processing to prevent XXE attacks + factory.setFeature("http://xml.org/sax/features/external-general-entities", false); + factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + factory.setExpandEntityReferences(false); + + // Parse the XML securely + domIn = new DOMInputCapsule(factory.newDocumentBuilder().parse(f), this); return domIn.readSavable(null, null); } catch (SAXException | ParserConfigurationException e) { IOException ex = new IOException(); @@ -106,7 +116,7 @@ public Savable load(InputStream f) throws IOException { throw ex; } } - + @Override public InputCapsule getCapsule(Savable id) { return domIn; From 890b48a3333a256f8e380b38b1527b8bac9bd905 Mon Sep 17 00:00:00 2001 From: apurba-das <61978827+apurba-das@users.noreply.github.com> Date: Mon, 2 Dec 2024 00:01:34 -0500 Subject: [PATCH 36/43] Revert "Revert" --- .../xml/java/com/jme3/export/xml/XMLImporter.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java b/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java index 7ff368e98..7cf2a98cb 100644 --- a/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java +++ b/jme3-plugins/src/xml/java/com/jme3/export/xml/XMLImporter.java @@ -98,17 +98,7 @@ public Savable load(File f) throws IOException { public Savable load(InputStream f) throws IOException { try { - // Create a secure DocumentBuilderFactory - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - - // Disable external entity processing to prevent XXE attacks - factory.setFeature("http://xml.org/sax/features/external-general-entities", false); - factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); - factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); - factory.setExpandEntityReferences(false); - - // Parse the XML securely - domIn = new DOMInputCapsule(factory.newDocumentBuilder().parse(f), this); + domIn = new DOMInputCapsule(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(f), this); return domIn.readSavable(null, null); } catch (SAXException | ParserConfigurationException e) { IOException ex = new IOException(); @@ -116,7 +106,7 @@ public Savable load(InputStream f) throws IOException { throw ex; } } - + @Override public InputCapsule getCapsule(Savable id) { return domIn; From 25302261941fb9079b41cf3c3ebd814f7520297e Mon Sep 17 00:00:00 2001 From: apurba-das <61978827+apurba-das@users.noreply.github.com> Date: Mon, 2 Dec 2024 00:12:17 -0500 Subject: [PATCH 37/43] Fix Denial of Service (DoS) vulnerability in ShaderGenerator.java --- jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java b/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java index 337623423..66811db3b 100644 --- a/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java +++ b/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java @@ -236,7 +236,7 @@ protected void generateDeclarationAndMainBody(List shaderNodes, Stri protected void appendNodeDeclarationAndMain(String loadedSource, StringBuilder sourceDeclaration, StringBuilder source, ShaderNode shaderNode, ShaderGenerationInfo info, String shaderPath) { if (loadedSource.length() > 1) { loadedSource = loadedSource.substring(0, loadedSource.lastIndexOf("}")); - String[] sourceParts = loadedSource.split("\\s*void\\s*main\\s*\\(\\s*\\)\\s*\\{"); + String[] sourceParts = loadedSource.split("\\s+void\\s+main\\s*\\(\\s*\\)\\s*\\{"); if(sourceParts.length<2){ throw new IllegalArgumentException("Syntax error in "+ shaderPath +". Cannot find 'void main(){' in \n"+ loadedSource); } From 31e3b607111598ac6b03419cb8237bb884b93c70 Mon Sep 17 00:00:00 2001 From: karthikCU1054 Date: Mon, 2 Dec 2024 04:41:23 -0500 Subject: [PATCH 38/43] Fixed the Malicious code vulnerability (MALICIOUS_CODE). --- .../main/java/com/jme3/environment/util/EnvMapUtils.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/environment/util/EnvMapUtils.java b/jme3-core/src/main/java/com/jme3/environment/util/EnvMapUtils.java index 81c12e4a2..938c7813d 100644 --- a/jme3-core/src/main/java/com/jme3/environment/util/EnvMapUtils.java +++ b/jme3-core/src/main/java/com/jme3/environment/util/EnvMapUtils.java @@ -65,7 +65,7 @@ public class EnvMapUtils { public final static int NUM_SH_COEFFICIENT = 9; // See Peter-Pike Sloan paper for these coefficients //http://www.ppsloan.org/publications/StupidSH36.pdf - public static float[] shBandFactor = {1.0f, + private static float[] shBandFactor = {1.0f, 2.0f / 3.0f, 2.0f / 3.0f, 2.0f / 3.0f, 1.0f / 4.0f, 1.0f / 4.0f, 1.0f / 4.0f, 1.0f / 4.0f, 1.0f / 4.0f}; @@ -96,6 +96,10 @@ public static enum GenerationType { private EnvMapUtils() { } + public static float[] getShBandFactor() { + return shBandFactor.clone(); + } + /** * Creates a cube map from 6 images * From aa6a949e4a66406d9b9e9645221cb9cba673233c Mon Sep 17 00:00:00 2001 From: SladeJustinFerrao <133801711+SladeJustinFerrao@users.noreply.github.com> Date: Mon, 2 Dec 2024 20:48:14 -0500 Subject: [PATCH 39/43] Removed the software vulnerability to avoid denial of service --- jme3-core/src/main/java/com/jme3/shader/ShaderUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/shader/ShaderUtils.java b/jme3-core/src/main/java/com/jme3/shader/ShaderUtils.java index d1db58262..3da19a3d4 100644 --- a/jme3-core/src/main/java/com/jme3/shader/ShaderUtils.java +++ b/jme3-core/src/main/java/com/jme3/shader/ShaderUtils.java @@ -123,7 +123,7 @@ public static int getCardinality(String type, String swizzling) { card = 0; } } else { - card = Integer.parseInt(type.replaceAll(".*vec", "")); + card = type.startsWith("vec") ? Integer.parseInt(type.substring(3, 4)) : 0; if (swizzling.length() > 0) { card = swizzling.length(); From cd94218ca56ff04f8a90c7c1333fc89db219118d Mon Sep 17 00:00:00 2001 From: SladeJustinFerrao <133801711+SladeJustinFerrao@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:55:06 -0500 Subject: [PATCH 40/43] Update build.gradle --- build.gradle | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 5b7895a8d..56b5f0366 100644 --- a/build.gradle +++ b/build.gradle @@ -15,9 +15,7 @@ buildscript { classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.18" } } -plugins { - id "org.sonarqube" version "5.1.0.4882" -} + allprojects { repositories { mavenCentral() @@ -252,4 +250,4 @@ retrolambda { javaVersion JavaVersion.VERSION_1_7 incremental true jvmArgs '-noverify' -} \ No newline at end of file +} From 36be293ac42b050f004d7aaef7415e594f3f01d7 Mon Sep 17 00:00:00 2001 From: SladeJustinFerrao <133801711+SladeJustinFerrao@users.noreply.github.com> Date: Mon, 2 Dec 2024 22:22:20 -0500 Subject: [PATCH 41/43] Update ShaderGenerator.java --- jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java b/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java index 66811db3b..337623423 100644 --- a/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java +++ b/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java @@ -236,7 +236,7 @@ protected void generateDeclarationAndMainBody(List shaderNodes, Stri protected void appendNodeDeclarationAndMain(String loadedSource, StringBuilder sourceDeclaration, StringBuilder source, ShaderNode shaderNode, ShaderGenerationInfo info, String shaderPath) { if (loadedSource.length() > 1) { loadedSource = loadedSource.substring(0, loadedSource.lastIndexOf("}")); - String[] sourceParts = loadedSource.split("\\s+void\\s+main\\s*\\(\\s*\\)\\s*\\{"); + String[] sourceParts = loadedSource.split("\\s*void\\s*main\\s*\\(\\s*\\)\\s*\\{"); if(sourceParts.length<2){ throw new IllegalArgumentException("Syntax error in "+ shaderPath +". Cannot find 'void main(){' in \n"+ loadedSource); } From 4d43f5d3b17be682784db8ade15300c7bd5099d5 Mon Sep 17 00:00:00 2001 From: SladeJustinFerrao <133801711+SladeJustinFerrao@users.noreply.github.com> Date: Mon, 2 Dec 2024 23:14:54 -0500 Subject: [PATCH 42/43] Update ShaderGenerator.java --- jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java b/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java index 337623423..623b7b9ab 100644 --- a/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java +++ b/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java @@ -236,7 +236,7 @@ protected void generateDeclarationAndMainBody(List shaderNodes, Stri protected void appendNodeDeclarationAndMain(String loadedSource, StringBuilder sourceDeclaration, StringBuilder source, ShaderNode shaderNode, ShaderGenerationInfo info, String shaderPath) { if (loadedSource.length() > 1) { loadedSource = loadedSource.substring(0, loadedSource.lastIndexOf("}")); - String[] sourceParts = loadedSource.split("\\s*void\\s*main\\s*\\(\\s*\\)\\s*\\{"); + String[] sourceParts = loadedSource.split("\\s+void\\s*main\\s*\\(\\s*\\)\\s*\\{"); if(sourceParts.length<2){ throw new IllegalArgumentException("Syntax error in "+ shaderPath +". Cannot find 'void main(){' in \n"+ loadedSource); } From f52ca70fe23fc8450363038cc90f613611edf533 Mon Sep 17 00:00:00 2001 From: SladeJustinFerrao <133801711+SladeJustinFerrao@users.noreply.github.com> Date: Mon, 2 Dec 2024 23:22:02 -0500 Subject: [PATCH 43/43] Update ShaderGenerator.java --- jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java b/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java index 623b7b9ab..21bc4da3a 100644 --- a/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java +++ b/jme3-core/src/main/java/com/jme3/shader/ShaderGenerator.java @@ -236,7 +236,7 @@ protected void generateDeclarationAndMainBody(List shaderNodes, Stri protected void appendNodeDeclarationAndMain(String loadedSource, StringBuilder sourceDeclaration, StringBuilder source, ShaderNode shaderNode, ShaderGenerationInfo info, String shaderPath) { if (loadedSource.length() > 1) { loadedSource = loadedSource.substring(0, loadedSource.lastIndexOf("}")); - String[] sourceParts = loadedSource.split("\\s+void\\s*main\\s*\\(\\s*\\)\\s*\\{"); + String[] sourceParts = loadedSource.split("\\s*void\\s+main\\s*\\(\\s*\\)\\s*\\{"); if(sourceParts.length<2){ throw new IllegalArgumentException("Syntax error in "+ shaderPath +". Cannot find 'void main(){' in \n"+ loadedSource); }