Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4380
Closed
Open
Issue created Nov 05, 2019 by Administrator@rootContributor

[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:

https://github.com/OpenAPITools/openapi-generator/blob/45fcf3792af0af4d18494324fa969d4edcd328d7/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/AnotherFakeApi.java#L102

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

See the repo: https://github.com/OpenAPITools/openapi-generator/blob/45fcf3792af0af4d18494324fa969d4edcd328d7/samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/AnotherFakeApi.java#L102

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);
    }
Assignee
Assign to
Time tracking