SafeR Project

Printer-friendly versionPrinter-friendly version
Design by contract with safe references (containers)

A lightweight framework to apply a Design by Contract (DbC) coding style. Additionally, SafeR provides operations for checks which return a boolean value beside other related operations. SafeR supports DbC in two ways: with safe reference objects and assertions with just static operations. While the latter is the same approach as seen typically in "Assert" classes with static operations, the former is the preferred approach wherever possible. Safe reference objects can be seen as (immutable) containers or wrappers which assert that the references they contain are in the specified / expected state. By using the type of a safe reference class as parameter type or return type of an operation, the caller of the operation is forced to comply with the contract at compile time - and the declaration of the contract (preconditions and postconditions) in the Javadoc can be omitted. While the assertions with just static operations can detect programmatic issues very early and very close to the location of the issue, with safe references the most of the relevant programmatic issues can be prevented by the compiler already and the rest of the programmatic issues should be detected directly at the location of the issue.

In case a programmatic issue is detected by SafeR, a runtime exception or error will be generated with a large exception message containing all the details which might be useful to fix the issue, including a filtered stacktrace. The exception message can be customized easily, translated to any language and split into parts in order to extract information for the user. Any given object or value will be encoded to a detailed string automatically or customized for the exception message. Please find below a sample log. Optionally, an analyzer tool like the SWDES Code Analyzer can be used to generate an analysis report or an advice about the root cause into the exception message. The SWDES Code Analyzer will try to perform a backtracking using static bytecode analysis to find the origin of the issue. This can make the manual backtracking of an issue obsolete, in applications where the assertion is not as close to the location of the issue (due to a less intensive use of assertions).

SafeR can be and shall be active in production environments as well, to detect programmatic issues which have not been detected previously and to prevent invalid states. In order to prevent any issue for the business or the users, due to thrown runtime exceptions, SafeR provides convenient possibilities to unblock an application quickly and just within the production environment, but just temporarily until the programmatic issue has been fixed. This can save your day or even your job! SafeR prevents that assertions can be switched off permanently and forgotten easily, as it can happen for instance with the Java assertions provided by the JDK.

SafeR is designed to reduce its impact on the performance of an application as much as possible, so that no impact should be noticeable even if a very large application uses SafeR very intensively.

Hint: even if SafeR is extremely easy to use already, for the everyday work it might be useful to create editor templates within your IDE for the code and/or Javadocs to quickly create an assertion with just two or three key strokes.

 

Downloads

Below you can download archives from this project. This project has no dependencies. Requires JSE 8+.

Please refer to the instructions how to use these Java software bundles.

 


SWDES SafeR
Version 2.0
(build 41)
  ZIP  
This file / content is licensed as follows:
 

Contains the SWDES SafeR library and javadocs.

License text   License parameters   Licensor   Copyright laws      Additional information

SWDES SafeR (all)
Version 2.0
(build 41)
  ZIP  
This file / content is licensed as follows:
 

Contains the SWDES SafeR library, javadocs, sources and classes.

License text   License parameters   Licensor   Copyright laws      Additional information

SWDES SafeR-Demo
Version 2.0
(build 12)
  ZIP  
This file / content is licensed as follows:
 

Contains the SWDES SafeR-Demo library and javadocs.

License text   License parameters   Licensor   Copyright laws      Additional information

SWDES SafeR-Demo (all)
Version 2.0
(build 12)
  ZIP  
This file / content is licensed as follows:
 

Contains the SWDES SafeR-Demo library, javadocs, sources and classes.

License text   License parameters   Licensor   Copyright laws      Additional information

SafeR-Demo Sample Log
From version 2.0
 
  LOG  
This file / content is licensed as follows:
 

A sample log file from the SWDES SafeR-Demo.

License text   License parameters   Licensor   Copyright laws      Additional information

SWDES Code Analyzer
Version 1.0 alpha
(build 8)        PoC  
  ZIP  
This file / content is licensed as follows:
 

Contains the SWDES Code Analyzer library and javadocs.

License text   License parameters   Licensor   Copyright laws      Additional information

 

Pages