microsoft / vscode-java-debug

Java Debugger for Visual Studio Code.
Other
531 stars 339 forks source link

Running Java via launch config is Enhancing my logger with Mokito #326

Closed iamlothian closed 6 years ago

iamlothian commented 6 years ago

The configuration of my logging classes seems to be affected by running the application via vscode launch configuration.

I as asking here as my assumption is vscode java debug might be wrapping application logging so that it can capture output and forward it to the nominated console

Environment
Steps To Reproduce

The Spring Boot project that I am working on has a logger that extends SL4J to add some extra formatting features.

If I run the jar via the command line with -jar it all runs fine, and i can even attach the debugger to it. If i run the application via the launch config then get a cast exception on startup

com.xxx.logging.XLogger$$EnhancerByMockitoWithCGLIB$$a7cd3f10 cannot be cast to com.xxx.logging.XLoggerImpl

XLoggerImpl extends XLogger and is configured and returned by a bean

@Bean
public XLogger xLogger(
    LoggingProperties loggingProperties,
    RequestBasedExecutionContextHolder requestBasedExecutionContextHolder
) {
    return new XLoggerImpl(loggingProperties, requestBasedExecutionContextHolder);
}
@Autowired
public void setXLogger(XLogger xLogger) {
    this.xLogger = (XLoggerImpl)xLogger;
}
Current Result

com.xxx.logging.XLogger$$EnhancerByMockitoWithCGLIB$$a7cd3f10 cannot be cast to com.xxx.logging.XLoggerImpl

Expected Result

No cast exception

Additional Informations
andxu commented 6 years ago

Could you start the launch mode again with the console option "externalTerminal", like image and copy the command line shown at the terminal, remove the debug options like: -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:???? and try to launch it in the terminal(system terminal not vscode) and check whether the "cannot be cast to" is gone?

image

image

iamlothian commented 6 years ago

I have tried with all console types and got the same result. I can run the app using: agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:1044 and connect to it using the attach config with no issues from both the internal and external terminals

Note:Redaction applied

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug (Launch)-RunApplication<xxx-svc>",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "console": "externalTerminal",
            "stopOnEntry": true,
            "mainClass": "com.xxx.RunApplication",
            "projectName": "xxx-svc",
            "args": "",
            "env": {
                "X_LOGGER_LEVEL":"INFO",
                "SPRING_PROFILES_ACTIVE": "local,mock-eventEmitter,local-issuers,mock-security-redis"
            }
        },
        {
            "type": "java",
            "name": "Debug (Attach)",
            "request": "attach",
            "hostName": "localhost",
            "port": 1044,
            "projectName": "xxx-svc",
        }
    ]
}

The generated run script seems to be quite large, let me see if i can pull out anything useful.

cd
'/Users/x/i-co/x-x/digital-x-security-tokensinternal';
env
'x_LOGGER_LEVEL=INFO'
'INTERNAL-TOKEN-PRIVATE-KEY=123'
'APPLICATION-INSIGHTS-IKEY=x'
'SPRING_PROFILES_ACTIVE=local,mock-eventEmitter,local-issuers,mock-security-redis'
'/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/bin/java'
'-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:53027'
'-Dfile.encoding=UTF-8'
'-cp'
'/Users/x/i-co/x-x/digital-x-security-tokensinternal/target/
classes:/Users/x/i-co/x-x/digital-x-security-tokensinternal/target/
classes:/Users/x/i-co/x-x/digital-x-security-tokensinternal/target/
classes:/Users/x/i-co/x-x/digital-x-security-tokensinternal/target/test-
classes:/Users/x/i-co/x-x/digital-x-security-tokensinternal/target/test-
classes:/Users/x/i-co/x-x/digital-x-security-tokensinternal/target/
classes:/Users/x/i-co/x-x/digital-x-security-tokensinternal/target/test-
classes:/Users/x/i-co/x-x/digital-x-starter/digital-x-autoconfigure/target/
classes:/Users/x/i-co/x-x/digital-x-starter/digital-x-autoconfigure/target/test-
classes:/Users/x/i-co/x-x/digital-x-starter/digital-x-circuit-breaker/target/
classes:/Users/x/i-co/x-x/digital-x-starter/digital-x-circuit-breaker/target/test-
classes:/Users/x/i-co/x-x/digital-x-starter/digital-x-core/target/
classes:/Users/x/i-co/x-x/digital-x-starter/digital-x-core/target/test-
classes:/Users/x/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.5.8.RELEASE/spring-boot-starter-web-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot-starter/1.5.8.RELEASE/spring-boot-starter-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/org/yaml/snakeyaml/1.17/snakeyaml-1.17.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/1.5.8.RELEASE/spring-boot-starter-tomcat-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.23/tomcat-embed-core-8.5.23.
jar:/Users/x/.m2/repository/org/apache/tomcat/tomcat-annotations-api/8.5.23/tomcat-annotations-api-8.5.23.
jar:/Users/x/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/8.5.23/tomcat-embed-el-8.5.23.
jar:/Users/x/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/8.5.23/tomcat-embed-websocket-8.5.23.
jar:/Users/x/.m2/repository/org/hibernate/hibernate-validator/5.3.5.Final/hibernate-validator-5.3.5.Final.
jar:/Users/x/.m2/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.
jar:/Users/x/.m2/repository/org/jboss/logging/jboss-logging/3.3.1.Final/jboss-logging-3.3.1.Final.
jar:/Users/x/.m2/repository/com/fasterxml/classmate/1.3.4/classmate-1.3.4.
jar:/Users/x/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.8.9/jackson-databind-2.8.9.
jar:/Users/x/.m2/repository/org/springframework/spring-web/4.3.12.RELEASE/spring-web-4.3.12.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/spring-beans/4.3.12.RELEASE/spring-beans-4.3.12.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/spring-webmvc/4.3.12.RELEASE/spring-webmvc-4.3.12.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/spring-expression/4.3.12.RELEASE/spring-expression-4.3.12.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot-starter-aop/1.5.8.RELEASE/spring-boot-starter-aop-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/spring-aop/4.3.12.RELEASE/spring-aop-4.3.12.RELEASE.
jar:/Users/x/.m2/repository/org/aspectj/aspectjweaver/1.8.11/aspectjweaver-1.8.11.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.5.8.RELEASE/spring-boot-starter-logging-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.
jar:/Users/x/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.25/jcl-over-slf4j-1.7.25.
jar:/Users/x/.m2/repository/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.
jar:/Users/x/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.25/log4j-over-slf4j-1.7.25.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot-starter-actuator/1.5.8.RELEASE/spring-boot-starter-actuator-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot-actuator/1.5.8.RELEASE/spring-boot-actuator-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot-starter-test/1.5.8.RELEASE/spring-boot-starter-test-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot-test/1.5.8.RELEASE/spring-boot-test-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot-test-autoconfigure/1.5.8.RELEASE/spring-boot-test-autoconfigure-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/com/jayway/jsonpath/json-path/2.2.0/json-path-2.2.0.
jar:/Users/x/.m2/repository/junit/junit/4.12/junit-4.12.
jar:/Users/x/.m2/repository/org/assertj/assertj-core/1.7.1/assertj-core-1.7.1.
jar:/Users/x/.m2/repository/org/mockito/mockito-core/1.10.19/mockito-core-1.10.19.
jar:/Users/x/.m2/repository/org/objenesis/objenesis/2.1/objenesis-2.1.
jar:/Users/x/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.
jar:/Users/x/.m2/repository/org/hamcrest/hamcrest-library/1.3/hamcrest-library-1.3.
jar:/Users/x/.m2/repository/org/skyscreamer/jsonassert/1.4.0/jsonassert-1.4.0.
jar:/Users/x/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.
jar:/Users/x/.m2/repository/org/springframework/spring-core/4.3.12.RELEASE/spring-core-4.3.12.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/spring-test/4.3.12.RELEASE/spring-test-4.3.12.RELEASE.
jar:/Users/x/.m2/repository/org/apache/commons/commons-lang3/3.6/commons-lang3-3.6.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot-devtools/1.5.8.RELEASE/spring-boot-devtools-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot/1.5.8.RELEASE/spring-boot-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.5.8.RELEASE/spring-boot-autoconfigure-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/com/nimbusds/nimbus-jose-jwt/5.9/nimbus-jose-jwt-5.9.
jar:/Users/x/.m2/repository/com/github/stephenc/jcip/jcip-annotations/1.0-1/jcip-annotations-1.0-1.
jar:/Users/x/.m2/repository/net/minidev/json-smart/2.3/json-smart-2.3.
jar:/Users/x/.m2/repository/net/minidev/accessors-smart/1.2/accessors-smart-1.2.
jar:/Users/x/.m2/repository/org/ow2/asm/asm/5.0.4/asm-5.0.4.
jar:/Users/x/.m2/repository/redis/clients/jedis/2.9.0/jedis-2.9.0.
jar:/Users/x/.m2/repository/org/apache/commons/commons-pool2/2.4.2/commons-pool2-2.4.2.
jar:/Users/x/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.8.9/jackson-datatype-jsr310-2.8.9.
jar:/Users/x/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.8.9/jackson-annotations-2.8.9.
jar:/Users/x/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.9/jackson-core-2.8.9.
jar:/Users/x/.m2/repository/org/projectlombok/lombok/1.16.18/lombok-1.16.18.
jar:/Users/x/.m2/repository/com/github/java-json-tools/json-schema-validator/2.2.8/json-schema-validator-2.2.8.
jar:/Users/x/.m2/repository/com/github/java-json-tools/json-schema-core/1.2.8/json-schema-core-1.2.8.
jar:/Users/x/.m2/repository/org/mozilla/rhino/1.7R4/rhino-1.7R4.
jar:/Users/x/.m2/repository/com/github/fge/jackson-coreutils/1.8/jackson-coreutils-1.8.
jar:/Users/x/.m2/repository/com/github/fge/msg-simple/1.1/msg-simple-1.1.
jar:/Users/x/.m2/repository/com/github/fge/btf/1.2/btf-1.2.
jar:/Users/x/.m2/repository/com/google/guava/guava/16.0.1/guava-16.0.1.
jar:/Users/x/.m2/repository/com/github/fge/uri-template/0.9/uri-template-0.9.
jar:/Users/x/.m2/repository/javax/mail/mailapi/1.4.3/mailapi-1.4.3.
jar:/Users/x/.m2/repository/javax/activation/activation/1.1/activation-1.1.
jar:/Users/x/.m2/repository/joda-time/joda-time/2.9.9/joda-time-2.9.9.
jar:/Users/x/.m2/repository/com/googlecode/libphonenumber/libphonenumber/8.0.0/libphonenumber-8.0.0.
jar:/Users/x/.m2/repository/com/google/code/findbugs/jsr305/3.0.1/jsr305-3.0.1.
jar:/Users/x/.m2/repository/net/sf/jopt-simple/jopt-simple/5.0.3/jopt-simple-5.0.3.
jar:/Users/x/.m2/repository/org/apache/kafka/kafka-clients/1.0.0/kafka-clients-1.0.0.
jar:/Users/x/.m2/repository/org/lz4/lz4-java/1.4/lz4-java-1.4.
jar:/Users/x/.m2/repository/org/xerial/snappy/snappy-java/1.1.4/snappy-java-1.1.4.
jar:/Users/x/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.
jar:/Users/x/.m2/repository/org/springframework/kafka/spring-kafka/2.1.4.RELEASE/spring-kafka-2.1.4.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/spring-context/4.3.12.RELEASE/spring-context-4.3.12.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/spring-messaging/4.3.12.RELEASE/spring-messaging-4.3.12.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/spring-tx/4.3.12.RELEASE/spring-tx-4.3.12.RELEASE.
jar:/Users/x/.m2/repository/org/springframework/retry/spring-retry/1.2.1.RELEASE/spring-retry-1.2.1.RELEASE.
jar:/Users/x/.m2/repository/com/microsoft/azure/azure-storage/5.0.0/azure-storage-5.0.0.
jar:/Users/x/.m2/repository/com/microsoft/azure/azure-keyvault-core/0.8.0/azure-keyvault-core-0.8.0.
jar:/Users/x/.m2/repository/commons-codec/commons-codec/1.10/commons-codec-1.10.
jar:/Users/x/.m2/repository/com/microsoft/azure/applicationinsights-spring-boot-starter/1.0.0-BETA/applicationinsights-spring-boot-starter-1.0.0-BETA.
jar:/Users/x/.m2/repository/com/microsoft/azure/applicationinsights-core/2.1.1/applicationinsights-core-2.1.1.
jar:/Users/x/.m2/repository/com/microsoft/azure/applicationinsights-web/2.1.1/applicationinsights-web-2.1.1.
jar:/Users/x/.m2/repository/com/microsoft/azure/applicationinsights-logging-logback/2.1.1/applicationinsights-logging-logback-2.1.1.
jar:/Users/x/.m2/repository/ch/qos/logback/logback-core/1.1.11/logback-core-1.1.11.
jar:/Users/x/.m2/repository/org/springframework/kafka/spring-kafka/1.1.7.RELEASE/spring-kafka-1.1.7.RELEASE.
jar:/Users/x/i-co/x-x/digital-x-starter/digital-x-security/target/
classes:/Users/x/i-co/x-x/digital-x-starter/digital-x-security/target/test-
classes:/Users/x/i-co/x-x/digital-x-starter/digital-x-validation/target/
classes:/Users/x/i-co/x-x/digital-x-starter/digital-x-validation/target/test-
classes:/Users/x/i-co/x-x/digital-x-starter/digital-x-events/target/
classes:/Users/x/i-co/x-x/digital-x-starter/digital-x-events/target/test-
classes:/Users/x/.m2/repository/net/minidev/json-smart/2.2.1/json-smart-2.2.1.
jar:/Users/x/.m2/repository/net/minidev/accessors-smart/1.1/accessors-smart-1.1.
jar:/Users/x/.m2/repository/org/ow2/asm/asm/5.0.3/asm-5.0.3.
jar:/Users/x/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.
jar:/Users/x/.m2/repository/org/projectlombok/lombok/1.16.20/lombok-1.16.20.
jar:/Users/x/.m2/repository/com/microsoft/azure/azure-keyvault-secrets-spring-boot-starter/0.2.3/azure-keyvault-secrets-spring-boot-starter-0.2.3.
jar:/Users/x/.m2/repository/com/microsoft/azure/azure-spring-boot-starter/0.2.3/azure-spring-boot-starter-0.2.3.
jar:/Users/x/.m2/repository/org/springframework/boot/spring-boot-starter-validation/1.5.8.RELEASE/spring-boot-starter-validation-1.5.8.RELEASE.
jar:/Users/x/.m2/repository/com/microsoft/azure/azure-spring-boot/0.2.3/azure-spring-boot-0.2.3.
jar:/Users/x/.m2/repository/com/google/code/findbugs/annotations/2.0.1/annotations-2.0.1.
jar:/Users/x/.m2/repository/org/json/json/20140107/json-20140107.
jar:/Users/x/.m2/repository/com/microsoft/azure/azure-keyvault/1.0.0/azure-keyvault-1.0.0.
jar:/Users/x/.m2/repository/com/microsoft/azure/azure-client-runtime/1.0.0/azure-client-runtime-1.0.0.
jar:/Users/x/.m2/repository/com/microsoft/rest/client-runtime/1.0.0/client-runtime-1.0.0.
jar:/Users/x/.m2/repository/com/squareup/retrofit2/retrofit/2.1.0/retrofit-2.1.0.
jar:/Users/x/.m2/repository/com/squareup/okhttp3/okhttp/3.3.1/okhttp-3.3.1.
jar:/Users/x/.m2/repository/com/squareup/okio/okio/1.8.0/okio-1.8.0.
jar:/Users/x/.m2/repository/com/squareup/okhttp3/logging-interceptor/3.3.1/logging-interceptor-3.3.1.
jar:/Users/x/.m2/repository/com/squareup/okhttp3/okhttp-urlconnection/3.3.1/okhttp-urlconnection-3.3.1.
jar:/Users/x/.m2/repository/com/squareup/retrofit2/converter-jackson/2.1.0/converter-jackson-2.1.0.
jar:/Users/x/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-joda/2.8.10/jackson-datatype-joda-2.8.10.
jar:/Users/x/.m2/repository/io/reactivex/rxjava/1.2.4/rxjava-1.2.4.
jar:/Users/x/.m2/repository/com/squareup/retrofit2/adapter-rxjava/2.1.0/adapter-rxjava-2.1.0.
jar:/Users/x/.m2/repository/com/microsoft/azure/azure-keyvault-webkey/1.0.0/azure-keyvault-webkey-1.0.0.
jar:/Users/x/.m2/repository/com/google/guava/guava/20.0/guava-20.0.
jar:/Users/x/.m2/repository/com/microsoft/azure/adal4j/1.3.0/adal4j-1.3.0.
jar:/Users/x/.m2/repository/com/nimbusds/oauth2-oidc-sdk/5.24.1/oauth2-oidc-sdk-5.24.1.
jar:/Users/x/.m2/repository/javax/mail/mail/1.4.7/mail-1.4.7.
jar:/Users/x/.m2/repository/org/apache/commons/commons-collections4/4.1/commons-collections4-4.1.
jar:/Users/x/.m2/repository/com/nimbusds/lang-tag/1.4.3/lang-tag-1.4.3.
jar:/Users/x/.m2/repository/com/google/code/gson/gson/2.8.2/gson-2.8.2.jar'
'com.xxx.RunApplication'
andxu commented 6 years ago

Remove that line -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:53027 and try to launch it in system terminal.

iamlothian commented 6 years ago

I have had mixed results since I last commented, where it will work sometimes, and not others. Which is rather unhelpful when trying to replicate and diagnose the issue.

andxu commented 6 years ago

Would you mind to upload your project here, in this way I can try your project to figure out what's the problem?

iamlothian commented 6 years ago

That will not be possible sorry. If i find some time this weekend. Ill try make a small project to reproduce the issue.

On Fri., 6 Jul. 2018, 12:55 pm Andy Xu(devdiv), notifications@github.com wrote:

Would you mind to upload your project here, in this way I can try your project to figure out what's the problem?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode-java-debug/issues/326#issuecomment-402910751, or mute the thread https://github.com/notifications/unsubscribe-auth/AEw1M_i_xnrElLs2MOMsoia0V1xMoAUbks5uDtGogaJpZM4VB1U5 .

no-response[bot] commented 6 years ago

This issue has been closed automatically because it needs more information and has not had recent activity. Please reach out if you have or find the answers we need so that we can investigate further.