Permalink
Browse files

SONAR-2424 Fix possible NPE during export of profile

Also provide generic handler of java.lang.IllegalArgumentException on
Ruby side.
  • Loading branch information...
Godin committed Apr 4, 2012
1 parent fed64a0 commit 060d0a43a78d759cf430e75b21ec2ee7d1dd5ed2
@@ -110,6 +110,9 @@ public String exportProfile(int profileId, String exporterKey) {
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();
@@ -265,6 +265,9 @@ public ValidationMessages restoreProfile(String xmlBackup) {
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);
}
@@ -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 @@ def render_not_found(error)
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)

0 comments on commit 060d0a4

Please sign in to comment.