Comments (10)
I wouldn't consider this feature necessary for 4.0 (if at all).
from c4j.
Well, it should be pretty easy to implement and can come in handy for legacy support. The main effort will be writing tests for almost every feature for static methods as well.
from c4j.
Static methods was easy, what's missing is static initializers. Not so easy, as the compiler is initializing the synthetic field $assertionsDisabled using Class.desiredAssertionStatus in the static initializer for every class using an assert statement :-(
Will have to find out if this is compiler specific. If it's not, we can safely remove this compiler magic and also make the needed -ea VM argument obsolete.
from c4j.
I would consider enabling assert
without the -ea VM argument magic (which I rather dislike when it comes to programming)…
from c4j.
You're right, we shouldn't change the assert mechianism as specified. Also, who knows how other compilers handle the -ea argument - maybe there's no such field that's being initialized in the static initializer.
However, we can probably assume that if we run the static initializer code in the contract class (being copied to a separate method) as the pre- and post-condition of the static initializer of the target class, that all static initializations are taking place as needed. This is because the static initializer of the target class is being run just before the target class is first being used (in a static or non-static way) and therefore the contract class can't be used earlier than that, making the pre-condition of the static initializer the earliest possible use of the contract class.
from c4j.
If I remember correctly, you can have multiple static initializers in a single class. How would you write a contract for this? A separate one for each initializer or one preconfition that must hold before the first and a postcondition that must hold after the last?
from c4j.
Very good point!
- Yes, you can have multiple static initializers.
- javac combines them into one static initializer at compile-time.
- I'm pretty sure that multiple static initializers aren't possible in byte-code (as they're named
<clinit>
and you cannot have multiple methods with the same name), but I'll double-check to be safe.
So, you'd always write pre- and post-conditions for all static initializers combined, because that's all we know when looking at the bytecode.
Another example of bytecode-differences are initializers like this:
public class DummyClass {
{
// this will be executed when an object of the class is instantiated
}
}
Code in (non-static) initializers like that simply gets inserted at the beginning of every constructor (named <init>
) in the bytecode. So there's no way we can write contracts for those initializer-blocks alone - they'll always have to be included with the constructor.
from c4j.
We could also postpone the ability to write contracts for static initializers to post-4.0-GA. Although it could come in handy, e.g. if you have a static Map being initialized in the static initializer and you want to ensure that there are at least a certain amount of elements, or at least as many as there are elements in an enum, etc.
from c4j.
My opinion is not really important, but I also think that this is not a must-have feature for 4.0.
from c4j.
Btw, I double-checked: There can at most be one static initializer <clinit>
in bytecode.
from c4j.
Related Issues (20)
- Fix @AllowPureAccess not working correctly with Objects
- Exceptions being thrown while storing a value for old() in a pre-condition should be thrown in the post-condition
- Work together with EclEmma
- Fix old-Expressions being evaluated in post-condition
- Fix bug when using old and unchanged together in a post-condition
- Fix bug when using old and unchanged in a post-condition as well as in a class-invariant
- Fix pure trying to access package-private fields when subclass is in another package
- Fix XML-Configuration not working for top-level package-names
- Improve performance by removing Thread.currentThread.getStackTrace() calls
- Allow class initializers write access on own static fields in pure validation
- Configure contracts to be run only for a fraction of method calls, ensuring a limited overhead during runtime
- Use SLF4J instead of Log4J
- Review and decide on LSP Implementation HOT 1
- No instrumentation when method is undeclared and already instrumented in super-class
- Bug: unchanged() and old() not usable within extracted methods in Contract class
- Change constructor contract functionality
- Synthetic static method in contract class throws UsageError
- instrumenting too much?
- c4j once configured in Base Eclipse Plugin used in dependant plugins
- Checking whether a precondition is strengthening a super-defined precondition seems to be to strict in case of using external contract classes.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from c4j.