-
-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: NullPointerException on CtTypeReferenceImpl.isGenerics (#3276)
- Loading branch information
1 parent
21de813
commit 904fb1e
Showing
3 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package spoon; | ||
|
||
import org.junit.Test; | ||
|
||
import spoon.processing.AbstractProcessor; | ||
import spoon.reflect.CtModel; | ||
import spoon.reflect.reference.CtTypeReference; | ||
|
||
/** | ||
* Issue3275 | ||
*/ | ||
public class Issue3275Test { | ||
// the following code reproduces the behavior from the issue | ||
@Test | ||
public void test() { | ||
CtModel model = new FluentLauncher().inputResource("src/test/resources/issue3275/BOMCostPrice.java") | ||
.noClasspath(true) | ||
.processor(new AbstractProcessor<CtTypeReference<?>>() { | ||
public void process(CtTypeReference<?> element) { | ||
System.out.println(element.isGenerics()); | ||
} | ||
}) | ||
.buildModel(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.eevolution.costing; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.stream.Stream; | ||
|
||
import com.google.common.base.Predicates; | ||
|
||
import de.metas.costing.CostAmount; | ||
import de.metas.costing.CostElementId; | ||
import de.metas.product.ProductId; | ||
import de.metas.util.GuavaCollectors; | ||
import de.metas.util.lang.RepoIdAware; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.Singular; | ||
import lombok.ToString; | ||
|
||
@ToString | ||
public class BOMCostPrice { | ||
public static BOMCostPrice empty(@NonNull final ProductId productId) { | ||
return builder().productId(productId).build(); | ||
} | ||
|
||
@Getter | ||
private final ProductId productId; | ||
private final HashMap<CostElementId, BOMCostElementPrice> pricesByElementId; | ||
|
||
@Builder | ||
private BOMCostPrice(@NonNull final ProductId productId, | ||
@NonNull @Singular final Collection<BOMCostElementPrice> costElementPrices) { | ||
this.productId = productId; | ||
pricesByElementId = costElementPrices.stream() | ||
.collect(GuavaCollectors.toHashMapByKey(BOMCostElementPrice::getCostElementId)); | ||
} | ||
|
||
public Stream<CostElementId> streamCostElementIds() { | ||
return pricesByElementId.keySet().stream(); | ||
} | ||
|
||
public BOMCostElementPrice getCostElementPriceOrNull(@NonNull final CostElementId costElementId) { | ||
return pricesByElementId.get(costElementId); | ||
} | ||
|
||
public void clearOwnCostPrice(@NonNull final CostElementId costElementId) { | ||
final BOMCostElementPrice elementCostPrice = getCostElementPriceOrNull(costElementId); | ||
if (elementCostPrice != null) { | ||
elementCostPrice.clearOwnCostPrice(); | ||
} | ||
} | ||
|
||
public void setComponentsCostPrice(@NonNull final CostAmount costPrice, | ||
@NonNull final CostElementId costElementId) { | ||
pricesByElementId | ||
.computeIfAbsent(costElementId, k -> BOMCostElementPrice.zero(costElementId, costPrice.getCurrencyId())) | ||
.setComponentsCostPrice(costPrice); | ||
} | ||
|
||
public void clearComponentsCostPrice(@NonNull final CostElementId costElementId) { | ||
final BOMCostElementPrice elementCostPrice = getCostElementPriceOrNull(costElementId); | ||
if (elementCostPrice != null) { | ||
elementCostPrice.clearComponentsCostPrice(); | ||
} | ||
} | ||
|
||
Collection<BOMCostElementPrice> getElementPrices() { | ||
return pricesByElementId.values(); | ||
} | ||
|
||
<T extends RepoIdAware> Stream<T> streamIds(@NonNull final Class<T> idType) { | ||
return getElementPrices().stream() | ||
.map(BOMCostElementPrice::getId) | ||
.filter(Predicates.notNull()) | ||
.map(idType::cast); | ||
} | ||
} |