Skip to content

Commit 928cab7

Browse files
omichelCopilotCoolSpy3
authored
Fix java warnings (#6936)
* Fixed warnings with Java compilation and execution * Updated tools related files * Fix Java compilation and run-time warnings * Update scripts/install/bash_profile.windows Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Set minimum Java version to Java 16 * Update docs/guide/using-java.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update scripts/install/bash_profile.windows Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update .gitignore Co-authored-by: CoolSpy3 <55305038+CoolSpy3@users.noreply.github.com> * Update scripts/install/bash_profile.windows Co-authored-by: CoolSpy3 <55305038+CoolSpy3@users.noreply.github.com> * Fixes the warning also for extern java controllers --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: CoolSpy3 <55305038+CoolSpy3@users.noreply.github.com>
1 parent e9061d7 commit 928cab7

File tree

8 files changed

+30
-78
lines changed

8 files changed

+30
-78
lines changed

.atom-build.json

Lines changed: 0 additions & 65 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@ Thumbs.db
7272

7373
# world thumbnail files
7474
.*.jpg
75+
76+
# Claude.ai
77+
/.claude

docs/guide/using-java.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ A complete description of these functions can be found in the reference guide wh
1010

1111
### Java and Java Compiler Installation
1212

13-
In order to develop and run Java controllers for Webots it is necessary to have the 64-bit version of the Java Development Kit (JDK) version 1.8 or later.
13+
In order to develop and run Java controllers for Webots it is necessary to have the 64-bit version of the Java Development Kit (JDK) version 16 or later.
1414

1515
The Java Development Kit (JDK) is free for personal and development use and it can be downloaded from the [Oracle Technology Network](http://www.oracle.com/technetwork/java/javase/downloads).
16-
Make sure you choose the most recent 64-bit release of the Standard Edition (SE) of the JDK version 8 or later.
16+
Make sure you choose the most recent 64-bit release of the Standard Edition (SE) of the JDK version 16 or later.
1717
Then, follow the installation instructions.
1818

1919
The `java` command is the Java Virtual Machine (JVM); it is used to execute Java controllers in Webots.

docs/reference/changelog-r2025.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- Fixed `addForceWithOffset` and `addTorque` doing the same thing as `addForce` in Python ([#6881](https://github.com/cyberbotics/webots/pull/6881)).
2525
- Fixed Python controllers on Windows ([#6933](https://github.com/cyberbotics/webots/pull/6933)).
2626
- OSM importer no longer crashes when run in 3d mode ([#6935](https://github.com/cyberbotics/webots/pull/6935)).
27+
- Fixed Java compilation deprecation warning and run-time warning ([#6936](https://github.com/cyberbotics/webots/pull/6936)).
2728

2829
## Webots R2025a
2930
Released on January 31st, 2025.

scripts/install/bash_profile.windows

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# Uncomment / edit the following environment variables when the corresponding software is installed #
44
#####################################################################################################
55

6-
# export PYTHON_HOME="C:\Program Files\Python310" # Optionally defines the path to Python home.
7-
# export JAVA_HOME=/C/Program\ Files/OpenJDK/`ls /C/Program\ Files/OpenJDK` # Optionally defines the path to Java home.
6+
# export PYTHON_HOME="/C/Program Files/Python3xx" # Optionally defines the path to Python home.
7+
# export JAVA_HOME="/C/Program Files/Microsoft/jdk-25.0.2.10-hotspot" # Optionally defines the path to Java home.
88
# export MATLAB_HOME=/C/Program\ Files/MATLAB/R2018b # Optionally defines the path to MATLAB home.
99
# export INNO_SETUP_HOME="/C/Program Files (x86)/Inno Setup 6" # Optionally defines the path to Inno Setup home.
1010

@@ -17,6 +17,16 @@ export WEBOTS_DISABLE_SAVE_SCREEN_PERSPECTIVE_ON_CLOSE=1 # If defined, Webots w
1717
export WEBOTS_ALLOW_MODIFY_INSTALLATION=1 # If defined, you are allowed to modify files in the Webots home using Webots.
1818

1919

20+
########################################################################
21+
# Bash function to start your favorite source code editor from MSYS2 #
22+
########################################################################
23+
24+
# code() {
25+
# "/C/Program Files/VSCodium/VSCodium.exe" "$@" &>/dev/null &
26+
# disown
27+
# }
28+
29+
2030
####################################################################################################
2131
# These aliases / environment variables allow to easily switch between a two webots source folders #
2232
####################################################################################################

src/controller/java/controller.i

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,12 @@ namespace webots {
468468
if (cPtr == 0)
469469
return null;
470470

471-
Field field = fields.get(new Long(cPtr));
471+
Field field = fields.get(Long.valueOf(cPtr));
472472
if (field != null)
473473
return field;
474474

475475
field = new Field(cPtr, false);
476-
fields.put(new Long(cPtr), field);
476+
fields.put(Long.valueOf(cPtr), field);
477477
return field;
478478
}
479479
%}
@@ -727,12 +727,12 @@ namespace webots {
727727
if (cPtr == 0)
728728
return null;
729729

730-
Node node = nodes.get(new Long(cPtr));
730+
Node node = nodes.get(Long.valueOf(cPtr));
731731
if (node != null)
732732
return node;
733733

734734
node = new Node(cPtr, false);
735-
nodes.put(new Long(cPtr), node);
735+
nodes.put(Long.valueOf(cPtr), node);
736736
return node;
737737
}
738738
%}
@@ -810,12 +810,12 @@ namespace webots {
810810
if (cPtr == 0)
811811
return null;
812812

813-
Proto proto = protos.get(new Long(cPtr));
813+
Proto proto = protos.get(Long.valueOf(cPtr));
814814
if (proto != null)
815815
return proto;
816816

817817
proto = new Proto(cPtr, false);
818-
protos.put(new Long(cPtr), proto);
818+
protos.put(Long.valueOf(cPtr), proto);
819819
return proto;
820820
}
821821
%}

src/controller/launcher/webots_controller.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ int main(int argc, char **argv) {
998998
new_argv = add_single_argument(new_argv, &current_size, "-classpath");
999999
new_argv = add_single_argument(new_argv, &current_size, classpath);
10001000
new_argv = add_single_argument(new_argv, &current_size, java_library);
1001+
new_argv = add_single_argument(new_argv, &current_size, "--enable-native-access=ALL-UNNAMED");
10011002
new_argv = add_single_argument(new_argv, &current_size, controller_name + 1);
10021003
new_argv = add_controller_arguments(new_argv, argv, &current_size, false);
10031004
new_argv = add_single_argument(new_argv, &current_size, NULL);

src/webots/control/WbLanguageTools.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ const QString &WbLanguageTools::javaCommand() {
5353
}
5454

5555
const QStringList WbLanguageTools::javaArguments() {
56+
QStringList arguments;
5657
#ifdef __APPLE__
5758
// In order to run the robot window on the gui thread (thread 0)
5859
// which is a requirement of Qt, this option is required
59-
return QStringList("-XstartOnFirstThread");
60-
#else
61-
return QStringList();
60+
arguments << "-XstartOnFirstThread";
6261
#endif
62+
// Allow JNI native access without warnings (Java 22+)
63+
arguments << "--enable-native-access=ALL-UNNAMED";
64+
return arguments;
6365
}
6466

6567
QString WbLanguageTools::pythonCommand(QString &shortVersion, const QString &command, QProcessEnvironment &env) {

0 commit comments

Comments
 (0)