Skip to content

Commit 10b8309

Browse files
committed
NPE in IdeProcessingEnvImpl.replacePlaceholdersUsing() if Map entry has
no value #4640
1 parent 940c710 commit 10b8309

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/dispatch/IdeProcessingEnvImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public Map<String, String> getOptions() {
102102

103103
private Function<Entry<String, String>, String> replacePlaceholdersUsing(Map<String, String> commandLineOptions) {
104104
return option -> {
105-
String variable, replacement, optionValue = option.getValue();
105+
String variable, replacement, optionValue = option.getValue() == null ? "" : option.getValue();
106106
Matcher placeholder = Pattern.compile("%([^%]+)%").matcher(optionValue);
107107
if (placeholder.find() && (variable = placeholder.group(1)) != null
108108
&& (replacement = commandLineOptions.get(variable)) != null) {

org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/BuilderTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,25 @@ public void testBug341298() throws Throwable {
415415
fullBuild();
416416
assertTrue("Processor should be able to compile with passed options", Bug341298Processor.success());
417417
}
418+
public void testGHIssue4640() throws Throwable {
419+
ProcessorTestStatus.reset();
420+
IJavaProject project = createJavaProject(_projectName);
421+
IPath root = project.getProject().getFullPath().append("src");
422+
env.addClass(root, "test341298", "Annotated",
423+
"package test341298;\n" +
424+
"@Annotation public class Annotated {}"
425+
);
426+
env.addClass(root, "test341298", "Annotation",
427+
"package test341298;\n" +
428+
"public @interface Annotation {}"
429+
);
430+
AptConfig.addProcessorOption(project, "classpath", "%classpath%");
431+
AptConfig.addProcessorOption(project, "sourcepath", "%sourcepath%");
432+
AptConfig.addProcessorOption(project, "phase", null);
433+
AptConfig.setEnabled(project, true);
434+
fullBuild();
435+
assertTrue("Processor should be able to compile with passed options", Bug341298Processor.success());
436+
}
418437

419438
public void testBug539663() throws Throwable {
420439
if (!canRunJava9()) {

0 commit comments

Comments
 (0)