aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2012-04-04 22:42:49 +0600
committerEvgeny Mandrikov <mandrikov@gmail.com>2012-04-04 23:24:41 +0600
commit060d0a43a78d759cf430e75b21ec2ee7d1dd5ed2 (patch)
treecaddb43e0aa4e0e1bbcc4c0f40f22c5a39ba353b
parentfed64a092206daebe4dd841fd89fced76163353f (diff)
downloadsonarqube-060d0a43a78d759cf430e75b21ec2ee7d1dd5ed2.tar.gz
sonarqube-060d0a43a78d759cf430e75b21ec2ee7d1dd5ed2.zip
SONAR-2424 Fix possible NPE during export of profile
Also provide generic handler of java.lang.IllegalArgumentException on Ruby side.
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java3
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java3
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb12
3 files changed, 17 insertions, 1 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java b/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java
index 6cbd6e6b266..16d5c5c65bd 100644
--- a/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java
+++ b/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java
@@ -110,6 +110,9 @@ public final class ProfilesConsole implements ServerComponent {
RulesProfile profile = loadProfile(session, profileId);
if (profile != null) {
ProfileExporter exporter = getProfileExporter(exporterKey);
+ if (exporter == null) {
+ throw new IllegalArgumentException("No such exporter");
+ }
Writer writer = new StringWriter();
exporter.exportProfile(profile, writer);
return writer.toString();
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
index 8c34f40739d..51372edf0d5 100644
--- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
+++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
@@ -265,6 +265,9 @@ public final class JRubyFacade {
return getContainer().getComponentByType(ProfilesConsole.class).getProfileImportersForLanguage(language);
}
+ /**
+ * @throws IllegalArgumentException if no such exporter
+ */
public String exportProfile(int profileId, String exporterKey) {
return getContainer().getComponentByType(ProfilesConsole.class).exportProfile(profileId, exporterKey);
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb
index a705aed664d..47b683e68b1 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb
@@ -25,6 +25,7 @@ class ApplicationController < ActionController::Base
before_filter :check_database_version, :set_locale, :check_authentication
rescue_from Exception, :with => :render_error
+ rescue_from NativeException, :with => :render_native_exception
rescue_from Errors::BadRequest, :with => :render_bad_request
rescue_from ActionController::UnknownAction, :with => :render_not_found
rescue_from ActionController::RoutingError, :with => :render_not_found
@@ -131,7 +132,16 @@ class ApplicationController < ActionController::Base
end
def render_bad_request(error)
- render :text => error.message, :status => 400
+ message = error.respond_to?('message') ? error.message : error.to_s
+ render :text => message, :status => 400
+ end
+
+ def render_native_exception(error)
+ if error.cause.java_kind_of? Java::JavaLang::IllegalArgumentException
+ render_bad_request(error.cause.getMessage)
+ else
+ render_error(error)
+ end
end
def render_error(error)