Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Jonaythaz
Copy link
Contributor

@Jonaythaz Jonaythaz commented Jul 1, 2024

Pull request for the new Jolie2Java, the changes made, outside of the jolie2java module, are:

  • Updated the jolie module to use Java21
  • Added files used by the classes generated by Jolie2Java to the jolie module (In the jolie.runtime.embedding.java package)
  • Updated the Dockerfiles of the .devcontainer and docker folders to use the Java 21 version of their images
  • Updated the jolie2java executables in the launchers folder to include the dependencies of the new Jolie2Java tool

Jonaythaz and others added 19 commits June 13, 2024 14:22
…ion, updated the launchers for jolie2java to include the dependencies of the new implementation, and updated the Dockerfile in .devcontainer to use the newest version of its image such that it includes Java 21.
…rall type hierarchy imposed by the tool. Also fixed bug related to having a choice type in a field and added unit tests to cover those cases.
…e, added examples of using the new jolie2java tool to a new javaServices/newJavaservices module, and fixed a minor bug regarding faults storing choice types.
Updated some inconsistencies with the wording in the README of jolie2java
…ations, improved the readability of unit test files, moved embedding files to the jolie module, updated jolie module to use java21, and updated jolie2java's README file.
…ection, and updated the generated equals() methods to respect structural equivalence.
…r JolieValue, improved unit tests to cover more cases, and made various minor improvements and fixes.
…ed checks to ensure inner class names do not hide outer class names, made linked types use their qualified names such that they can't conflict with inner classes, and made some improvements to the Builder generated for Structures.
… added unit tests to cover this case, improved the way refinements are handled, improved flexibility of placing generated files, and made other minor fixes and updates.
…ses is used in the generated classes, and made adjusments to how refinements are validated.
…y JavaServices, added support for JolieValue in JavaService's Embedder class, removed newJavaServices in preparation for pull request, and made minor improvements and fixes.
…ifically target services, interfaces, or types, and removed now unnecessary flags to simplify usage.
…w many exceptions they throw, made it so JavaService also searches for the @requestresponse annotation in inherited interfaces, and updated how services and interfaces are generated accordingly.
@fmontesi
Copy link
Member

fmontesi commented Jul 1, 2024

Please rebase and let's try the CI again. I put Java 21 in the CI on master, it might help. :-)

Copy link
Contributor

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@Jonaythaz
Copy link
Contributor Author

Jonaythaz commented Jul 1, 2024

@fmontesi there seems to have been made a change to the hashCode method of the Value class that makes it loop indefintely, which causes StackOverflow when trying to run the jolie2java tests. I believe it is because the line Objects.requireNonNullElse( valueObject(), UNDEFINED_VALUE ).hashCode() is causing the hashCode method of UNDEFINED_VALUE to be called recursively.

@Jonaythaz
Copy link
Contributor Author

@fmontesi I refactored the tests such that they do not call hashCode on the Value class, if you want I can open an issue about the infinite looping, but now the JavaDoc goal throws an error because I use the tags @apiNote, @implNote, and @implSpec, which apparently aren't standard tags, would you prefer I change the tags to something else or should I just add them as custom tags in the maven-javadoc-plugin?

@fmontesi
Copy link
Member

fmontesi commented Jul 3, 2024

@Jonaythaz Yes please open an issue for that. @mwallnoefer Perhaps this is caused by the recent patches you made about hashCode for Value? (If I remember correctly, I haven't checked.)

Regarding the javadoc tags, can you point me to an example? Is it in your own code or code that you generate from jolie2java?

@Jonaythaz
Copy link
Contributor Author

Jonaythaz commented Jul 3, 2024

@Jonaythaz Yes please open an issue for that. @mwallnoefer Perhaps this is caused by the recent patches you made about hashCode for Value? (If I remember correctly, I haven't checked.)

Regarding the javadoc tags, can you point me to an example? Is it in your own code or code that you generate from jolie2java?

I use the tags in some of the classes in the Jolie module that are used by the generated classes, e.g. in the documentation string for JolieNative I used @apiNote for the section where I explain how to use an enhanced switch expression to access its data. Another example is using @implSpec in JolieValue to document methods that are just shorthands for using a combination of different methods.

These tags are used in the documentation for the Java standard library, although I can't think of an example off the top of my head, so I don't think it's a problem to just add them, but since they aren't standard I figured I shouldn't do it without asking.

@mwallnoefer
Copy link
Member

@Jonaythaz maybe keep a look for not introducing new CodeQL warnings. I have tried very hard to reduce them to an absolute minimum over the last few months

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Regarding to the hashCode()refactoring it is a pity, I have tried very hard comply with CodeQL to not break anything. Of course feel free to propose some patch if you see some better solution, here is my commit: c1e90f7

. @mwallnoefer Perhaps this is caused by the recent patches you made about hashCode for Value? (If I remember correctly, I haven't checked.)

@mwallnoefer
Copy link
Member

Maybe something like this could fix it?


	@Override
	public int hashCode() {
		return isLink() || !isDefined() ? super.hashCode()
			: valueObject().hashCode();
	}

@Jonaythaz
Copy link
Contributor Author

Jonaythaz commented Jul 3, 2024

Maybe something like this could fix it?


	@Override
	public int hashCode() {
		return isLink() || !isDefined() ? super.hashCode()
			: valueObject().hashCode();
	}

At the very least this doesn't cause loops with any of the instances of Value I use in the jolie2java tests, although when testing it the hashcodes were different despite the instances containing the same data, is that intentional?

@Jonaythaz maybe keep a look for not introducing new CodeQL warnings. I have tried very hard to reduce them to an absolute minimum over the last few months

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Regarding to the hashCode()refactoring it is a pity, I have tried very hard comply with CodeQL to not break anything. Of course feel free to propose some patch if you see some better solution, here is my commit: c1e90f7

. @mwallnoefer Perhaps this is caused by the recent patches you made about hashCode for Value? (If I remember correctly, I haven't checked.)

I have some new changes that addresses most of the CodeQL complaints, just waiting for the verdict on the tags before pushing them. Annoyingly CodeQL warns you about unused variable in a switch expression, even though you can't use anonymous variables, i.e. _ instead of a variable name, until Java 22.

@mwallnoefer
Copy link
Member

Maybe something like this could fix it?


	@Override
	public int hashCode() {
		return isLink() || !isDefined() ? super.hashCode()
			: valueObject().hashCode();
	}

At the very least this doesn't cause loops with any of the instances of Value I use in the jolie2java tests, although when testing it the hashcodes were different despite the instances containing the same data, is that intentional?

Before there was no hashCode() implementation at all, so yes I think so.

@fmontesi What do you think, given the importance of a correct hashCode() implementation which should not end up in a stack recursion overflow, should we apply my patch and roll out a v12.1.0 bug-fix release?
Nevertheless strange that the situation was not covered by the unit tests.

@fmontesi
Copy link
Member

fmontesi commented Jul 6, 2024

Yes, good idea. Please apply it to both master and release/1.12, I'll make a patch release for 1.12.1.

@fmontesi
Copy link
Member

fmontesi commented Jul 6, 2024

Would also be good to add a test for this here: https://github.com/jolie/jolie/blob/master/jolie/src/test/java/interpreter/ValueTests.java

@fmontesi
Copy link
Member

fmontesi commented Jul 7, 2024

Thanks @mwallnoefer!

@Jonaythaz, please rebase once again and let's retry. :-)

@Jonaythaz
Copy link
Contributor Author

@Jonaythaz, please rebase once again and let's retry. :-)

@fmontesi before rebasing, what is the verdict on the non-standard tags, add them to the JavaDoc plugin or replace them with a different tag?

@fmontesi
Copy link
Member

fmontesi commented Jul 8, 2024

Oh, right, about the tags: as long as we don't force users of Jolie and our tools to have custom javadoc configurations, they're fine!
So, if I understand correctly, having them in our own source code in the jolie repository should be fine. But we shouldn't use them in comments of code generated by jolie2java, otherwise users will need to know about this in order to run javadoc and I suspect most will just get surprised that the toolchain is 'broken'.

Makes sense?


private void appendMethods( Definition d ) {
builder.newline()
.newlineAppend( "public " ).append( switch ( d ) { case Basic b -> b.type().wrapperType(); case Structure s -> s.contentType().wrapperType(); case Choice c -> ClassPath.JOLIENATIVE.parameterized( "?" ); } ).append( " content() { return option.content(); }" )

Check notice

Code scanning / CodeQL

Unread local variable

Variable 'Choice c' is never read.
final String getField = "t." + f.javaName() + "()";
final UnaryOperator<String> setValue = x -> switch ( storedType( f.type() ) ) {
case Native n when n == Native.ANY || n == Native.VOID -> ".setValue( " + x + ".value() )";
case Native n -> ".setValue( " + x + " )";

Check notice

Code scanning / CodeQL

Unread local variable

Variable 'Native n' is never read.
return switch ( request() ) {
case Native.VOID -> Optional.empty();
case Native n -> Optional.of( n.nativeType() );
case Undefined d -> Optional.of( ClassPath.JOLIEVALUE.get() );

Check notice

Code scanning / CodeQL

Unread local variable

Variable 'Undefined d' is never read.
return switch( response() ) {
case Native.VOID -> "void";
case Native n -> n.nativeType();
case Undefined d -> ClassPath.JOLIEVALUE.get();

Check notice

Code scanning / CodeQL

Unread local variable

Variable 'Undefined d' is never read.
private JolieType parse( TypeDefinition typeDefinition, NameSupplier nameSupplier, boolean isInner ) {
return switch ( typeDefinition ) {

case TypeDefinitionUndefined ud -> Undefined.getInstance();

Check notice

Code scanning / CodeQL

Unread local variable

Variable 'TypeDefinitionUndefined ud' is never read.
@Override
public String toString() { return ""; }

public static JolieVoid from( JolieValue j ) { return new JolieVoid(); }

Check notice

Code scanning / CodeQL

Useless parameter

The parameter 'j' is never used.
qualifiedName( s ) + ".builder()" );
}

private void appendExtraSetters( String fieldName, Choice c ) {

Check notice

Code scanning / CodeQL

Useless parameter

The parameter 'fieldName' is never used.
qualifiedName( s ) + ".builder()" );
}

private void appendExtraSetters( String fieldName, Choice c ) {

Check notice

Code scanning / CodeQL

Useless parameter

The parameter 'c' is never used.
@Jonaythaz
Copy link
Contributor Author

Oh, right, about the tags: as long as we don't force users of Jolie and our tools to have custom javadoc configurations, they're fine! So, if I understand correctly, having them in our own source code in the jolie repository should be fine. But we shouldn't use them in comments of code generated by jolie2java, otherwise users will need to know about this in order to run javadoc and I suspect most will just get surprised that the toolchain is 'broken'.

The only tags used in the generated files is @see so that shouldn't be a problem. While adding the tags it turns out that the plugin doesn't allow the tags I used as custom tags because "they could be overridden by future standard tags", so I had to prefix them with custom., but this can pretty easily be changed back if those tags ever actually get added as standard tags.

@fmontesi fmontesi merged commit bb1868b into jolie:master Jul 11, 2024
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

Successfully merging this pull request may close these issues.

3 participants