I am very new to groovy script runner and I have been trying to delete a field in JIRA but I always get NullPointerException.
I do understand what NullPointerMeans and I have read multiple posts online and on atlassian but nothing has helped.
Any idea / help is appreciated on how I can achieve this
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customField_toDelete = customFieldManager.getCustomFieldObject("12345")
customFieldManager.removeCustomField(customField_toDelete);
Stacktrace
java.lang.NullPointerException
at com.atlassian.jira.issue.managers.DefaultCustomFieldManager.removeCustomField(DefaultCustomFieldManager.java:490)
at com.atlassian.jira.issue.CustomFieldManager$removeCustomField$7.call(Unknown Source)
at Script2441.run(Script2441.groovy:20)
According to the JIRA documentation
customFieldManager.getCustomFieldObject("12345")
Will return null if there is no customer field in JIRA with the identifier "12345", hence why
customFieldManager.removeCustomField(customField_toDelete)
Throws a null pointer (because customField_toDelete is null)
If the method removeCustomField was #Nullable (i.e was annotated with the Nullable annotation) then it would be ok to pass a null to the method, but since it is not annotated with the method, it throws an exception.
Related
I'm making a Java Spring project in IntelliJ as an exercise and I don't understand a file configuration error I'm having.
Please look at my project directory layout as described in this screenshot:
The three most important files here are the Main & GameConfig classes, and the game.properties file. Or, to use their full package directory names, "console/src/main/java/academy.learnprogramming.console.Main", "core/src/main/java/academy.learnprogramming.config.GameConfig" and core/src.resources.config.game.properties
When I run project, the Main class tries to run the following code:
package academy.learnprogramming.console;
import academy.learnprogramming.MessageGenerator;
import academy.learnprogramming.NumberGenerator;
import academy.learnprogramming.config.GameConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Main {
private static final Logger log = LoggerFactory.getLogger(com.sun.tools.javac.Main.class);
public static void main(String[] args) {
log.info("Guess the number");
//== create the context first ==
ConfigurableApplicationContext context
= new AnnotationConfigApplicationContext(GameConfig.class);
// rest of code, which we never get to because of an error with the above line
When I try to create ConfigurableApplicationContext, I am trying to call the GameConfig class from the Core package. But I get this runtime error instead:
Exception in thread "main"
org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to parse configuration class
[academy.learnprogramming.config.GameConfig]; nested exception is
java.io.FileNotFoundException: class path resource
[config/game.properties] cannot be opened because it does not exist
I do not understand why it thinks GameConfig does not exist, or how to fix it. No solutions I have found seem to have the precise answer for this. I have gotten a configuration comparison from someone whose code is identical to mine, but neither of us understand why their version works and mine does not.
For comparison's sake, the GameConfig class has the following code:
package academy.learnprogramming.config;
import academy.learnprogramming.GuessCount;
import academy.learnprogramming.MaxNumber;
import academy.learnprogramming.MinNumber;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
#Configuration
#ComponentScan(basePackages = "academy.learnprogramming")
#PropertySource("classpath:config/game.properties")
public class GameConfig {
//rest of GameConfig code here...
While game.properties is as simple as this:
game.maxNumber = 100
game.guessCount = 10
game.minNumber = 0
I can't find a question similar to this, nor do other websites point out what's going on. Does anyone have any idea why this error might be happening? Any advice would be invaluable
A null pointer exception occurred when trying to connect to hybris database using hybris flexible search service seemingly due to getJaloResult() method.
I need to retrieve certain data from hybris commerce database. I tried to use hybris flexible service to do that by using defaultFlexibleSearchService.search() method, but I got a null pointer exception. It seems that the exception occurred when search() method tries to call getJaloResult() method. I have no clue about the solution - thanks for any hints.
My class definition code is here
package de.hybris.platform.integrationservices.audit;
import java.util.stream.Stream;
import com.sun.tools.javac.util.List;
import de.hybris.platform.audit.TypeAuditReportConfig;
import de.hybris.platform.audit.view.AuditViewService;
import de.hybris.platform.audit.view.impl.ReportView;
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
import de.hybris.platform.servicelayer.search.FlexibleSearchService;
import de.hybris.platform.servicelayer.search.RelationQuery;
import de.hybris.platform.servicelayer.search.SearchResult;
import de.hybris.platform.servicelayer.search.impl.DefaultFlexibleSearchService;
import de.hybris.platform.integrationservices.model.IntegrationObjectModel;
public class IntegrationObjectAudit implements AuditViewService
{
private DefaultFlexibleSearchService defaultFlexibleSearchService;
public IntegrationObjectAudit() {
defaultFlexibleSearchService = new DefaultFlexibleSearchService();
}
public List<IntegrationObjectModel> searchModel(){
String query = "SELECT {PK} FROM {IntegrationObject}";
FlexibleSearchQuery flexibleSearchQuery = new FlexibleSearchQuery(query);
flexibleSearchQuery.setCount(1);
de.hybris.platform.servicelayer.search.SearchResult<IntegrationObjectModel> resListIntegrationModel = this.defaultFlexibleSearchService.search(query);
List<IntegrationObjectModel> resList = (List<IntegrationObjectModel>) resListIntegrationModel.getResult();
return resList;
}
}
Didnt notice it was posted days back. Hope you already resolved it. Still adding my answer as it may be helpful for others.
What I see you are not injecting flexibleSearchService bean in IntegrationObjectAudit. And as flexibleSearchService bean is not injected, its causing NullPointerException when you call any function on it.
You can fix it as following (spring bean injection concept)
Either you should create a setter function and inject it by spring xml
Or use #Resource or #Autowire annotation for same
public class IntegrationObjectAudit implements AuditViewService
{
#Resource
private DefaultFlexibleSearchService flexibleSearchService;
.....
Hope it helps. Let me know please.
There is a feature on the CouchbaseTemplate class in Spring Data Couchbase to set how exceptions are handled on writes, using the setWriteResultChecking method.
There doesn't seem to be any information on this in the documentation.
If you dig into the source code, the default setting is NONE. This means that exceptions get logged but don't get passed back up to your calling code.
Please does anyone know why this is the default behaviour? Wouldn't it make more sense to use EXCEPTION, so at least your calling code knows that something has gone wrong?
I've not got a lot of experience with Spring data for Couchbase, or indeed Couchbase, so I feel like I'm missing a fundamental point here.
Thanks.
For future reference, this is how I set the write checking to EXCEPTION:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
import org.springframework.data.couchbase.config.BeanNames;
import org.springframework.data.couchbase.core.CouchbaseTemplate;
import org.springframework.data.couchbase.core.WriteResultChecking;
#Configuration
public class CouchbaseConfig extends AbstractCouchbaseConfiguration {
#Override
#Bean(name = BeanNames.COUCHBASE_TEMPLATE)
public CouchbaseTemplate couchbaseTemplate() throws Exception {
CouchbaseTemplate couchbaseTemplate = super.couchbaseTemplate();
couchbaseTemplate.setWriteResultChecking(WriteResultChecking.EXCEPTION);
return couchbaseTemplate;
}
}
I didn't include this as an answer, because it isn't answering the question. The quesstion was about why NONE is the default.
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import org.apache.cxf.jaxrs.ext.search.SearchCondition;
import org.apache.cxf.jaxrs.ext.search.SearchContext;
import com.f2s.bean.Recentbean;
#Path("search")
public class SearchResource {
private List<Recentbean> ra;
#Path("book")
#GET
public List<Recentbean> findBooks(#Context SearchContext searchContext)
{
SearchCondition<Recentbean> condition = searchContext.getCondition(Recentbean.class);
return condition.findAll(ra);
}
error :- annotated with GET of resource, class com.f2s.restws.SearchResource, is not recognized as valid resource method.
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
First of all, you "question" is actually not a question. You're just presenting an error that you get. No explanation, no expected behaviour, no question asked. Providing some more details would be helpful.
Secondly, have you had a look on the other questions dealing with the presented exception? Here there are a few:
Exception :com.sun.jersey.spi.inject.Errors$ErrorMessagesException
Jersey: com.sun.jersey.spi.inject.Errors$ErrorMessagesException
Errors$ErrorMessagesException when using Jersey in Java
Because of my reputation I couldn't add this as a comment...
When I call Velocity.init() I get the following exception. I have included all dependencies, I have tried setting properties and using property files but all to no avail. any help?
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:97)
at org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:543)
at org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:519)
at org.apache.velocity.runtime.RuntimeInstance.setDefaultProperties(RuntimeInstance.java:416)
at org.apache.velocity.runtime.RuntimeInstance.initializeProperties(RuntimeInstance.java:628)
at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:261)
at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:112)
at org.apache.velocity.app.Velocity.init(Velocity.java:74)
here is the calling code
import com.syntatik.roborm.RobormEntity;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.Properties;
public class Generator{
protected VelocityContext context;
public Generator(){
Velocity.init();
this.context = new VelocityContext();
}
}
I have looked at the Velocity source code and can see that it's finding the default properties file on your classpath and then it's having trouble in Reader.java. With an IDE you should be able to get the source to Reader.java to find out why it's getting the NPE. Unfortunately at the moment I can't look at Reader to give you more information.
If you can't determine the cause of the NPE, I suggest you delete the default property file from your classpath and set the properties in code.
Have a look at this question for more information