Skip to content

Commit

Permalink
Resolve issue with introspection references referencing introspection…
Browse files Browse the repository at this point in the history
…s in other packages. Fixes #2596
  • Loading branch information
jameskleeh committed Jan 8, 2020
1 parent 77d64f1 commit 698f01f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ class Test {
context?.close()
}

void "test write bean introspection data for classes"() {
void "test write bean introspection data for class in another package"() {
given:
ApplicationContext context = buildContext('test.Test', '''
package test;
Expand All @@ -666,7 +666,7 @@ import javax.validation.constraints.*;
import java.util.*;
import io.micronaut.inject.visitor.beans.*;
@Introspected(classes=TestBean.class)
@Introspected(classes=OtherTestBean.class)
class Test {}
''')

Expand All @@ -676,7 +676,13 @@ class Test {}

then:"The reference is valid"
reference != null
reference.getBeanType() == TestBean
reference.getBeanType() == OtherTestBean

when:
reference.load()

then:
noExceptionThrown()

cleanup:
context?.close()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.micronaut.inject.visitor.beans;

public class OtherTestBean {
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class BeanIntrospectionWriter extends AbstractAnnotationMetadataWriter {
private int propertyIndex = 0;
private ParameterElement[] constructorArguments;
private final HashMap<String, GeneratorAdapter> loadTypeMethods = new HashMap<>();
private final boolean publicIntrospection;

/**
* Default constructor.
Expand All @@ -88,6 +89,7 @@ class BeanIntrospectionWriter extends AbstractAnnotationMetadataWriter {
this.introspectionName = computeIntrospectionName(className);
this.introspectionType = getTypeReference(introspectionName);
this.beanType = getTypeReference(className);
this.publicIntrospection = false;
}

/**
Expand All @@ -106,6 +108,7 @@ class BeanIntrospectionWriter extends AbstractAnnotationMetadataWriter {
this.introspectionName = computeIntrospectionName(className);
this.introspectionType = getTypeReference(introspectionName);
this.beanType = getTypeReference(className);
this.publicIntrospection = true;
}

/**
Expand Down Expand Up @@ -189,7 +192,11 @@ private void writeIntrospectionClass(ClassWriterOutputVisitor classWriterOutputV

try (OutputStream introspectionStream = classWriterOutputVisitor.visitClass(introspectionName)) {

startFinalClass(introspectionWriter, introspectionType.getInternalName(), superType);
if (publicIntrospection) {
startPublicFinalClass(introspectionWriter, introspectionType.getInternalName(), superType);
} else {
startFinalClass(introspectionWriter, introspectionType.getInternalName(), superType);
}
final GeneratorAdapter constructorWriter = startConstructor(introspectionWriter);

// writer the constructor
Expand Down

0 comments on commit 698f01f

Please sign in to comment.