-
Notifications
You must be signed in to change notification settings - Fork 194
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
Groovy: compiler error: exception in phase 'semantic analysis' in source unit 'xxx.groovy' unexpected NullPointerException #1268
Comments
Would it be possible to isolate this error to a small piece of code? It has to do with an inner class somewhere, which could also be a closure or anonymous inner. I'm thinking it's an anon. inner because the stack trace has Also, what version of the Groovy Compiler are you running? |
I use Groovy Compiler 2.5.4 and spock-core version 1.3-groovy-2.5. package at.example
import at.example.service.logging.extractor.LogDataExtractor
import at.example.service.logging.extractor.MessageToLogDataConverter
import at.example.logging.UnicLogConstants
import at.example.logging.LogRecord
import org.apache.cxf.binding.soap.SoapMessage
import org.apache.cxf.message.ExchangeImpl
import org.apache.cxf.message.MessageImpl
import org.aspectj.lang.ProceedingJoinPoint
import org.joda.time.DateTimeUtils
import org.slf4j.MDC
import spock.lang.Specification
class LogDataExtractorTest extends Specification {
final def RELEASE_NUMBER = "5.18.x"
final def CURRENT_TIME = 4815162342L
final def TRANSACTION_ID = UUID.randomUUID().toString();
final def DEFAULT_MESSAGE_XML = "<request />"
final def SOAP_ACTION = "checkRequestedServices"
def soapMessage = setupMessage()
LogDataExtractor<Message, TestLogRecord> logDataExtractor = new LogDataExtractor<Message, TestLogRecord>(Message) {
@Override
protected MessageToLogDataConverter<Message, TestLogRecord> getConverter() {
return new MessageToLogDataConverter<Message, TestLogRecord>() {
@Override
TestLogRecord extractLogDataFromMessage(String messageXml, Message convertedMessage, ProceedingJoinPoint pjp) {
return new TestLogRecord()
}
}
}
}
def setup() {
logDataExtractor.releaseNumber = RELEASE_NUMBER
DateTimeUtils.setCurrentMillisFixed(CURRENT_TIME)
MDC.put(UnicLogConstants.TRANSACTION_ID, TRANSACTION_ID)
}
def "Throws ClassCastException if message does not correspond to the extractors type argument"() {
given:
InvalidMessage invalidUnmarshalledMessage = new InvalidMessage()
when:
logDataExtractor.extractLogRecord(DEFAULT_MESSAGE_XML, invalidUnmarshalledMessage, null)
then:
thrown(ClassCastException)
}
def "LogRecord contains release number"() {
given:
Message unmarshalledMessage = new Message()
when:
LogRecord logRecord = logDataExtractor.extractLogRecord(DEFAULT_MESSAGE_XML, unmarshalledMessage, null)
then:
logRecord.releaseNumber == RELEASE_NUMBER
}
def "LogRecord contains transactionId()"() {
given:
Message unmarshalledMessage = new Message()
when:
LogRecord logRecord = logDataExtractor.extractLogRecord(DEFAULT_MESSAGE_XML, unmarshalledMessage, null)
then:
logRecord.transactionId == TRANSACTION_ID
}
SoapMessage setupMessage() {
SoapMessage message = new SoapMessage(new MessageImpl(exchange: new ExchangeImpl()))
message.put("SOAPAction", SOAP_ACTION)
return message
}
private class Message {}
private class InvalidMessage {}
private class TestLogRecord extends at.example.logging.LogRecord {}
} |
The NPE happens when processing "new TestLogRecord()" within the LogDataExtractor AIC. You can work around this by making |
Hi! Changig the inner classes helped.
Thanks |
I have a fix building. The GROOVY-8104 fix introduced this NPE. |
In Eclipse 2021-03 and Eclipse Groovy Development Tools 4.2.0.v202106140218-e2103 i get this error
The text was updated successfully, but these errors were encountered: