[BUG] The interrupt() flag is not restored for the caught RuntimeException.
Created by: feliksik
Description
The generated ApiClient does not reset the interrupt flag with Thread.currentThread().interrupt()
E.g. see here:
One of the source(s) where this comes from: https://github.com/OpenAPITools/openapi-generator/blob/16ad66759b3d9ab42dc4eb852c6bc8929f2fb965/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache#L152-L152
I would expect the generated code to look like:
} catch (IOException){
throw new ApiException(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}
Otherwise, the caller has to check the thrown ApiException for the underlying type of Exception, and see whether it is instanceof InterruptedException
to properly clean up the Thread. I don't think this makes sense -- right?
openapi-generator version
See the link to the repo above; Also I reproduced it locally with the following mvn spec:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.0</version>
<executions>
<execution>
<id>Generate models</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>specs/api/api-v1.yml</inputSpec>
<generatorName>java</generatorName>
<groupId>my.api</groupId>
<artifactId>dto</artifactId>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<configOptions>
<modelPackage>my.dto</modelPackage>
<apiPackage>my.api</apiPackage>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java11</dateLibrary>
<library>native</library>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
OpenAPI declaration file content or url
(not relevant)
Command line used for generation
or the pom above.
Suggest a fix
All code generators should generate code that does reset the interrupt flag;
} catch (IOException){
throw new ApiException(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}