]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4045 fix support of Java exception in ruby code
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 13 Sep 2013 08:52:32 +0000 (10:52 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 13 Sep 2013 08:52:32 +0000 (10:52 +0200)
Behavior changed in JRuby 1.7....
http://pivotallabs.com/upgrading-to-jruby-1-7-0/

sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb

index dee18cc0d7c7487a6a9cb2e3693553cb45f11eba..671380536da7f578350b116fda2daef5ded7c787 100644 (file)
@@ -139,7 +139,6 @@ public class InternalPermissionTemplateService implements ServerComponent {
   private void validateTemplateName(Long templateId, String templateName) {
     if(StringUtils.isNullOrEmpty(templateName)) {
       String errorMsg = "Name can't be blank";
-      LOG.error(errorMsg);
       throw new BadRequestException(errorMsg);
     }
     List<PermissionTemplateDto> existingTemplates = permissionDao.selectAllPermissionTemplates();
@@ -147,7 +146,6 @@ public class InternalPermissionTemplateService implements ServerComponent {
       for (PermissionTemplateDto existingTemplate : existingTemplates) {
         if((templateId == null ||  !existingTemplate.getId().equals(templateId)) && (existingTemplate.getName().equals(templateName))) {
           String errorMsg = "A template with that name already exists";
-          LOG.error(errorMsg);
           throw new BadRequestException(errorMsg);
         }
       }
index 884389660db2223a1b8d5e1d08db2387462a14bc..655407a4b52ac37cf542a535a21e9caba60d5227 100644 (file)
@@ -24,8 +24,15 @@ class ApplicationController < ActionController::Base
 
   before_filter :check_database_version, :set_user_session, :check_authentication
 
+  # Required for JRuby 1.7
+  rescue_from 'Java::JavaLang::Exception', :with => :render_java_exception
+
   rescue_from Exception, :with => :render_error
-  rescue_from NativeException, :with => :render_native_exception
+
+  # Is it still required for JRuby 1.7 ? Java exception no longer inherits from ruby exception.
+  # See http://pivotallabs.com/upgrading-to-jruby-1-7-0/
+  rescue_from NativeException, :with => :render_java_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
@@ -182,15 +189,15 @@ class ApplicationController < ActionController::Base
     end
   end
 
-  def render_native_exception(error)
-    if error.cause.java_kind_of? Java::JavaLang::IllegalArgumentException
-      render_bad_request(error.cause.getMessage)
-    elsif error.cause.java_kind_of? Java::OrgSonarServerExceptions::UnauthorizedException
-      render_native_access_denied(error.cause)
-    elsif error.cause.java_kind_of? Java::OrgSonarServerExceptions::ForbiddenException
-      render_native_access_denied(error.cause)
-    elsif error.cause.java_kind_of? Java::OrgSonarServerExceptions::HttpException
-      render_server_exception(error.cause)
+  def render_java_exception(error)
+    if error.java_kind_of? Java::JavaLang::IllegalArgumentException
+      render_bad_request(error.getMessage)
+    elsif error.java_kind_of? Java::OrgSonarServerExceptions::UnauthorizedException
+      render_native_access_denied(error)
+    elsif error.java_kind_of? Java::OrgSonarServerExceptions::ForbiddenException
+      render_native_access_denied(error)
+    elsif error.java_kind_of? Java::OrgSonarServerExceptions::HttpException
+      render_server_exception(error)
     else
       render_error(error)
     end