Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create CognitivePedestrian2D and HeterogeneousPedestrian2D if Alchemist is executed via jar #459

Closed
aPlacuzzi opened this issue Jun 26, 2020 · 23 comments
Assignees

Comments

@aPlacuzzi
Copy link
Contributor

Tested on

Environment

OS: Windows 10
Java: 11.0.2 (OpenJDK)
Alchemist: 9.3.0 and later until commit 9e92d2c

What happens

Launching a simple simulation via the jar file, with the following command:

java -jar alchemist-redist-9.3.0.jar -y configuration.yml

will fail with the following exception (short version):

Exception in thread "main" java.lang.IllegalStateException: java.lang.IllegalArgumentException: Cannot create it.unibo.alchemist.model.implementations.nodes.CognitivePedestrian2D with arguments [child:String, male:String]
	at it.unibo.alchemist.AlchemistRunner.launch(AlchemistRunner.java:188)
	at it.unibo.alchemist.Alchemist.main(Alchemist.java:143)
Caused by: java.lang.IllegalArgumentException: Cannot create it.unibo.alchemist.model.implementations.nodes.CognitivePedestrian2D with arguments [child:String, male:String]
	at org.danilopianini.jirf.FactoryImpl.lambda$null$6(FactoryImpl.java:57)
	at java.base/java.util.Optional.orElseThrow(Optional.java:408)
	at org.danilopianini.jirf.FactoryImpl.lambda$build$7(FactoryImpl.java:51)
	at java.base/java.util.Optional.orElseGet(Optional.java:369)
	at org.danilopianini.jirf.FactoryImpl.build(FactoryImpl.java:34)
	at it.unibo.alchemist.loader.YamlLoader$Builder.lambda$new$2(YamlLoader.java:811)
	at it.unibo.alchemist.loader.YamlLoader$BuilderConfiguration.lambda$build$0(YamlLoader.java:864)
	at it.unibo.alchemist.loader.YamlLoader$BuilderConfiguration.ifMap(YamlLoader.java:872)
	at it.unibo.alchemist.loader.YamlLoader$BuilderConfiguration.build(YamlLoader.java:850)
	at it.unibo.alchemist.loader.YamlLoader$Builder.build(YamlLoader.java:830)
	at it.unibo.alchemist.loader.YamlLoader.getWith(YamlLoader.java:555)
	at it.unibo.alchemist.AlchemistRunner.lambda$prepareSimulations$11(AlchemistRunner.java:295)
	at it.unibo.alchemist.AlchemistRunner.launch(AlchemistRunner.java:181)
	... 1 more

The complete stacktrace is in the file log.txt

The simulation file used is here configuration.yml.txt (there is the final extension .txt because Github doesn't allow YAML extension).

The same happens also with HeterogeneousPedestrian2D.

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

@paagamelo any hint?

@paagamelo
Copy link

This is the kind of error you get when you forget to put @JvmOverloads to a constructor with default parameters in Kotlin. It's strange because pedestrians' loading is tested.

Looking at the stack trace, it seems to me that the simulator is unable to use pedestrians' secondary constructors for some reason. It says:

Couldn't convert child from java.lang.String to it.unibo.alchemist.model.cognitiveagents.characteristics.individual.Age

Whilst there's a secondary constructor taking in a String instead of an Age.

@Placu95 Did you check that the issue was present in the commit previous to 9e92d2c? I can't see how upgrading spotbugs could solve it.

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

@Placu95 this bug smells. Why do you say that Github doesn't allow YAML? That's blatantly false, we got a ton of .yml files around.

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

@paagamelo well I'd have some problems converting "child" or "male" to an Age as well. @Placu95 is that exception full? I need to see all the Exceptions suppressed by JIRF

@aPlacuzzi
Copy link
Contributor Author

aPlacuzzi commented Jun 26, 2020

@paagamelo I tried with Alchemist at version 9.3.0, commits 9e92d2c and 1f70c89. The bug is present in all the versions.

@DanySK Github doesn't allow to attach YAML file in issue.

The file log.txt contains the complete stacktrace printed by the simulator.

I can add that if you run Alchemist via Gradle downloading it from maven, all work fine. (I tested this only with Alchemist v9.3.0)

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

@paagamelo can we add the source to the test suite and verify that the bug is reproducibile?

This constructor it.unibo.alchemist.model.implementations.nodes.CognitivePedestrian2D(it.unibo.alchemist.model.interfaces.environments.EuclideanPhysics2DEnvironment,org.apache.commons.math3.random.RandomGenerator,it.unibo.alchemist.model.cognitiveagents.characteristics.individual.Age,it.unibo.alchemist.model.cognitiveagents.characteristics.individual.Gender) fails as expected

Then this one: Suppressed: org.danilopianini.jirf.InstancingImpossibleException: Could not create an instance with public it.unibo.alchemist.model.implementations.nodes.CognitivePedestrian2D(it.unibo.alchemist.model.interfaces.environments.EuclideanPhysics2DEnvironment,org.apache.commons.math3.random.RandomGenerator,int,java.lang.String) also "fails correctly".

The system then tries it.unibo.alchemist.model.implementations.nodes.CognitivePedestrian2D(it.unibo.alchemist.model.interfaces.environments.EuclideanPhysics2DEnvironment,org.apache.commons.math3.random.RandomGenerator,java.lang.String,java.lang.String), and this should work, but fails

Caused by: java.lang.IllegalStateException: No BuiltInsLoader implementation was found. Please ensure that the META-INF/services/ is not stripped from your application and that the Java virtual machine is not running under a security manager

This is the problem

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

@Placu95 how do you get the jar? And: is this class included (use jar -tf)
https://github.com/JetBrains/kotlin/blob/master/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsLoader.kt

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

And also kotlin.reflect.jvm.internal.impl.serialization.deserialization.builtins.BuiltInsLoaderImpl

We maybe are stripping kotlin-reflect from the jar file. But it's very very strange

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

@Placu95 also please try to use the jar you're currently using + the kotlin.reflect 1.3.71 jar and launch the application with

java -cp alchemist-full.jar kotlin.reflect-1.3.71.jar it.unibo.alchemist.Alchemist <options>

@aPlacuzzi
Copy link
Contributor Author

@DanySK the jar contains the two classes.
I downloaded the jar here: https://github.com/AlchemistSimulator/Alchemist/releases/tag/9.3.0

@aPlacuzzi
Copy link
Contributor Author

@DanySK I tried also java -cp alchemist-full.jar kotlin.reflect-1.3.71.jar it.unibo.alchemist.Alchemist <options> and the bug is still present

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

No do not use Alchemist 9.3.0. Use the latest development version.

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

9.3.0 is no longer supported, unless the bug also affects the current development version. We need to release 10.0.0 asap

@paagamelo
Copy link

@Placu95 Ah sorry, I thought the bug disappeared in commit 9e92d2c.

@paagamelo can we add the source to the test suite and verify that the bug is reproducibile?

@DanySK We already test pedestrians' loading using that constructor, and everything works via Gradle. Or you meant adding a test launching the full jar?

@aPlacuzzi
Copy link
Contributor Author

@DanySK also alchemist-full-9.3.0-devyg+9e92d2cdc-all.jar contains the two classes.
I obtained the jar via the gradle task shadowJar.

java -cp "alchemist-full-9.3.0-devyg+9e92d2cdc-all.jar";kotlin.reflect-1.3.71.jar it.unibo.alchemist.Alchemist -y configuration.yml doesn't work.

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

Can you list the content of the META-INF/services folder in that jar?

@aPlacuzzi
Copy link
Contributor Author

the directory META-INF contains only the file MANIFEST.MF

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

what-the-fuck.
The file is in kotlin-reflect, and we need to pack it, so I'll change that. But it should work with the other command.
What is the content of META-INF/services in the kotlin-reflect jar you are using?

And is the command accurate? If so, you mistaken the reflect jar name (dash, not dot). Use the autocompletion!

@aPlacuzzi
Copy link
Contributor Author

Ok. I tried this java -cp "alchemist-full-9.3.0-devyg+9e92d2cdc-all.jar";kotlin-reflect-1.3.71.jar it.unibo.alchemist.Alchemist -y configuration.yml (with dash) and it works

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

YEAH!!!!
Then solution's easy... let me implement it

DanySK added a commit that referenced this issue Jun 26, 2020
@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

try with fc6172a and let me know @Placu95

@aPlacuzzi
Copy link
Contributor Author

It works

@DanySK
Copy link
Member

DanySK commented Jun 26, 2020

Closing

@DanySK DanySK closed this as completed Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants