Skip to content

Commit

Permalink
[FIXED JENKINS-37820] Stack overflow for classes which were their own…
Browse files Browse the repository at this point in the history
… descriptors, common for global configuration.
  • Loading branch information
jglick committed Aug 30, 2016
1 parent c681aef commit 284e11b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
Expand Up @@ -14,7 +14,6 @@
import javax.inject.Inject;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -185,7 +184,7 @@ public static SymbolLookup get() {
justification = "Jenkins.getInstance() can return null in theory.")
@Nonnull public static Set<String> getSymbolValue(@Nonnull Class<?> c) {
Set<String> symbolValues = new LinkedHashSet<String>();
if (Describable.class.isAssignableFrom(c) && Jenkins.getInstance() != null) {
if (Describable.class.isAssignableFrom(c) && !Descriptor.class.isAssignableFrom(c) && Jenkins.getInstance() != null) {
Descriptor d = Jenkins.getInstance().getDescriptor(c.asSubclass(Describable.class));
symbolValues.addAll(getSymbolValue(d));
} else {
Expand Down
@@ -1,25 +1,20 @@
package org.jenkinsci.plugins.structs;

import hudson.model.Descriptor;
import java.util.Collections;
import java.util.Set;
import javax.inject.Inject;
import jenkins.model.GlobalConfiguration;
import static org.hamcrest.CoreMatchers.*;
import org.jenkinsci.Symbol;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;

import javax.inject.Inject;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

/**
* @author Kohsuke Kawaguchi
*/
public class SymbolLookupTest {
@TestExtension @Symbol("foo")
public static class Foo {}
Expand Down Expand Up @@ -90,4 +85,15 @@ public void symbolValueFromClass() {
assertEquals(netSet, SymbolLookup.getSymbolValue(FishingNet.DescriptorImpl.class));
assertEquals(fooSet, SymbolLookup.getSymbolValue(Foo.class));
}

@Issue("JENKINS-37820")
@Test
public void descriptorIsDescribable() {
assertEquals(Collections.singleton("whatever"), SymbolLookup.getSymbolValue(SomeConfiguration.class));
assertEquals(Collections.singleton("whatever"), SymbolLookup.getSymbolValue(rule.jenkins.getDescriptorByType(SomeConfiguration.class)));
}
@TestExtension("descriptorIsDescribable")
@Symbol("whatever")
public static class SomeConfiguration extends GlobalConfiguration {}

}
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -4,8 +4,8 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.12</version>
<relativePath />
<version>2.14</version>
<relativePath/>
</parent>

<groupId>org.jenkins-ci.plugins</groupId>
Expand Down

0 comments on commit 284e11b

Please sign in to comment.