Questions tagged [preconditions]

A precondition is some condition which must be satisfied before running a given section of code. It may be specified in code via assertions, or in the documentation.

If a precondition is violated, errors or security issues may occur. A precondition states what is required for the section of code to run correctly.

Links

Related tags

166 questions
4
votes
1 answer

UPnP subscription renewal fails on the device

When I try to renew the UPnP event subscription on the device, I have an 412 HTTP Error: Precondition Failed, bad SID. This error occurs only on one device, all other devices works fine. Buggy device is an D-Link XTreme N GIGABIT Router DIR-655…
4
votes
2 answers

grails changelog preconditions not doing anything

I am trying to make changes to the database using the changelog. Since I cannot guarantee that the values currently exist for the specific code, but could exist, I need to be able to check for them in order to either do an insert or an update. Here…
k_jaeger
  • 61
  • 1
  • 6
4
votes
4 answers

What are the options for precondition checking in Haskell

This is a simple question with a complex answer I presume. A very common programming problem is a function that returns something, or fails precondition checks. In Java I would use some assert function that throws IllegalArgumentException at the…
iwein
  • 25,788
  • 10
  • 70
  • 111
4
votes
9 answers

how do i explain that if (xyz == null) checks are not "protective"

i have a few developers who constantly put If null checks For example: Run(Order order) { if (order == null) return; } in their code as they think they are protecting their class if someone passes in a parameter that is null. I am trying to tell…
leora
  • 188,729
  • 360
  • 878
  • 1,366
4
votes
1 answer

How can class invariant strengthen pre and post-conditions?

Link You can think of the class invariant as a health criterion, which must be fulfilled by all objects in between operations. As a precondition of every public operation of the class, it can therefore be assumed that the class invariant…
4
votes
2 answers

How to check function parameters in Go

Guava Preconditions allow to check method parameters in Java easily. public void doUsefulThings(Something s, int x, int position) { checkNotNull(s); checkArgument(x >= 0, "Argument was %s but expected nonnegative", x); …
deamon
  • 89,107
  • 111
  • 320
  • 448
4
votes
3 answers

Are preconditions and postconditions needed in addition to invariants in member functions if doing design by contract?

I understand that in the DbC method, preconditions and postconditions are attached to a function. What I'm wondering is if that applies to member functions as well. For instance, assuming I use invariants at the beginning at end of each public…
3
votes
2 answers

Check in range precondition

I like guava preconditions, but what I really need from it is one more method - check that the number is in range. Smt like this //probably there should be checkStateInRange also public static void checkArgumentInRange(double value, int min, int…
Stan Kurilin
  • 15,614
  • 21
  • 81
  • 132
3
votes
0 answers

How to reference the default schema in liquibase preCondition sqlCheck

Posting here in case it helps someone. TLDR: ${database.defaultSchemaName} within sqlCheck to access default schema name I wanted my database changeset to first check if a certain row is present in the database. If not present, it should execute…
blimkt
  • 31
  • 2
3
votes
2 answers

Java 8 Guava Preconditions throwing NullPointerException while evaluating the exception message string

I have an object myObject and I want to make sure that it is null or else I want to print a custom message with the object's id. I have the following line of code trying to achieve the same Preconditions.checkArgument(Objects.isNull(myObject), …
Marco Polo
  • 113
  • 1
  • 6
3
votes
0 answers

Post- and Preconditions

I was just reading the documentation for the Bosque Programming Language and came across section 12 about errors and checks I was wondering if C# has a similar concept to post and preconditions. At first glimpse, I thought that this looks like…
Bongo
  • 2,933
  • 5
  • 36
  • 67
3
votes
1 answer

Check if not null or not 0 in Liquibase Precondition

I have currently an issue with liquibase preconditions. I would like to insert something only if a precondition request does'nt answer 0 or null... I explain :
Sophie3591
  • 51
  • 1
  • 1
  • 3
3
votes
2 answers

Precondition and postcondition checks in public methods

I was reading the Oracle documentation about using the assert keyword to verify method preconditions and postconditions. The document says that it's fine to use the assert keyword to verify postconditions for public methods but you should only use…
Ogen
  • 6,499
  • 7
  • 58
  • 124
3
votes
4 answers

Function description

If I have fnc like this: void fnc(const SomeType&){/**/} And when I list preconditions and postconditions for this fnc I think that listing precondition of form: SomeType must be of a correct type is rather dumb, isn't it? I'm asking for this…
There is nothing we can do
  • 23,727
  • 30
  • 106
  • 194
3
votes
6 answers

How to ask multiple conditions to return true Java

I am writing a code that must meet a precondition, and if the conditions are all met then it will return true. I have tried multiple "if" statements but that doesn't seem to work. Nested if statements don't seem to be the answer here and I don't…
spotTop
  • 87
  • 2
  • 7
1 2
3
11 12