Skip to content

Commit 8663402

Browse files
clr182yousif-bugsnagtomlongridge
authored
Release/v3.7.2 (#222)
* (docs): update docs references from `master` to `main` * (docs): switch build status badge to buildkite * Update selector to accept only the major version * Update Changelog * update linting * Added severity check (#214) * added severity check * fixed linting * fixed linting v2 * added changelog entry * Reverting changes * update notify override with null check * Update changelog * Update Bugsnag.java call notify override method on null severity * add aopproxyutils dependancy and add handling in scheduledTaskConfig class (#218) * add aopproxyutils dependancy and add handling in scheduledTaskConfig class * fixed comment typo * fixed import of aoputils * added proxy testing * fixed linting * Updated tests * updated tests * update changelog * moving createProxy method to util class * update variable name * reverting * Update Serializer object to be an interface (#219) * Adding non serializable metadata handling * removed an unused import * update feature * update changelog * Add serializeObject public method * Fixed linting * fixed tests * Implemented Serializer interface * update scenarios * update changelog * Changes based on feedback * update tests * updates based on reviews * Update bugsnag/src/main/java/com/bugsnag/Configuration.java Co-authored-by: Tom Longridge <[email protected]> * update config --------- Co-authored-by: Tom Longridge <[email protected]> * v3.7.2 --------- Co-authored-by: Yousif Ahmed <[email protected]> Co-authored-by: Yousif <[email protected]> Co-authored-by: Tom Longridge <[email protected]>
1 parent 8cc7444 commit 8663402

File tree

17 files changed

+177
-49
lines changed

17 files changed

+177
-49
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Changelog
22

3+
## 3.7.2 (2024-08-28)
4+
5+
### Changed
6+
7+
* Add a null check for `Severity` to the notify override method. [#214](https://github.com/bugsnag/bugsnag-java/pull/214)
8+
9+
* Created Serializer interface, allowing for implementation of a custom serializer. [#219](https://github.com/bugsnag/bugsnag-java/pull/219)
10+
11+
* Updated ScheduleTaskConfiguration configureTask method to properly handle wrapped/proxied objects. [#218](https://github.com/bugsnag/bugsnag-java/pull/218)
12+
13+
### Bug Fixes
14+
15+
* Update `BugsnagImportSelector` to allow major versions that do not have a minor version.
16+
fixes [issue #211](https://github.com/bugsnag/bugsnag-java/issues/211).
17+
[#213](https://github.com/bugsnag/bugsnag-java/pull/213)
18+
319
## 3.7.1 (2023-10-25)
420

521
* Restore `BugsnagServletContainerInitializer` and `BugsnagServletRequestListener` to the `com.bugsnag.servlet` package.

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ To start a release:
122122
- `./gradlew -Preleasing=true clean publishAllPublicationsToSonatypeRepository`
123123
- Verify that the artefacts are uploaded to sonatype - ensure that JARs, POMs and JAVADOCs are present for each module.
124124
- Test the Sonatype artefacts in the example app by adding the newly created 'combugsnag-XXXX' repository to the build.gradle: maven {url "https://oss.sonatype.org/service/local/repositories/combugsnag-XXXX/content/"}
125-
- Once you are happy, make a PR from your release branch to `master` entitled `Release vX.Y.Z`
125+
- Once you are happy, make a PR from your release branch to `main` entitled `Release vX.Y.Z`
126126
- Get the release PR reviewed – all code changes should have been reviewed already, this should be a review of the integration of all changes to be shipped and the changelog
127127
- Once merged:
128-
- Pull the latest changes (checking out `master` if necessary)
128+
- Pull the latest changes (checking out `main` if necessary)
129129
- Create a release build and upload to sonatype:
130130
- `./gradlew -Preleasing=true clean publishAllPublicationsToSonatypeRepository`
131131
- Release to GitHub:
132-
- [ ] Create *and tag* the release from `master` on [GitHub Releases](https://github.com/bugsnag/bugsnag-android/releases), attaching the changelog entry and build artifacts
133-
- Checkout `master` and pull the latest changes
132+
- [ ] Create *and tag* the release from `main` on [GitHub Releases](https://github.com/bugsnag/bugsnag-android/releases), attaching the changelog entry and build artifacts
133+
- Checkout `main` and pull the latest changes
134134
- "Promote" the release build on Maven Central:
135135
- Go to the [sonatype open source dashboard](https://oss.sonatype.org/index.html#stagingRepositories)
136136
- Click the search box at the top right, and type “com.bugsnag”

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Bugsnag exception reporter for Java
22
[![Documentation](https://img.shields.io/badge/docs-latest-blue.svg)](https://docs.bugsnag.com/platforms/java)
3-
[![Build status](https://travis-ci.org/bugsnag/bugsnag-java.svg?branch=master)](https://travis-ci.org/bugsnag/bugsnag-java)
3+
[![Build status](https://badge.buildkite.com/de087a23152718c7d33b0ae7f566a940a92fb9d92becdb61a3.svg?branch=main)](https://buildkite.com/bugsnag/bugsnag-java)
44

55
The Bugsnag exception reporter for Java automatically detects and reports errors and exceptions in your Java code. Learn more about [reporting Java exceptions](https://www.bugsnag.com/platforms/java/) with Bugsnag.
66

@@ -35,7 +35,7 @@ The Bugsnag exception reporter for Java automatically detects and reports errors
3535
## Contributing
3636

3737
All contributors are welcome! For information on how to build, test, and release
38-
`bugsnag-java`, see our [contributing guide](https://github.com/bugsnag/bugsnag-java/blob/master/CONTRIBUTING.md).
38+
`bugsnag-java`, see our [contributing guide](https://github.com/bugsnag/bugsnag-java/blob/main/CONTRIBUTING.md).
3939

4040
## License
4141

bugsnag-spring/build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,32 @@ dependencies {
134134
compileJavax "javax.servlet:javax.servlet-api:${javaxServletApiVersion}"
135135
compileJavax "org.springframework:spring-webmvc:${javaxSpringVersion}"
136136
compileJavax "org.springframework.boot:spring-boot:${javaxSpringBootVersion}"
137+
compileJavax "org.springframework:spring-aop:${javaxSpringVersion}"
137138

138139
compileJakarta "jakarta.servlet:jakarta.servlet-api:${jakartaServletApiVersion}"
139140
compileJakarta "org.springframework:spring-webmvc:${jakartaSpringVersion}"
140141
compileJakarta "org.springframework.boot:spring-boot:${jakartaSpringBootVersion}"
142+
compileJakarta "org.springframework:spring-aop:${jakartaSpringVersion}"
143+
141144

142145
commonTestImplementation project(':bugsnag').sourceSets.test.output
143146
commonTestImplementation project(':bugsnag')
144147

145148
commonTestImplementation "junit:junit:${junitVersion}"
146-
149+
147150
commonTestCompileOnly "org.mockito:mockito-core:2.10.0"
148-
151+
149152
jakartaTestImplementation "org.mockito:mockito-core:${mockitoVersion}"
150153
jakartaTestImplementation "jakarta.servlet:jakarta.servlet-api:${jakartaServletApiVersion}"
151154
jakartaTestImplementation "org.springframework.boot:spring-boot-starter-test:${jakartaSpringBootVersion}"
152155
jakartaTestImplementation "org.springframework.boot:spring-boot-starter-web:${jakartaSpringBootVersion}"
156+
jakartaTestImplementation "org.springframework:spring-aop:${jakartaSpringVersion}"
153157

154158
javaxTestImplementation "org.mockito:mockito-core:2.10.0"
155159
javaxTestImplementation "javax.servlet:javax.servlet-api:${javaxServletApiVersion}"
156160
javaxTestImplementation "org.springframework.boot:spring-boot-starter-test:${javaxSpringBootVersion}"
157161
javaxTestImplementation "org.springframework.boot:spring-boot-starter-web:${javaxSpringBootVersion}"
162+
javaxTestImplementation "org.springframework:spring-aop:${javaxSpringVersion}"
158163
}
159164

160165
dependencies {

bugsnag-spring/src/common/java/com/bugsnag/BugsnagImportSelector.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ private static int getMajorVersion(String version) {
4040
return 0;
4141
}
4242
int firstDot = version.indexOf(".");
43+
String majorVersion;
44+
4345
if (firstDot == -1) {
44-
return 0;
46+
majorVersion = version;
47+
} else {
48+
majorVersion = version.substring(0, firstDot);
4549
}
4650

47-
String majorVersion = version.substring(0, firstDot);
4851
try {
4952
return Integer.parseInt(majorVersion);
5053
} catch (NumberFormatException nfe) {

bugsnag-spring/src/common/java/com/bugsnag/ScheduledTaskConfiguration.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
5+
import org.springframework.aop.framework.AopProxyUtils;
6+
import org.springframework.aop.support.AopUtils;
57
import org.springframework.beans.factory.annotation.Autowired;
68
import org.springframework.context.annotation.Configuration;
79
import org.springframework.scheduling.TaskScheduler;
810
import org.springframework.scheduling.annotation.SchedulingConfigurer;
911
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
1012
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
1113
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
14+
1215
import org.springframework.util.ErrorHandler;
1316

1417
import java.lang.reflect.Field;
@@ -49,10 +52,17 @@ public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
4952
? registrarScheduler : beanLocator.resolveTaskScheduler();
5053

5154
if (taskScheduler != null) {
55+
//check if taskSchedular is a proxy
56+
if (AopUtils.isAopProxy(taskScheduler)) {
57+
//if it's a proxy then get the target class and cast as necessary
58+
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(taskScheduler);
59+
if (TaskScheduler.class.isAssignableFrom(targetClass)) {
60+
taskScheduler = (TaskScheduler) AopProxyUtils.getSingletonTarget(taskScheduler);
61+
}
62+
}
5263
configureExistingTaskScheduler(taskScheduler, bugsnagErrorHandler);
5364
} else {
54-
ScheduledExecutorService executorService
55-
= beanLocator.resolveScheduledExecutorService();
65+
ScheduledExecutorService executorService = beanLocator.resolveScheduledExecutorService();
5666
taskScheduler = createNewTaskScheduler(executorService, bugsnagErrorHandler);
5767
taskRegistrar.setScheduler(taskScheduler);
5868
}

bugsnag-spring/src/jakartaTest/java/com/bugsnag/ScheduledTaskConfigurationTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNull;
55
import static org.junit.Assert.assertTrue;
6+
import static org.junit.jupiter.api.Assertions.assertFalse;
67
import static org.mockito.Mockito.when;
78

89
import com.bugsnag.testapp.springboot.TestSpringBootApplication;
910

11+
import org.aopalliance.intercept.MethodInterceptor;
1012
import org.junit.Before;
1113
import org.junit.Test;
1214
import org.junit.runner.RunWith;
1315

1416
import org.mockito.Mock;
15-
17+
import org.springframework.aop.framework.ProxyFactory;
1618
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
1719
import org.springframework.beans.factory.annotation.Autowired;
1820
import org.springframework.boot.test.context.SpringBootTest;
@@ -113,6 +115,31 @@ public void findExecutorByName() throws NoSuchFieldException, IllegalAccessExcep
113115
assertEquals(expected, accessField(scheduler, "scheduledExecutor"));
114116
}
115117

118+
@Test
119+
public void configureTasks_withProxyWrappedRegistrar() throws NoSuchFieldException, IllegalAccessException {
120+
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
121+
when(context.getBean(TaskScheduler.class)).thenReturn(scheduler);
122+
TaskScheduler proxyScheduler = createProxy(scheduler);
123+
registrar.setScheduler(proxyScheduler);
124+
Object errorHandler = accessField(scheduler, "errorHandler");
125+
assertFalse(
126+
errorHandler instanceof BugsnagScheduledTaskExceptionHandler,
127+
"errorHandler should not be BugsnagScheduledTaskExceptionHandler"
128+
);
129+
configuration.configureTasks(registrar);
130+
errorHandler = accessField(scheduler, "errorHandler");
131+
assertTrue(
132+
"errorHandler should be BugsnagScheduledTaskExceptionHandler",
133+
errorHandler instanceof BugsnagScheduledTaskExceptionHandler
134+
);
135+
}
136+
137+
private TaskScheduler createProxy(TaskScheduler target) {
138+
ProxyFactory factory = new ProxyFactory(target);
139+
factory.addAdvice((MethodInterceptor) invocation -> invocation.proceed());
140+
return (TaskScheduler) factory.getProxy();
141+
}
142+
116143
private Object accessField(Object object, String fieldName)
117144
throws NoSuchFieldException, IllegalAccessException {
118145
Field field = object.getClass().getDeclaredField(fieldName);

bugsnag-spring/src/javaxTest/java/com/bugsnag/ScheduledTaskConfigurationTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNull;
55
import static org.junit.Assert.assertTrue;
6+
import static org.junit.jupiter.api.Assertions.assertFalse;
67
import static org.mockito.Mockito.when;
78

89
import com.bugsnag.testapp.springboot.TestSpringBootApplication;
910

11+
import org.aopalliance.intercept.MethodInterceptor;
1012
import org.junit.Before;
1113
import org.junit.Test;
1214
import org.junit.runner.RunWith;
1315
import org.mockito.Mock;
16+
import org.springframework.aop.framework.ProxyFactory;
1417
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
1518
import org.springframework.beans.factory.annotation.Autowired;
1619
import org.springframework.boot.test.context.SpringBootTest;
@@ -111,6 +114,31 @@ public void findExecutorByName() throws NoSuchFieldException, IllegalAccessExcep
111114
assertEquals(expected, accessField(scheduler, "scheduledExecutor"));
112115
}
113116

117+
@Test
118+
public void configureTasks_withProxyWrappedRegistrar() throws NoSuchFieldException, IllegalAccessException {
119+
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
120+
when(context.getBean(TaskScheduler.class)).thenReturn(scheduler);
121+
TaskScheduler proxyScheduler = createProxy(scheduler);
122+
registrar.setScheduler(proxyScheduler);
123+
Object errorHandler = accessField(scheduler, "errorHandler");
124+
assertFalse(
125+
errorHandler instanceof BugsnagScheduledTaskExceptionHandler,
126+
"errorHandler should not be BugsnagScheduledTaskExceptionHandler"
127+
);
128+
configuration.configureTasks(registrar);
129+
errorHandler = accessField(scheduler, "errorHandler");
130+
assertTrue(
131+
"errorHandler should be BugsnagScheduledTaskExceptionHandler",
132+
errorHandler instanceof BugsnagScheduledTaskExceptionHandler
133+
);
134+
}
135+
136+
private TaskScheduler createProxy(TaskScheduler target) {
137+
ProxyFactory factory = new ProxyFactory(target);
138+
factory.addAdvice((MethodInterceptor) invocation -> invocation.proceed());
139+
return (TaskScheduler) factory.getProxy();
140+
}
141+
114142
private Object accessField(Object object, String fieldName)
115143
throws NoSuchFieldException, IllegalAccessException {
116144
Field field = object.getClass().getDeclaredField(fieldName);

bugsnag/src/main/java/com/bugsnag/Bugsnag.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ public boolean notify(Throwable throwable, Severity severity, Callback callback)
388388
LOGGER.warn("Tried to notify with a null Throwable");
389389
return false;
390390
}
391+
if (severity == null) {
392+
return notify(throwable, callback);
393+
}
391394

392395
HandledState handledState = HandledState.newInstance(
393396
HandledState.SeverityReasonType.REASON_USER_SPECIFIED, severity);

bugsnag/src/main/java/com/bugsnag/Configuration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.bugsnag.delivery.Delivery;
1010
import com.bugsnag.delivery.HttpDelivery;
1111
import com.bugsnag.delivery.SyncHttpDelivery;
12+
import com.bugsnag.serialization.DefaultSerializer;
1213
import com.bugsnag.serialization.Serializer;
1314

1415
import org.slf4j.Logger;
@@ -44,15 +45,14 @@ public class Configuration {
4445
public String[] projectPackages;
4546
public String releaseStage;
4647
public boolean sendThreads = false;
48+
public Serializer serializer = new DefaultSerializer();
4749

4850
Collection<Callback> callbacks = new ConcurrentLinkedQueue<Callback>();
49-
Serializer serializer = new Serializer();
5051
private final AtomicBoolean autoCaptureSessions = new AtomicBoolean(true);
5152
private final AtomicBoolean sendUncaughtExceptions = new AtomicBoolean(true);
5253

5354
Configuration(String apiKey) {
5455
this.apiKey = apiKey;
55-
5656
// Add built-in callbacks
5757
addCallback(new AppCallback(this));
5858
addCallback(new DeviceCallback());

0 commit comments

Comments
 (0)